Basic Concepts Trees
Basic Concepts Trees
6. Which traversal method visits nodes in the order: left subtree, root, right subtree?
a) Preorder
b) In-order
c) Post-order
d) Level Order
10. In a binary tree, if the height of the root node is h, the maximum number of nodes in the tree is:
a) 2h−1
b) 2h+1−1
c) h2−1
d) h+1
15. Which traversal method can be used to generate a sorted sequence from a binary search tree?
a) Preorder
b) In-order
c) Post-order
d) Level Order
16. In a tree, the relationship between a node and its children is called:
a) Hierarchical
b) Linear
c) Cyclic
d) None of the above
20. The level order traversal of a binary tree uses which data structure?
a) Stack
b) Queue
c) Array
d) Linked List
2. What are the differences between height and depth in a tree? Provide examples.
3. Describe the level order traversal of a tree. Which data structure is used to implement it?
4. Explain the three common tree traversal methods: In-order, Pre-order, and Post-order, with
examples.
5. How can you represent a tree in memory? Compare adjacency list and adjacency matrix
representations.
1. Explain the tree traversal methods with detailed examples of Preorder, In-order, Post-order, and
Level Order traversals for the following binary tree:
2. Define and explain the terms nodes, edges, root, leaves, height, and depth with a diagrammatic
example of a tree.
3. Write and explain an algorithm to perform Level Order Traversal of a tree. Include an example
and discuss its time complexity.
Binary Tree Basics
1. Write and explain an iterative algorithm for level order traversal of a binary tree. Discuss
its time and space complexity.
2. Explain the construction of a Huffman tree with an example. Discuss how it is used for
data compression.
3. Discuss the various types of binary tree traversals. Implement recursive and iterative
approaches for preorder traversal.
1. Define a Binary Search Tree (BST) and explain its key property.
2. Describe the algorithm for searching a key in a BST.
3. Explain the process of deleting a node with one child in a BST.
4. What are the advantages of using a BST over an array for searching operations?
5. Discuss how the height of a BST impacts its performance.
6. List at least three practical applications of BSTs and explain one in detail.
1. Explain the process of inserting a node into a BST, and illustrate it with an example.
2. Discuss the time complexities of various operations (insertion, deletion, and search) in a
BST, comparing balanced and unbalanced cases.
3. Write a program or pseudocode to implement the deletion operation in a BST. Explain
each step-in detail.
AVL Tree
1. Explain the process of inserting a node in an AVL tree, and illustrate with an example
where rotations are required.
2. Write pseudocode for deleting a node in an AVL tree and rebalancing it. Explain the
process with an example.
3. Compare AVL trees with red-black trees in terms of their balancing techniques, use
cases, and performance.
Red-Black Tree
1. Write a detailed explanation of the insertion operation in a Red-Black Tree. Include all
possible cases of rebalancing with examples.
2. Explain the deletion operation in a Red-Black Tree with pseudocode. Provide examples
to illustrate the balancing process.
3. Compare Red-Black Trees with other self-balancing trees (e.g., AVL Trees, B-trees) in
terms of structure, performance, and use cases.
Splay Tree
1. Write and explain the pseudocode for the search operation in a splay tree, including the
splaying process.
2. Discuss the insertion operation in a splay tree with an example, detailing the splaying
process.
3. Compare and contrast splay trees with AVL and Red-Black Trees, focusing on use cases,
performance, and implementation complexity.
Heap Tree
1. What is a heap?
a) A binary search tree
b) A complete binary tree
c) A balanced binary tree
d) An AVL tree
2. In a max-heap, the parent node is always:
a) Smaller than both children
b) Larger than or equal to both children
c) Equal to its children
d) At the same level as its children
3. In a min-heap, the smallest element is:
a) At the deepest level
b) At the root
c) In the middle
d) At any leaf
4. Which of the following is NOT a property of heaps?
a) Complete binary tree structure
b) Sibling nodes have no order relationship
c) Nodes follow in-order traversal
d) Parent nodes follow specific priority rules
5. What is the time complexity of inserting an element into a heap?
a) O(log n)
b) O(n)
c) O(1)
d) O(n log n)
6. What is the primary use of heaps in computer science?
a) Priority queues
b) Binary search trees
c) Sorting algorithms like bubble sort
d) Graph traversals
7. Which algorithm uses a heap for sorting?
a) Quick sort
b) Merge sort
c) Heap sort
d) Bubble sort
8. What is the relationship between the indices of a node and its children in a 0-based array
representation of a heap?
a) Left child: 2i + 1, Right child: 2i + 2
b) Left child: 2i - 1, Right child: 2i
c) Left child: i/2, Right child: i/2 + 1
d) Left child: i + 1, Right child: i + 2
9. How is the root of a heap deleted?
a) By removing it and leaving the tree incomplete
b) By replacing it with the last element and heapifying
c) By swapping it with any leaf
d) By rearranging the tree without replacement
10. In a max-heap, which node will be replaced during insertion?
a) The root
b) The smallest leaf
c) The parent node, if smaller than the new node
d) The last inserted node
11. What is the height of a heap with n nodes?
a) O (log n)
b) O(n)
c) O(1)
d) O(n²)
12. Which operation involves the reordering of elements to maintain the heap property?
a) Traversal
b) Deletion
c) Heapify
d) Sorting
13. In a min-heap, where is the largest element located?
a) At the root
b) At the leftmost leaf
c) At one of the leaves
d) In the middle of the tree
14. Which data structure is commonly implemented using heaps?
a) Stacks
b) Priority queues
c) Linked lists
d) Hash maps
15. What is the worst-case time complexity of heapify?
a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)
16. During heap sort, what operation is performed repeatedly?
a) Insertion
b) Searching
c) Extracting the root and heapifying
d) Rebalancing the tree
17. Which of the following applications is NOT suitable for heaps?
a) Priority-based task scheduling
b) Median finding
c) Dijkstra's algorithm
d) Depth-first search
18. What happens when a max-heap is converted to a min-heap?
a) The tree is reversed.
b) Heapify is performed in reverse order.
c) The tree structure is flattened.
d) All keys are rearranged in increasing order.
19. Which of the following is NOT true about heaps?
a) Can be represented using arrays
b) Used in priority queues
c) Always balanced like AVL trees
d) Root is the highest or lowest priority element
20. How many leaf nodes does a heap with n elements have?
b) ⌈n/2⌉
a) n/2
c) ⌊n/2⌋
d) n
1. Define a heap and explain the differences between a min-heap and a max-heap.
2. Describe the process of inserting an element into a heap.
3. Explain how heap sort works, step by step.
4. Write the pseudocode for the heapify operation and explain its purpose.
5. What are the advantages of using heaps in implementing priority queues?
6. Discuss the array representation of heaps and its advantages.
1. Explain the deletion operation in a heap, including how the heap property is restored.
Provide an example.
2. Write and explain the algorithm for heap sort. Illustrate with an example of sorting an
array.
3. Compare and contrast heaps with other tree structures like binary search trees and AVL
trees, focusing on their use cases and efficiency.
Multi-way Tree
b) ⌈m/2⌉
a) 1
c) m
d) m/2
10. What happens during deletion in a B-tree if a node becomes underfull?
a) The node is left as is
b) The tree height decreases
c) Keys are borrowed from siblings or nodes are merged
d) The root is deleted
11. What is the primary use of B-trees?
a) Database indexing
b) Sorting algorithms
c) Graph traversal
d) Priority queues
12. In a 2-3 tree, a node can have at most:
a) 3 children
b) 2 keys and 3 children
c) 4 keys
d) 2 children
13. What distinguishes a B+ tree from a B-tree?
a) B+ trees are unbalanced
b) All data entries are stored in the leaf nodes in B+ trees
c) B+ trees have fixed node sizes
d) B+ trees do not support search
14. In a multi-way tree, the root node has:
a) No parent
b) Exactly two children
c) No children
d) Multiple parents
15. What does the order of a multi-way tree indicate?
a) The depth of the tree
b) The maximum number of children a node can have
c) The height of the tree
d) The number of leaves
16. Which of the following is TRUE about deletion in a B-tree?
a) It always reduces the height of the tree
b) It always involves merging nodes
c) It may involve redistributing keys among sibling nodes
d) It requires rebalancing like AVL trees
17. What is a 2-3 tree?
a) A binary tree
b) A tree with a height of 2 or 3
c) A multi-way tree where each node has 2 or 3 children
d) A tree with at least 2 levels
18. What is the advantage of using multi-way trees over binary trees?
a) Easier implementation
b) Reduced tree height
c) Faster traversal
d) No rebalancing required
19. In a B-tree, splitting occurs when:
a) A node is underfull
b) The root has only one child
c) A node exceeds its maximum number of keys
d) The tree is traversed
20. What is the height of a B-tree with n elements and order m?
a) O(logₘ n)
b) O(log n)
c) O(m log n)
d) O(n log m)
1. Describe the algorithm for inserting a key into a B-tree. Illustrate with an example,
including a case where splitting occurs.
2. Explain the deletion process in a B-tree with an example. Include the cases of merging
and redistribution.
3. Compare and contrast multi-way trees with AVL and binary search trees, focusing on
their properties, operations, and use cases.
B-Tree
1. What is a B-tree?
a) A binary search tree
b) A self-balancing multi-way search tree
c) A tree with only two children per node
d) A graph with hierarchical properties
2. In a B-tree of order m, the maximum number of keys a node can have is:
a) m
b) m - 1
c) 2m
d) m/2
3. What is the minimum degree (t) of a B-tree?
a) The maximum number of keys in a node
b) The number of levels in the tree
c) The minimum number of children for a non-root node
d) The total number of nodes in the tree
4. In a B-tree, all leaves are:
a) At different levels
b) At the same level
c) At least half full
d) At the root level
5. What happens during a search operation in a B-tree?
a) The tree is traversed depth-first
b) Keys in a node are sequentially searched and the appropriate child is followed
c) All nodes are scanned linearly
d) The tree is completely traversed
6. What is the time complexity of a search operation in a B-tree?
a) O(log n)
b) O(n)
c) O(1)
d) O(n log n)
7. What happens when a node in a B-tree becomes full during insertion?
a) The node splits, and the middle key is promoted to the parent
b) The tree is converted into a binary search tree
c) The node is merged with its sibling
d) A new child node is added
8. What is the primary use case for B-trees?
a) Sorting arrays
b) Database indexing
c) Graph traversal
d) Implementing stacks
9. What is the minimum number of keys a non-root node must have in a B-tree of degree t?
a) t
b) t - 1
c) t/2
d) 2t
10. During deletion in a B-tree, what happens if a node becomes underfull?
a) The node is deleted
b) A new node is created
c) Keys are borrowed from siblings or the node is merged
d) The entire tree is restructured
11. Which of the following is NOT true about B-trees?
a) All leaf nodes are at the same level
b) It is a self-balancing tree
c) Keys are stored in sorted order only at the leaf nodes
d) Search, insertion, and deletion are efficient
12. Which operation involves promoting a key to the parent node?
a) Deletion
b) Searching
c) Insertion
d) Merging
13. In a B-tree, what is the maximum number of children a node can have if it contains 3
keys?
a) 3
b) 4
c) 4
d) 5
14. What is the height of a B-tree with n keys and minimum degree t?
a) O (logₜ n)
b) O (log n)
c) O(n)
d) O (n log n)
15. During the deletion of a key in a B-tree, which case does NOT require rebalancing?
a) The key is in an internal node
b) The node becomes underfull
c) The key is deleted from a leaf node with enough keys
d) The node merges with a sibling
16. How does splitting work in a B-tree?
a) The parent node is split into two nodes
b) A full node is divided, and the middle key is moved to the parent
c) A leaf node is split, and the tree is restructured
d) Keys are shifted between siblings
17. What is the relationship between the height of a B-tree and its degree?
a) The height increases with the degree
b) The height decreases with the degree
c) The height is logarithmic to the number of keys
d) The height is linear with the degree
18. In a B-tree, the root node must have at least:
a) t - 1 keys
b) 2 keys
c) 1 key
d) t keys
19. How does a B+ tree differ from a B-tree?
a) In a B+ tree, all data entries are stored in the leaf nodes
b) A B+ tree does not maintain balance
c) A B+ tree supports only search operations
d) A B+ tree has only one level
20. Which of the following is a property of B-trees?
a) Keys are stored only at leaf nodes
b) Nodes are sorted using breadth-first traversal
c) Each node is at least half full
d) Nodes are balanced based on height
1. Explain the process of inserting a key into a B-tree with an example where splitting
occurs.
2. Discuss the deletion operation in a B-tree. Include examples for cases where merging and
key borrowing occur.
3. Compare and contrast B-trees and B+ trees, focusing on their structure, operations, and
use cases.
Sorting algorithms
Selection Sort algorithm
1. Implement the Selection Sort algorithm in your preferred programming language to sort
an array of integers.
2. Analyze the time and space complexity of the Selection Sort algorithm with examples.
3. Provide a detailed explanation of how Selection Sort works with an example array of
your choice.
1. Implement the Merge Sort algorithm in your preferred programming language and
demonstrate sorting an example array.
2. Analyze the time complexity of Merge Sort in the best, average, and worst cases, and
explain with an example.
3. Using an example array, explain how the merging process works in detail, including the
steps to combine two sorted subarrays.
1. Write a program to implement Bubble Sort in your preferred programming language and
demonstrate its working on an example array.
2. Analyze the time complexity of Bubble Sort for best, average, and worst cases with
examples.
3. Using an example array, explain the step-by-step process of Bubble Sort, including how
swaps are made during each pass.
1. Write a program to implement Heap Sort in your preferred programming language and
demonstrate its working on an example array.
2. Analyze the time complexity of Heap Sort for best, average, and worst cases with
examples.
3. Using an example array, explain how the heapify process works and how the heap is built
in Heap Sort.
1. Write a program to implement Shell Sort in your preferred programming language and
demonstrate its working on an example array.
2. Analyze the time complexity of Shell Sort for different gap sequences with examples.
3. Using an example array, explain how Shell Sort works step by step, including the effect
of changing the gap size.
1. Write a program to implement Radix Sort in your preferred programming language and
demonstrate its working on an example dataset.
2. Analyze the time and space complexity of Radix Sort with examples.
3. Using an example dataset, explain step-by-step how Radix Sort processes each digit and
maintains stability.
1. Write a program to implement Bucket Sort in your preferred programming language and
demonstrate its working on an example dataset.
2. Analyze the time and space complexity of Bucket Sort with examples.
3. Using an example dataset, explain step-by-step how Bucket Sort distributes, sorts, and
collects elements.