Deck 10: Trees

Full screen (f)
exit full mode
Question
A min-heap is a binary tree in which each node is less than or equal to both of its children.
Use Space or
up arrow
down arrow
to flip the card.
Question
A file system is similar to a binary search tree.
Question
With trees, each item, including the first and last, have a distinct successor.
Question
An access, an insertion, or a removal of a node in vine-like tree with N nodes and a height of N - 1 would be linear in the worst case.
Question
The heap sort algorithm builds a heap from a set of data and then repeatedly removes the leaf item and adds it to the end of a list.
Question
A grammar in a programming language consists of a vocabulary, syntax rules, and a list of operators.
Question
The height of an empty tree is -1.
Question
You should use a postorder iteration method for the tree's __iter__ method to enable the user to create a clone of the tree with the same shape as the original.
Question
In a tree, an interior node is a node that has no children.
Question
In a tree, the root item has no parent item.
Question
In the replace method for a binary search tree interface, None is returned if the first argument cannot be found.
Question
Because the recursive search algorithm doesn't require a parameter for a tree node, you can define it as a top-level method.
Question
The preorder traversal algorithm traverses the left subtree, visits the root node, and traverses the right subtree.
Question
Two trees are considered equal if they contain the same items in the same positions.
Question
The level order traversal guides the visits to items from left to right through the levels of the tree, much like reading lines of text in a document.
Question
An expression tree is never empty.
Question
The maximum amount of work that it takes to access a given node in a full binary tree is O( N ).
Question
When a linked binary search tree is instantiated, the self.root variable is set to self .
Question
The inorder traversal algorithm visits a tree's root node and then traverses the left subtree and the right subtree in a similar manner.
Question
A parse tree describes the syntactic structure of a sentence in terms of its component parts.
Question
Syntax rules specify how sentences in the language should be interpreted.
Question
Which type of binary tree traversal visits the tree's root node, the left subtree and then the right subtree?

A) postorder traversal
B) inorder traversal
C) preorder traversal
D) unordered traversal
Question
The number of comparisons required for a removal in an array-based heap is at most log2 n , so the pop operation is O(log n ).
Question
The peek method in a heap implementation returns the bottom most item in the heap.
Question
Which type of binary tree traversal traverses the left subtree, visits, the root node, and traverses the right subtree?

A) postorder traversal
B) inorder traversal
C) preorder traversal
D) unordered traversal
Question
Which of the following is true about a max-heap?

A) each node is less than or equal to its children
B) the largest nodes are nearer to the root
C) the largest items are in the leaves
D) the smallest item is in the root node
Question
Array-based binary trees are the easiest to define and implement.
Question
Which is true about binary search trees?

A) they cannot support logarithmic insertions
B) they can support logarithmic searches
C) they don't work well for sorted collections
D) each node in the right subtree of a given node is less than that node
Question
In a tree, which of the following is true?

A) all items have a distinct predecessor and successor
B) each item can have multiple children
C) each item can have multiple parents
D) the root has exactly one parent
Question
Which type of binary tree traversal traverses the left subtree, traverses the right subtree, and then visits the root node?

A) postorder traversal
B) inorder traversal
C) preorder traversal
D) unordered traversal
Question
Which of the following is described as a node's parent, its parent's parent, and so on up to the root?

A) descendant
B) path
C) depth
D) ancestor
Question
What is the formula for determining the number of nodes in a full binary tree where H is the height of the tree?

A) 2 H - 1 + 1
B) 2 H + 1
C) 2 H + 1
D) 2 H + 1 - 1
Question
One of the types of symbols used by an EBNF is metasymbols.
Question
What is the height of a full binary tree with 63 nodes?

A) 5
B) 8
C) 6
D) 7
Question
Which of the following is NOT a common application for a binary tree?

A) heap
B) expression tree
C) search tree
D) stack
Question
Which of the following is the topmost node in a tree and does not have a parent?

A) root
B) child
C) leaf
D) interior node
Question
What is the number of nodes in a full binary tree with a height of 4?

A) 23
B) 19
C) 31
D) 47
Question
Which of the following is true about a binary tree?

A) each node has at most two children
B) each node has only one child
C) child nodes can have multiple parents
D) the root node must have only one child
Question
When the shape of a BST approaches that of a perfectly balanced binary tree, what is the worst case performance characteristic of searches and insertions?

A) O(log n )
B) O n
C) O( n )
D) O(log2 n )
Question
What kind of tree would be useful in analyzing the syntax of a sentence?

A) binary search tree
B) sorting tree
C) parse tree
D) linear tree
Question
In the following code for the find method, what is the missing code? def find(self, item):
Def recurse(node):
If node is None:
Return None
Elif item == node.data:
< missing code >
Elif item < node.data:
Return recurse(node.left)
Else:
Return recurse(node.right)
Return recurse(self.root)

A) return node.data
B) return self.data
C) return recurse(node.root)
D) return node.root
Question
In the code for the inorder method for a binary search tree, what is the missing code? def inorder(self):
Lyst = list()
Def recurse(node):
If node != None:
< missing code >
Lyst.append(node.data)
Recurse(node.right)
Recurse(self.root)
Return iter(lyst)

A) recurse(node.root)
B) return(node.data)
C) recurse(node.left)
D) return iter(self.root)
Question
Which of the following carries out the actions specified by a sentence?

A) interpreter
B) parser
C) recognizer
D) compiler
Question
Which traversal type guides visits to items in the tree from left to right through the levels of the tree?

A) levelorder
B) inorder
C) preorder
D) postorder
Question
Which symbol type is NOT found in an EBNF?

A) terminal symbols
B) metasymbols
C) hypersymbols
D) nonterminal symbols
Question
In the code for the add method in the implementation of a heap, what is the missing code? def add(self, item):
Self.size += 1
Self.heap.append(item)
CurPos = len(self.heap) - 1
While curPos > 0:
Parent = (curPos - 1) // 2
ParentItem = self.heap[parent]
If parentItem <= item:
< missing code >
Else:
Self.heap[curPos] = self.heap[parent]
Self.heap[parent] = item
CurPos = parent

A) curPos += 1
B) break
C) self.heap[ curPos ] = item
D) parent = curpos
Question
What type of traversal occurs in the binary search trees __iter__ method?

A) sequential
B) postorder
C) preorder
D) inorder
Question
In the following code for the __init__ method for the linked binary search tree, what is the missing code? def __init__(self, sourceCollection = None):
< missing code >
AbstractCollection.__init__(sourceCollection)

A) self.root = sourceCollection
B) self.root = None
C) sourceCollection.__init__(AbstractCollection)
D) self.leaf = root
Question
What operator causes the __contains__ method to run in the binary search tree implementation?

A) =
B) is
C) +
D) in
Question
Which of the following is not a part of a grammar?

A) vocabulary
B) semantic rules
C) syntax rules
D) method rules
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 10: Trees
1
A min-heap is a binary tree in which each node is less than or equal to both of its children.
True
2
A file system is similar to a binary search tree.
False
3
With trees, each item, including the first and last, have a distinct successor.
False
4
An access, an insertion, or a removal of a node in vine-like tree with N nodes and a height of N - 1 would be linear in the worst case.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
The heap sort algorithm builds a heap from a set of data and then repeatedly removes the leaf item and adds it to the end of a list.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
A grammar in a programming language consists of a vocabulary, syntax rules, and a list of operators.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
The height of an empty tree is -1.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
You should use a postorder iteration method for the tree's __iter__ method to enable the user to create a clone of the tree with the same shape as the original.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
In a tree, an interior node is a node that has no children.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
In a tree, the root item has no parent item.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
In the replace method for a binary search tree interface, None is returned if the first argument cannot be found.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
Because the recursive search algorithm doesn't require a parameter for a tree node, you can define it as a top-level method.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
The preorder traversal algorithm traverses the left subtree, visits the root node, and traverses the right subtree.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Two trees are considered equal if they contain the same items in the same positions.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
The level order traversal guides the visits to items from left to right through the levels of the tree, much like reading lines of text in a document.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
An expression tree is never empty.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
The maximum amount of work that it takes to access a given node in a full binary tree is O( N ).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
When a linked binary search tree is instantiated, the self.root variable is set to self .
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
The inorder traversal algorithm visits a tree's root node and then traverses the left subtree and the right subtree in a similar manner.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
A parse tree describes the syntactic structure of a sentence in terms of its component parts.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
Syntax rules specify how sentences in the language should be interpreted.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Which type of binary tree traversal visits the tree's root node, the left subtree and then the right subtree?

A) postorder traversal
B) inorder traversal
C) preorder traversal
D) unordered traversal
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
The number of comparisons required for a removal in an array-based heap is at most log2 n , so the pop operation is O(log n ).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
The peek method in a heap implementation returns the bottom most item in the heap.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
Which type of binary tree traversal traverses the left subtree, visits, the root node, and traverses the right subtree?

A) postorder traversal
B) inorder traversal
C) preorder traversal
D) unordered traversal
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following is true about a max-heap?

A) each node is less than or equal to its children
B) the largest nodes are nearer to the root
C) the largest items are in the leaves
D) the smallest item is in the root node
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
Array-based binary trees are the easiest to define and implement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
Which is true about binary search trees?

A) they cannot support logarithmic insertions
B) they can support logarithmic searches
C) they don't work well for sorted collections
D) each node in the right subtree of a given node is less than that node
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
In a tree, which of the following is true?

A) all items have a distinct predecessor and successor
B) each item can have multiple children
C) each item can have multiple parents
D) the root has exactly one parent
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
Which type of binary tree traversal traverses the left subtree, traverses the right subtree, and then visits the root node?

A) postorder traversal
B) inorder traversal
C) preorder traversal
D) unordered traversal
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following is described as a node's parent, its parent's parent, and so on up to the root?

A) descendant
B) path
C) depth
D) ancestor
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
What is the formula for determining the number of nodes in a full binary tree where H is the height of the tree?

A) 2 H - 1 + 1
B) 2 H + 1
C) 2 H + 1
D) 2 H + 1 - 1
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
One of the types of symbols used by an EBNF is metasymbols.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
What is the height of a full binary tree with 63 nodes?

A) 5
B) 8
C) 6
D) 7
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following is NOT a common application for a binary tree?

A) heap
B) expression tree
C) search tree
D) stack
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following is the topmost node in a tree and does not have a parent?

A) root
B) child
C) leaf
D) interior node
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
What is the number of nodes in a full binary tree with a height of 4?

A) 23
B) 19
C) 31
D) 47
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
Which of the following is true about a binary tree?

A) each node has at most two children
B) each node has only one child
C) child nodes can have multiple parents
D) the root node must have only one child
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
When the shape of a BST approaches that of a perfectly balanced binary tree, what is the worst case performance characteristic of searches and insertions?

A) O(log n )
B) O n
C) O( n )
D) O(log2 n )
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
What kind of tree would be useful in analyzing the syntax of a sentence?

A) binary search tree
B) sorting tree
C) parse tree
D) linear tree
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
In the following code for the find method, what is the missing code? def find(self, item):
Def recurse(node):
If node is None:
Return None
Elif item == node.data:
< missing code >
Elif item < node.data:
Return recurse(node.left)
Else:
Return recurse(node.right)
Return recurse(self.root)

A) return node.data
B) return self.data
C) return recurse(node.root)
D) return node.root
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
In the code for the inorder method for a binary search tree, what is the missing code? def inorder(self):
Lyst = list()
Def recurse(node):
If node != None:
< missing code >
Lyst.append(node.data)
Recurse(node.right)
Recurse(self.root)
Return iter(lyst)

A) recurse(node.root)
B) return(node.data)
C) recurse(node.left)
D) return iter(self.root)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following carries out the actions specified by a sentence?

A) interpreter
B) parser
C) recognizer
D) compiler
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
Which traversal type guides visits to items in the tree from left to right through the levels of the tree?

A) levelorder
B) inorder
C) preorder
D) postorder
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
Which symbol type is NOT found in an EBNF?

A) terminal symbols
B) metasymbols
C) hypersymbols
D) nonterminal symbols
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
In the code for the add method in the implementation of a heap, what is the missing code? def add(self, item):
Self.size += 1
Self.heap.append(item)
CurPos = len(self.heap) - 1
While curPos > 0:
Parent = (curPos - 1) // 2
ParentItem = self.heap[parent]
If parentItem <= item:
< missing code >
Else:
Self.heap[curPos] = self.heap[parent]
Self.heap[parent] = item
CurPos = parent

A) curPos += 1
B) break
C) self.heap[ curPos ] = item
D) parent = curpos
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
What type of traversal occurs in the binary search trees __iter__ method?

A) sequential
B) postorder
C) preorder
D) inorder
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
In the following code for the __init__ method for the linked binary search tree, what is the missing code? def __init__(self, sourceCollection = None):
< missing code >
AbstractCollection.__init__(sourceCollection)

A) self.root = sourceCollection
B) self.root = None
C) sourceCollection.__init__(AbstractCollection)
D) self.leaf = root
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
What operator causes the __contains__ method to run in the binary search tree implementation?

A) =
B) is
C) +
D) in
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Which of the following is not a part of a grammar?

A) vocabulary
B) semantic rules
C) syntax rules
D) method rules
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.