Binary search trees/Recursion

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards

False

True/False: The number of nodes in a binary tree is the number of nodes in its left subtree plus the number of nodes in its right subtree.

2
New cards

root pointer

The ________ in a binary tree is analogous to the head pointer in a linked list.

A) null pointer

B) binary pointer

C) root pointer

D) leaf pointer

E) None of the above

3
New cards

True

True/False: A subtree is the collection of some node, together with all its descendants.

4
New cards

nodes in a binary tree have two successors instead of one.

The main difference between a binary tree and a linked list is that

A) a linked list can be empty, but a binary tree cannot.

B) recursion is useful on binary trees, but not on linked lists.

C) nodes in a binary tree have two successors instead of one.

D) a binary tree can be empty, but a linked list cannot.

E) None of the above

5
New cards

NULL .

If a node has no successor, the corresponding pointer is set to

A) point to its parent node.

B) NULL .

C) the root of the tree.

D) a leaf.

E) None of the above

6
New cards

the root of the tree.

Implementing a binary tree in a class requires a structure for representing the nodes of the binary tree, as well as a pointer to the structure as a class member. This pointer will be set to

A) the root of the tree.

B) the first leaf node.

C) the leftmost child node.

D) the deepest leaf node.

E) None of the above

7
New cards

Both A and B, but not C

Recursion can be used to

A) compute factorials.

B) find the greatest common divisor of two integers (GCD).

C) program things that cannot be programmed without recursion.

D) All of the above

E) Both A and B, but not C

8
New cards

does not correctly handle its base case.

The function

int fact(int k)

{

return k*fact(k-1);

if (k==0) return 1;

}

A) returns the value 1 if it is passed a value of 0 for the parameter k.

B) works for all non-negative values of k, but not for negative numbers.

C) computes the factorial on an integer k passed to it as parameter.

D) does not correctly handle its base case.

E) None of the above

9
New cards

determined by the order in which values are inserted.

The shape of a binary search tree is

A) determined by the order in which values are inserted.

B) always triangular.

C) determined by the programmer.

D) always balanced.

E) None of the above

10
New cards

D) All of the above

One method of traversing a binary tree is

A) preorder traversal.

B) postorder traversal.

C) inorder traversal.

D) All of the above

E) None of the above

11
New cards

True

True/False: Deleting a leaf node from a binary search tree is not difficult. Deleting a non-leaf node requires several steps.

12
New cards

True

True/False: There exists a binary tree with a hundred nodes, but only one leaf.

13
New cards

True

True/False: The preorder method of traversing a binary tree involves processing the root node's

data, traversing the left subtree, and then traversing the right subtree.

14
New cards

recursion.

Inorder, preorder, and postorder traversals can be accomplished using

A) recursion.

B) no pointers.

C) no parameters.

D) no arguments.

E) None of the above.

15
New cards

True

True/False: In a binary search tree where all the stored values are different, the node holding the largest value cannot have two children.

16
New cards

True

True/False: The smallest number of levels that a binary tree with three nodes can have is two.

17
New cards

three levels.

A tree with a height of three must have

A) three levels.

B) six nodes.

C) three subtrees.

D) one root and three nodes with two children each.

E) None of the above

18
New cards

True

True/False: The width of a tree is the largest number of nodes at the same level.

19
New cards

True

True/False: In a binary search tree, all nodes to the right of a node hold values greater than the node's value.

20
New cards

False

True/False: In certain types of binary trees, the number of leaves can be greater than the number of

nodes.

21
New cards

True

True/False: Binary trees are commonly used to organize key values that index database records.

22
New cards

D) All of the above

An operation that can be performed on a binary search tree is

A) insertion of new value.

B) removing a value stored in the tree.

C) searching the tree for the occurrence of a given value.

D) All of the above

E) None of the above

23
New cards

two pointers, one for the left child and one for the right child.

A binary tree can be created using a structure containing a data value and

A) two pointers, one for the left child and one for the right child.

B) a pointer to the last child node.

C) a pointer to the first child node.

D) two data nodes.

E) None of the above

24
New cards

its root node.

A program keeps track of a binary tree using a pointer to

A) its root node.

B) one of its leaves.

C) the node in the tree holding the smallest value.

D) the node in the tree holding the biggest value.

E) None of the above

25
New cards

its left and right child.

Every node in a binary tree can have pointers to

A) its left and right child.

B) its end nodes.

C) binary nodes.

D) its left and right parent.

E) None of the above

26
New cards

in database applications

Binary search trees are commonly used

A) with arrays of integers.

B) in linear data communication processes.

C) in database applications.

D) A and C

E) None of the above

27
New cards

left, node's

Values are commonly stored in a binary search tree so that a node's ________ child holds data that is less than the ________ data, while the node's data is less than the data in the other child.

A) left, right child's

B) left, node's

C) right, node's

D) right, left child's

E) None of the above

28
New cards

is hardest when the node has two children.

Deleting a node from a binary search tree node

A) is hardest when the node is a leaf.

B) is easiest when the node is the root.

C) is hardest when the node has two children.

D) is hardest when the node has one child.

E) None of the above

29
New cards

False

True/False: Output will be the same if you use inorder, postorder, or preorder traversals to print the values stored in a binary tree.

30
New cards

True

True/False: The height of a binary tree describes how many levels there are in the tree.

31
New cards

traversing the tree.

Visiting all nodes of a binary tree in some methodical fashion is known as

A) walking through tree.

B) climbing the tree.

C) branching out along the tree.

D) traversing the tree.

E) None of the above

32
New cards

D) All of the above

Binary search trees may be implemented as templates, but any data types used with them should support the ________ operator.

A) >

B) <

C) ==

D) All of the above

E) None of the above

33
New cards

to expedite the process of searching large sets of information.

A strong reason to use a binary search tree is

A) it is more flexible than the unary search tree.

B) aesthetics and program design.

C) to expedite the process of searching large sets of information.

D) to enhance code readability.

E) None of the above

34
New cards

True

True/False: Binary trees are called "trees" because they resemble an upside-down tree.

35
New cards

root node.

A binary tree node with no parent is called the

A) head pointer.

B) pointer node.

C) root node.

D) binary node.

E) None of the above

36
New cards

leaf node

A node that has no children is a

A) head node.

B) root node.

C) pure binary node.

D) leaf node.

E) None of the above

37
New cards

E) None of the above

A child node that has no parent is

A) a rootless node.

B) a leaf node.

C) an orphan node.

D) A or C

E) None of the above

38
New cards

True

True/False: The inorder method of traversing a binary tree involves traversing the left subtree,

processing the data in the root, and then traversing the right subtree.

39
New cards

binary search tree.

When a binary tree is used to facilitate a search, it is referred to as a

A) binary queue.

B) binary search tree.

C) sort algorithm.

D) binary ordered deque.

E) None of the above

40
New cards

the root node.

When an application begins searching a binary search tree, it starts at

A) the middle node, halfway between the root and the longest branch.

B) the outermost leaf node.

C) the rightmost child of the root node.

D) the root node.

E) None of the above

41
New cards

E) both A and D

The advantage of a linear search is that

A) it can be used on unordered data.

B) it is efficient.

C) it is fast.

D) it is simple.

E) both A and D

42
New cards

A) binary, linear

A(n) ________ search is more efficient than a(n) ________ search.

A) binary, linear

B) string, double

C) integer, double

D) linear, binary

E) None of the above. All searches are equally efficient

43
New cards

A) middle

A binary search begins by examining the ________ element of an array.

A) middle

B) last

C) smallest

D) first

E) largest

44
New cards

A) selection, bubble

The ________ sort usually performs fewer exchanges than the ________ sort.

A) selection, bubble

B) linear, bubble

C) linear, binary

D) bubble, selection

E) binary, linear

45
New cards

C) 50

To find a value that is in an unordered array of 100 items, linear search must examine an average of ________ values.

A) 7

B) 10

C) 50

D) 100

E) 101

46
New cards

B) 5 3 7 2 6 9

If a bubble sort is used to arrange the numbers 7 5 3 9 2 6 in ascending order, what order will the data be in after the first pass?

A) 5 7 3 9 2 6

B) 5 3 7 2 6 9

C) 2 5 3 9 7 6

D) 2 3 5 6 7 9

E) none of the above

47
New cards

A) 2 5 3 9 7 6

If a selection sort is used to arrange the numbers 7 5 3 9 2 6 in ascending order, what order will the data be in after the first pass?

A) 2 5 3 9 7 6

B) 2 3 5 6 7 9

C) 5 7 3 9 2 6

D) 5 3 7 2 6 9

E) none of the above

48
New cards

B) 7

If a binary search is used to search for the number 4 in the 11-element array shown below, which value will the 4 be compared to first? 1 2 3 4 6 7 8 9 10 12 17

A) 1

B) 7

C) 8

D) 9

E) 17

49
New cards

A) 6 4 8 3 7 9

If a bubble sort is used to arrange the numbers 8 6 4 9 3 7 in ascending order, what order will the data be in after the first pass of the sort is completed?

A) 6 4 8 3 7 9

B) 6 8 4 9 3 7

C) 3 4 6 7 8 9

D) 3 6 4 9 8 7

E) None of the above

50
New cards

B) 3 6 4 9 8 7

If a selection sort is used to arrange the numbers 8 6 4 9 3 7 in ascending order, what order will the data be in after the first pass of the sort is completed?

A) 6 4 8 3 7 9

B) 3 6 4 9 8 7

C) 3 4 6 7 8 9

D) 6 8 4 9 3 7

E) None of the above