Unit 4: Trees and Recursion - Practice Quiz

CSE205 — Data Structures And Algorithms 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 In a binary tree, what is the maximum number of children a node can have?

A. 0
B. 1
C. 2
D. 3

2 What is a Complete Binary Tree?

A. A tree where the left child is smaller than the parent and the right child is larger.
B. A tree where every node has exactly two children.
C. A tree that contains no null pointers.
D. A binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

3 In an Extended Binary Tree (2-tree), nodes that replace NULL pointers in the original tree are called:

A. Sibling nodes
B. Internal nodes
C. Root nodes
D. External nodes

4 What is the maximum number of nodes in a binary tree of height 'h' (where the root is at height 1)?

A. 2^h - 1
B. 2^(h-1)
C. 2^h
D. h^2

5 If a binary tree has 'n' nodes, how many edges does it have?

A. n - 1
B. n + 1
C. 2n
D. n

6 When representing a binary tree using an array (sequential representation) with the root at index 0, what is the index of the left child of the node at index 'i'?

A. 2i + 1
B. 2i + 2
C. i + 1
D. 2i

7 When representing a binary tree using an array with the root at index 0, what is the index of the right child of the node at index 'i'?

A. i + 2
B. 2i + 2
C. 2i + 1
D. 2i

8 Which memory representation is most memory-efficient for a skewed binary tree?

A. Stack
B. Hash table
C. Sequential representation (Array)
D. Linked representation

9 In the linked representation of a binary tree, a node structure typically contains:

A. Data only
B. Data and an array index
C. Data, a pointer to the left child, and a pointer to the right child
D. Data and a pointer to the next node

10 Which traversal visits the root first, then the left subtree, then the right subtree?

A. Level-order
B. Post-order
C. Pre-order
D. In-order

11 Which traversal visits the left subtree, then the root, then the right subtree?

A. In-order
B. Pre-order
C. Post-order
D. Level-order

12 Which traversal visits the left subtree, then the right subtree, then the root?

A. Pre-order
B. In-order
C. Level-order
D. Post-order

13 What is the In-order traversal of a tree with Root A, Left Child B, and Right Child C?

A. C B A
B. B A C
C. B C A
D. A B C

14 Which traversal is useful for deleting nodes in a binary tree (freeing memory)?

A. In-order
B. Level-order
C. Pre-order
D. Post-order

15 Performing an In-order traversal on a Binary Search Tree (BST) results in:

A. Random order
B. The same sequence as Pre-order
C. Nodes in ascending sorted order
D. Nodes in descending order

16 To reconstruct a unique binary tree, which combination of traversals is sufficient?

A. Pre-order and In-order
B. Pre-order and Post-order
C. In-order and Level-order
D. Post-order and Level-order

17 What is the primary property of a Binary Search Tree (BST)?

A. Left child value < Root value < Right child value.
B. It is a complete binary tree.
C. Root value < Left child value < Right child value.
D. It must be balanced.

18 What is the worst-case time complexity for searching in a Binary Search Tree?

A. O(n)
B. O(n log n)
C. O(1)
D. O(log n)

19 What is the best-case time complexity for searching in a Binary Search Tree?

A. O(log n)
B. O(1)
C. O(n)
D. O(n^2)

20 When inserting a new node into a BST, the new node is always inserted as:

A. An internal node
B. The root
C. The right child of the root
D. A leaf node

21 Which node has the minimum value in a Binary Search Tree?

A. The leftmost node in the left subtree
B. The root
C. The rightmost node in the right subtree
D. A leaf node chosen randomly

22 When deleting a node with two children in a BST, which node can replace it to maintain the BST property?

A. The root node
B. Its right child
C. Its left child
D. Its In-order predecessor or In-order successor

23 What defines a 'base case' in recursion?

A. The first function call made.
B. The condition that stops the recursion.
C. The most complex instance of the problem.
D. A variable declared globally.

24 What happens if a recursive function does not have a base case?

A. It causes a Stack Overflow error.
B. It returns 0.
C. It runs once and stops.
D. It optimizes the code.

25 The Towers of Hanoi problem with 'n' disks requires a minimum of how many moves?

A. 2^n - 1
B. n^2
C. 2n - 1
D. n!

26 In the recursive solution to Towers of Hanoi, how many recursive calls are made to move n-1 disks?

A. 3
B. 2
C. n
D. 1

27 What data structure is implicitly used by the system to handle recursion?

A. Tree
B. Queue
C. Linked List
D. Stack

28 Which sorting algorithm uses the 'Divide and Conquer' strategy and merges two sorted subarrays?

A. Merge Sort
B. Insertion Sort
C. Quick Sort
D. Bubble Sort

29 What is the time complexity of Merge Sort in the worst case?

A. O(n)
B. O(n^2)
C. O(log n)
D. O(n log n)

30 Which of the following is a disadvantage of Merge Sort compared to Quick Sort?

A. It has a higher worst-case time complexity.
B. It requires O(n) auxiliary space.
C. It is unstable.
D. It is slower on linked lists.

31 Quick Sort uses which element to partition the array?

A. The smallest element
B. The accumulator
C. The midpoint
D. The pivot

32 What is the worst-case time complexity of Quick Sort?

A. O(n log n)
B. O(n)
C. O(log n)
D. O(n^2)

33 In Quick Sort, if the partition is always balanced (splits array in half), the time complexity is:

A. O(n log n)
B. O(n)
C. O(n^2)
D. O(log n)

34 Which sorting algorithm is generally considered the fastest in practice (average case) for arrays?

A. Selection Sort
B. Merge Sort
C. Quick Sort
D. Bubble Sort

35 Is Merge Sort a stable sorting algorithm?

A. No
B. Yes
C. Only for linked lists
D. Only for integers

36 What does 'Tail Recursion' mean?

A. Recursion with two base cases.
B. Recursion used for sorting.
C. Recursion where the recursive call is the last operation performed.
D. Recursion where the recursive call is the first statement.

37 In a binary tree, a node with no children is called a:

A. Subtree
B. Leaf
C. Parent
D. Root

38 The height of a binary tree with only a root node is:

A. 0
B. 2
C. Undefined
D. 1

39 If a Binary Search Tree is created from the sequence [10, 5, 20, 3, 7], which node is the left child of 5?

A. 3
B. 7
C. 10
D. 20

40 Which data structure concept is Towers of Hanoi primarily used to illustrate?

A. Recursion
B. Searching
C. Hashing
D. Sorting

41 In Quick Sort, what happens during the 'partition' step?

A. Elements are placed in their correct sorted position relative to the pivot.
B. The array is split in half.
C. Adjacent elements are swapped if they are in wrong order.
D. The smallest element is moved to the front.

42 Merge Sort on a Linked List can be implemented with:

A. It is not possible
B. O(n^2) auxiliary space
C. O(n) auxiliary space
D. O(1) auxiliary space

43 The traversal sequence 4, 2, 5, 1, 3 is obtained from a tree. If this is an In-order traversal and the Root is 1, what is the Left Subtree?

A. {3}
B. {2, 4, 5}
C. {4, 2, 5}
D. {5}

44 In a recursive function, the set of local variables is stored in a:

A. Register
B. Stack frame
C. Heap
D. Global memory

45 Which of the following is true about Quick Sort regarding stability?

A. It is not stable.
B. It is stable if implemented with a specific pivot.
C. Stability depends on the hardware.
D. It is always stable.

46 Which traversal is equivalent to a Depth First Search (DFS) on a tree?

A. Level-order
B. Both Pre-order and In-order
C. Pre-order
D. None of the above

47 What is the space complexity of the recursive implementation of Post-order traversal?

A. O(1)
B. O(n)
C. O(h) where h is height
D. O(n log n)

48 If the Pre-order traversal is AB and In-order traversal is BA, what is the structure of the binary tree?

A. Root A, Right Child B
B. Root A, Left Child B
C. Root B, Left Child A
D. Root B, Right Child A

49 Which operation is NOT supported efficiently by a standard Binary Search Tree?

A. Random Access
B. Search
C. Delete
D. Insert

50 In the context of recursion, what is 'Indirect Recursion'?

A. Function A calls a loop.
B. Function A calls Function B, and Function B calls Function A.
C. Function A calls Function A.
D. Function A uses a goto statement.