Trees Flashcards

1
Q

What is the order of nodes visited in an inorder traversal of a binary tree?

A

Left subtree, root, right subtree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: Inorder traversal of a binary tree results in nodes being visited in ascending order for a binary search tree.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What data structure is commonly used to implement iterative inorder traversal?

A

Stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fill in the blank: Inorder traversal is defined as visiting the _______ first, then the root, and finally the _______.

A

left subtree; right subtree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you perform a recursive inorder traversal?

A

Visit the left subtree, then the root, and finally the right subtree recursively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the time complexity of inorder traversal?

A

O(n), where n is the number of nodes in the tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which traversal method would you use to retrieve values in non-decreasing order from a binary search tree?

A

Inorder traversal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: Inorder traversal can be applied to non-binary trees.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the space complexity for recursive inorder traversal?

A

O(h), where h is the height of the tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following is NOT a type of tree traversal? A) Inorder B) Preorder C) Postorder D) Sideorder

A

D) Sideorder.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the result of inorder traversal on the following binary tree: 1 (root), 2 (left child), 3 (right child)?

A

2, 1, 3.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Fill in the blank: In a binary tree, inorder traversal visits the _______ child before the root.

A

left.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the primary purpose of inorder traversal?

A

To retrieve nodes in a sorted order for binary search trees.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False: Inorder traversal modifies the structure of the binary tree.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the main difference between inorder and preorder traversal?

A

Inorder visits left child, root, then right; preorder visits root, left child, then right.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the iterative algorithm for inorder traversal?

A

Use a stack to keep track of nodes; push left children until reaching null, then process the node and move to the right.

17
Q

In a binary tree with only one node, what is the result of an inorder traversal?

A

The single node itself.

18
Q

Fill in the blank: Inorder traversal is one of the _______ methods used to traverse a binary tree.

A

depth-first.

19
Q

Which traversal would you use to create a sorted list from a binary search tree?

A

Inorder traversal.

20
Q

True or False: The inorder traversal of a tree is unique.

A

False; different trees can have the same inorder traversal.

21
Q

What does the term ‘height of the tree’ refer to?

A

The length of the longest path from the root to a leaf.

22
Q

How many times is the root node visited during an inorder traversal?

23
Q

What is the key advantage of using an iterative approach for inorder traversal?

A

It avoids the risk of stack overflow with very deep trees.

24
Q

Fill in the blank: The inorder traversal of a complete binary tree produces a _______ output.

25
Which programming language feature is often used to implement tree traversals?
Recursion.
26
In a binary tree, if the inorder traversal results in the sequence 4, 2, 5, 1, 6, 3, what can we infer about the structure of the tree?
It is a binary search tree.
27