Unit 4: Recursion and Trees - Practice Quiz

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

1 What is recursion in programming?

Introduction to recursion Easy
A. An array sorting itself
B. A variable changing type
C. A function calling itself
D. A loop running forever

2 What is the purpose of a base case in a recursive function?

Introduction to recursion Easy
A. To repeat the first call
B. To create a new function
C. To stop the recursive calls
D. To increase the input size

3 What is the maximum number of children that a node in a binary tree can have?

Binary trees Easy
A. Two
B. Four
C. One
D. Three

4 Which statement describes a complete binary tree?

Complete binary trees Easy
A. Every node has exactly two children
B. All levels except possibly the last are full
C. Only the root may have children
D. Every level contains the same values

5 In an extended binary tree, what replaces each missing child of an original node?

Extended binary trees Easy
A. A duplicate node
B. An external node
C. A root node
D. A parent node

6 Which fields are commonly stored in a linked binary-tree node?

Linked memory representation of binary trees Easy
A. Front, rear, and queue size
B. Key, top, and stack size
C. Data, left link, and right link
D. Data, index, and array size

7 A binary tree stored in sequential memory is commonly represented using which structure?

Sequential memory representation of binary trees Easy
A. A linked list
B. A queue
C. An array
D. A hash table

8 In a zero-based array representation of a binary tree, what is the index of the left child of a node at index ?

Sequential memory representation of binary trees Easy
A.
B.
C.
D.

9 Which property is normally true for every node in a binary search tree with distinct keys?

Introduction to binary search trees Easy
A. Both children always have equal keys
B. Left keys are smaller and right keys are larger
C. All leaf keys are smaller than the root
D. Left keys are larger and right keys are smaller

10 While searching a binary search tree, where should the search continue if the target is smaller than the current node's key?

Binary search tree searching Easy
A. At the root again
B. In the right subtree
C. In the left subtree
D. At the deepest leaf

11 Where is a new key normally placed during binary search tree insertion?

Binary search tree insertion Easy
A. At an available leaf position
B. Between two sibling nodes
C. Directly above the root node
D. At the first array position

12 What is the simplest case of deleting a node from a binary search tree?

Binary search tree deletion Easy
A. Deleting a node with two children
B. Deleting the root node
C. Deleting a leaf node
D. Deleting a node with one child

13 When deleting a binary search tree node with two children, which value can replace it?

Binary search tree deletion Easy
A. Its in-order successor
B. Its leftmost ancestor
C. Its deepest descendant
D. Its original parent

14 What is the visiting order of recursive in-order traversal?

In-order traversal using recursion Easy
A. Left, root, right
B. Root, left, right
C. Right, root, left
D. Left, right, root

15 What is the visiting order of recursive pre-order traversal?

Pre-order traversal using recursion Easy
A. Right, left, root
B. Left, root, right
C. Root, left, right
D. Left, right, root

16 What is the visiting order of recursive post-order traversal?

Post-order traversal using recursion Easy
A. Left, right, root
B. Root, right, left
C. Root, left, right
D. Left, root, right

17 What is the minimum number of moves required to solve Towers of Hanoi with disks?

Recursive implementation of Towers of Hanoi Easy
A.
B.
C.
D.

18 In Towers of Hanoi, which disk may be placed on top of a larger disk?

Recursive implementation of Towers of Hanoi Easy
A. A larger disk
B. The bottom disk
C. A smaller disk
D. Any selected disk

19 What does merge sort do after recursively sorting two halves of a list?

Merge sort Easy
A. Reverses the sorted halves
B. Merges the sorted halves
C. Shuffles the sorted halves
D. Deletes one sorted half

20 Which element is selected to divide data into partitions in quick sort?

Quick sort Easy
A. A successor
B. A pointer
C. A sentinel
D. A pivot

21 Consider the recursive function:

f(n) = n + f(n - 2) for , with f(0) = 0 and f(1) = 1.

What is the value of f(6)?

Introduction to recursion Medium
A. 12
B. 9
C. 15
D. 21

22 A recursive algorithm makes one call with input and performs constant work during each call. Which recurrence and time complexity describe it?

Introduction to recursion Medium
A. ,
B. ,
C. ,
D. ,

23 A binary tree has 18 nodes. If every node except the root has exactly one incoming edge, how many edges does the tree contain?

Binary trees Medium
A. 19
B. 17
C. 36
D. 18

24 A complete binary tree contains 10 nodes stored in level order. At which zero-based array index will the next inserted node be placed?

Complete binary trees Medium
A. 20
B. 10
C. 11
D. 9

25 An extended binary tree is formed by replacing every null child pointer with an external node. If the original binary tree has 12 internal nodes, how many external nodes are added?

Extended binary trees Medium
A. 13
B. 11
C. 24
D. 12

26 A node in a linked binary tree has fields data, left, and right. If left is null and right points to another node, what does this indicate?

Linked memory representation of binary trees Medium
A. The node is necessarily a leaf
B. The node has only a right child
C. The node has only a left child
D. The node is necessarily the root

27 A binary tree is stored in a one-based array. If a node is stored at index 7, where are its left and right children stored, assuming both exist?

Sequential memory representation of binary trees Medium
A. Indices 15 and 16
B. Indices 13 and 14
C. Indices 14 and 15
D. Indices 7 and 8

28 Which sequence could be the in-order traversal of a binary search tree containing the keys 10, 4, 15, 7, and 12?

Introduction to binary search trees Medium
A. 4, 10, 7, 12, 15
B. 10, 4, 7, 15, 12
C. 4, 7, 10, 12, 15
D. 15, 12, 10, 7, 4

29 A binary search tree is formed by inserting 50, 30, 70, 20, 40, 60, and 80 in that order. Which keys are compared when searching for 60?

Binary search tree searching Medium
A. 50, 70, 80
B. 50, 30, 60
C. 50, 30, 40
D. 50, 70, 60

30 The keys 40, 20, 60, 10, 30, and 50 are inserted into an empty binary search tree in that order. Where will key 55 be inserted?

Binary search tree insertion Medium
A. As the left child of 50
B. As the right child of 60
C. As the left child of 60
D. As the right child of 50

31 In a binary search tree, a node with two children is deleted by replacing it with its in-order successor. Which node is selected as the successor?

Binary search tree deletion Medium
A. The minimum node in its left subtree
B. The maximum node in its right subtree
C. The parent node of the deleted node
D. The minimum node in its right subtree

32 A binary search tree is formed by inserting 40, 20, 60, 10, 30, and 50. If node 60 is deleted, which key directly replaces it using the standard one-child deletion rule?

Binary search tree deletion Medium
A. 40
B. 50
C. 30
D. 10

33 A binary tree has root A. Its left child B has children D and E, while its right child C has only a left child F. What is its recursive in-order traversal?

In-order traversal using recursion Medium
A. A, B, D, E, C, F
B. D, E, B, F, C, A
C. B, D, E, A, C, F
D. D, B, E, A, F, C

34 A binary tree has root 8. Its left subtree is rooted at 4 with children 2 and 6, and its right subtree is rooted at 12 with left child 10. What is its recursive pre-order traversal?

Pre-order traversal using recursion Medium
A. 8, 4, 2, 6, 12, 10
B. 8, 12, 10, 4, 6, 2
C. 2, 4, 6, 8, 10, 12
D. 2, 6, 4, 10, 12, 8

35 A binary tree has root M. Its left child G has children D and J, and its right child T has only a right child W. What is its recursive post-order traversal?

Post-order traversal using recursion Medium
A. M, G, D, J, T, W
B. D, J, G, W, T, M
C. J, D, G, W, M, T
D. D, G, J, T, W, M

36 In the recursive Towers of Hanoi solution for 4 disks, how many disk moves are required to transfer all disks from the source peg to the destination peg?

Recursive implementation of Towers of Hanoi Medium
A. 12
B. 16
C. 15
D. 8

37 To move Towers of Hanoi disks from peg A to peg C using peg B, what is the first major recursive operation?

Recursive implementation of Towers of Hanoi Medium
A. Move disks from A to B using C
B. Move disks from A to C using B
C. Move disks from B to C using A
D. Move the largest disk from A to B

38 During merge sort, the sorted subarrays [2, 7, 9] and [1, 6, 8] are merged. What is the array after the first four elements have been selected?

Merge sort Medium
A. [1, 2, 7, 9]
B. [1, 6, 8, 2]
C. [2, 7, 1, 6]
D. [1, 2, 6, 7]

39 Merge sort divides an array into two equal halves and spends linear time merging them. Which recurrence represents its running time?

Merge sort Medium
A.
B.
C.
D.

40 Using Lomuto partitioning on [4, 2, 7, 3, 6] with the final element 6 as the pivot, which array results immediately after partitioning?

Quick sort Medium
A. [4, 2, 6, 3, 7]
B. [6, 2, 3, 4, 7]
C. [2, 3, 4, 6, 7]
D. [4, 2, 3, 6, 7]

41 Let , , and for . What are the value of and the maximum number of simultaneously active calls when evaluating using direct recursion?

Introduction to recursion Hard
A. and 12 active calls
B. and 7 active calls
C. and 6 active calls
D. and 7 active calls

42 A binary tree contains 20 nodes and exactly 7 leaf nodes. How many nodes in the tree have exactly one child?

Binary trees Hard
A. 7 nodes
B. 8 nodes
C. 5 nodes
D. 6 nodes

43 A complete binary tree has 1000 nodes and uses zero-based array indexing. Which statement correctly identifies its leaves and last internal node?

Complete binary trees Hard
A. Leaves occupy indices 500 through 998; last internal index is 499
B. Leaves occupy indices 499 through 999; last internal index is 498
C. Leaves occupy indices 501 through 999; last internal index is 500
D. Leaves occupy indices 500 through 999; last internal index is 499

44 An extended binary tree is formed by replacing every missing child link of an ordinary binary tree with an external node. If the original tree has 23 internal nodes, how many external nodes and total nodes does the extended tree contain?

Extended binary trees Hard
A. 22 external nodes and 45 total nodes
B. 24 external nodes and 47 total nodes
C. 23 external nodes and 46 total nodes
D. 46 external nodes and 69 total nodes

45 A linked binary tree has ordinary nodes, and every node stores two child pointers. Assuming absent children are represented by null pointers, how many null pointers exist?

Linked memory representation of binary trees Hard
A. null pointers
B. null pointers
C. null pointers
D. null pointers

46 Using one-based sequential representation, a binary tree has a single node at depth 10, and that node is the rightmost possible node at that depth. What is the minimum array length required to represent it without compression?

Sequential memory representation of binary trees Hard
A. 2047 positions
B. 1023 positions
C. 1024 positions
D. 2048 positions

47 Consider the BST with root 50, whose left subtree is rooted at 30 with right child 40 and left child 10, and whose right subtree is rooted at 80 with left child 70, where 70 has right child 75. How many key comparisons are required to successfully search for 75?

Binary search tree searching Hard
A. 4 comparisons
B. 5 comparisons
C. 3 comparisons
D. 6 comparisons

48 Starting with an empty BST, insert the keys . How many comparisons are made while inserting key 34, counting the comparison at each visited node?

Binary search tree insertion Hard
A. 5 comparisons
B. 6 comparisons
C. 4 comparisons
D. 3 comparisons

49 A BST has root 50; its right subtree is rooted at 70, with left child 60 and right child 80; node 60 has left child 55 and right child 65. When deleting 50 using its in-order successor, what is the resulting root and the new left child of node 60?

Binary search tree deletion Hard
A. Root 55; node 60 has no left child
B. Root 65; node 60 has left child 55
C. Root 60; node 60 has left child 55
D. Root 60; node 60 has no left child

50 For the binary tree with root 8; left subtree rooted at 3 with children 1 and 6, where 6 has children 4 and 7; and right subtree rooted at 10 with right child 14, where 14 has left child 13, what is the recursive in-order traversal?

In-order traversal using recursion Hard
A. 1, 4, 7, 6, 3, 13, 14, 10, 8
B. 8, 3, 1, 6, 4, 7, 10, 14, 13
C. 1, 3, 4, 6, 7, 8, 10, 13, 14
D. 8, 1, 3, 4, 6, 7, 10, 13, 14

51 Using the same tree with root 8; left subtree rooted at 3 with children 1 and 6, where 6 has children 4 and 7; and right subtree rooted at 10 with right child 14, where 14 has left child 13, what is the recursive pre-order traversal?

Pre-order traversal using recursion Hard
A. 1, 3, 4, 6, 7, 8, 10, 13, 14
B. 8, 3, 1, 6, 4, 7, 10, 14, 13
C. 8, 10, 14, 13, 3, 1, 6, 4, 7
D. 8, 3, 1, 6, 4, 7, 10, 13, 14

52 Using the same tree with root 8; left subtree rooted at 3 with children 1 and 6, where 6 has children 4 and 7; and right subtree rooted at 10 with right child 14, where 14 has left child 13, what is the recursive post-order traversal?

Post-order traversal using recursion Hard
A. 1, 4, 7, 6, 3, 13, 14, 10, 8
B. 1, 3, 4, 6, 7, 8, 10, 13, 14
C. 8, 3, 1, 6, 4, 7, 10, 14, 13
D. 4, 7, 6, 1, 3, 13, 14, 10, 8

53 A standard recursive Towers of Hanoi implementation makes one recursive call for each smaller problem, performs one move, and makes another recursive call. Including calls with as invocations, how many total function calls and disk moves occur for ?

Recursive implementation of Towers of Hanoi Hard
A. 63 calls and 63 moves
B. 31 calls and 15 moves
C. 31 calls and 31 moves
D. 63 calls and 31 moves

54 What is the maximum number of element comparisons performed by standard top-down merge sort when sorting 10 elements, assuming each merge stops as soon as one subarray is exhausted?

Merge sort Hard
A. 25 comparisons
B. 23 comparisons
C. 19 comparisons
D. 22 comparisons

55 In a recursive merge sort implementation that splits until every subarray has one element, how many merge operations are performed when sorting 13 elements?

Merge sort Hard
A. 11 merge operations
B. 13 merge operations
C. 14 merge operations
D. 12 merge operations

56 Quick sort uses the last element as the pivot and Lomuto partitioning. What is the array immediately after partitioning around pivot 5?

Quick sort Hard
A.
B.
C.
D.

57 Quick sort always chooses the first element as pivot and partitions a sorted array of 1024 distinct elements into subarrays of sizes 0 and 1023. What are the comparison count and maximum recursion depth?

Quick sort Hard
A. 523,776 comparisons and depth 1024
B. 524,800 comparisons and depth 1024
C. 523,776 comparisons and depth 1023
D. 1,048,576 comparisons and depth 1024

58 A two-way quick sort partition treats values equal to the pivot as belonging to the same side rather than separating them. On an array of identical values, which complexity pair is most accurate for the resulting recursion?

Quick sort Hard
A. Time and stack
B. Time and stack
C. Time and stack
D. Time and stack

59 In a BST, a node with two children is deleted by replacing it with its in-order predecessor. If the predecessor has a left child but no right child, which structural operation is required after the replacement?

Binary search tree deletion Hard
A. Delete the predecessor without reconnecting any subtree
B. Attach the predecessor's left child to its former parent
C. Attach the predecessor's right child to its former parent
D. Replace the predecessor with its right subtree

60 Starting with an empty BST, insert . What are the height in edges and the number of leaves in the resulting tree?

Binary search tree insertion Hard
A. Height 3 and 3 leaves
B. Height 2 and 4 leaves
C. Height 3 and 4 leaves
D. Height 4 and 4 leaves