Data Structures Final Exam

0.0(0)
Studied by 7 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/77

flashcard set

Earn XP

Description and Tags

78 Terms

1
New cards
root
Given a root of a Binary search tree, return the minimum value in the tree

Node \*Node::minValueNode(Node \*root)

{

Node\* temp = ____________;

\
while (temp->left != NULL)
{
temp = temp->left;
}

\
return (temp);
}
2
New cards
temp->left != NULL
Given a root of a Binary search tree, return the minimum value in the tree

Node \*Node::minValueNode(Node \*root\*)\*

{

Node\* temp = root;

while (____________________)
{
temp = temp->left;
}

return (temp);
}
3
New cards
temp->left
\
Given a root of a Binary search tree, return the minimum value in the tree
Node \*Node::minValueNode(Node root*)*
{

Node\* temp = root;

while (temp->left != NULL)
{
temp = _______________;
}

return (temp);
}
4
New cards
(temp)
\
Given a root of a Binary search tree, return the minimum value in the tree

Node \*Node::minValueNode(Node \*root)

{

Node temp = root;

while (temp->left != NULL)
{
temp = temp->left;
}

return _________________;
}
5
New cards
element
This function gets a node and the root of the Binary Search Tree and inserts the node into the BST. Then, it returns the root after insertion.
Node* insert(Node *root, Node *element)
{
// Inserting into an empty tree.
if (root == NULL)
{
return ________________;
}
else
{
// element should be inserted to the right.
if (element->data > root->data)
{
// There is a right subtree to insert the node.
if (root->right != NULL)
root->right = insert(root->right, element);
// Place the node directly to the right of root.
else
root->right = element;
}
// element should be inserted to the left.
else
{
// There is a left subtree to insert the node.
if (root->left != NULL)
root->left = insert(root->left, element);
// Place the node directly to the left of root.
else
root->left = element;
}
// Return the root pointer of the updated tree.
return root;
}
}
6
New cards
element->data > root->data
This function gets a node and the root of the Binary Search Tree and inserts the node into the BST. Then, it returns the root after insertion.
Node* insert(Node *root, Node *element)
{
// Inserting into an empty tree.
if (root == NULL)
{
return element;
}
else
{
// element should be inserted to the right.
if (___________________)
{
// There is a right subtree to insert the node.
if (root->right != NULL)
root->right = insert(root->right, element);
// Place the node directly to the right of root.
else
root->right = element;
}
// element should be inserted to the left.
else
{
// There is a left subtree to insert the node.
if (root->left != NULL)
root->left = insert(root->left, element);
// Place the node directly to the left of root.
else
root->left = element;
}
// Return the root pointer of the updated tree.
return root;
}
}
7
New cards
root->right != NULL
This function gets a node and the root of the Binary Search Tree and inserts the node into the BST. Then, it returns the root after insertion.
Node* insert(Node *root, Node *element)
{
// Inserting into an empty tree.
if (root == NULL)
{
return element;
}
else
{
// element should be inserted to the right.
if (element->data > root->data)
{
// There is a right subtree to insert the node.
if (________________)
root->right = insert(root->right, element);
// Place the node directly to the right of root.
else
root->right = element;
}
// element should be inserted to the left.
else
{
// There is a left subtree to insert the node.
if (root->left != NULL)
root->left = insert(root->left, element);
// Place the node directly to the left of root.
else
root->left = element;
}
// Return the root pointer of the updated tree.
return root;
}
}
8
New cards
insert(root->right, element)
This function gets a node and the root of the Binary Search Tree and inserts the node into the BST. Then, it returns the root after insertion.
Node* insert(Node *root, Node *element)
{
// Inserting into an empty tree.
if (root == NULL)
{
return element;
}
else
{
// element should be inserted to the right.
if (element->data > root->data)
{
// There is a right subtree to insert the node.
if (root->right != NULL)
root->right = __________________________;
// Place the node directly to the right of root.
else
root->right = element;
}
// element should be inserted to the left.
else
{
// There is a left subtree to insert the node.
if (root->left != NULL)
root->left = insert(root->left, element);
// Place the node directly to the left of root.
else
root->left = element;
}
// Return the root pointer of the updated tree.
return root;
}
}
9
New cards
root->right = element
This function gets a node and the root of the Binary Search Tree and inserts the node into the BST. Then, it returns the root after insertion.
Node* insert(Node *root, Node *element)
{
// Inserting into an empty tree.
if (root == NULL)
{
return element;
}
else
{
// element should be inserted to the right.
if (element->data > root->data)
{
// There is a right subtree to insert the node.
if (root->right != NULL)
root->right = insert(root->right, element);
// Place the node directly to the right of root.
else
____________________;
}
// element should be inserted to the left.
else
{
// There is a left subtree to insert the node.
if (root->left != NULL)
root->left = insert(root->left, element);
// Place the node directly to the left of root.
else
root->left = element;
}
// Return the root pointer of the updated tree.
return root;
}
}
10
New cards
root->left != NULL
This function gets a node and the root of the Binary Search Tree and inserts the node into the BST. Then, it returns the root after insertion.
Node* insert(Node *root, Node *element)
{
// Inserting into an empty tree.
if (root == NULL)
{
return element;
}
else
{
// element should be inserted to the right.
if (element->data > root->data)
{
// There is a right subtree to insert the node.
if (root->right != NULL)
root->right = insert(root->right, element);
// Place the node directly to the right of root.
else
root->right = element;
}
// element should be inserted to the left.
else
{
// There is a left subtree to insert the node.
if (___________________)
root->left = insert(root->left, element);
// Place the node directly to the left of root.
else
root->left = element;
}
// Return the root pointer of the updated tree.
return root;
}
}
11
New cards
insert(root->left, element)
This function gets a node and the root of the Binary Search Tree and inserts the node into the BST. Then, it returns the root after insertion.
Node* insert(Node *root, Node *element)
{
// Inserting into an empty tree.
if (root == NULL)
{
return element;
}
else
{
// element should be inserted to the right.
if (element->data > root->data)
{
// There is a right subtree to insert the node.
if (root->right != NULL)
root->right = insert(root->right, element);
// Place the node directly to the right of root.
else
root->right = element;
}
// element should be inserted to the left.
else
{
// There is a left subtree to insert the node.
if (root->left != NULL)
root->left = _____________________;
// Place the node directly to the left of root.
else
root->left = element;
}
// Return the root pointer of the updated tree.
return root;
}
}
12
New cards
root->left = element
This function gets a node and the root of the Binary Search Tree and inserts the node into the BST. Then, it returns the root after insertion.
Node* insert(Node *root, Node *element)
{
// Inserting into an empty tree.
if (root == NULL)
{
return element;
}
else
{
// element should be inserted to the right.
if (element->data > root->data)
{
// There is a right subtree to insert the node.
if (root->right != NULL)
root->right = insert(root->right, element);
// Place the node directly to the right of root.
else
root->right = element;
}
// element should be inserted to the left.
else
{
// There is a left subtree to insert the node.
if (root->left != NULL)
root->left = insert(root->left, element);
// Place the node directly to the left of root.
else
____________________;
}
// Return the root pointer of the updated tree.
return root;
}
}
13
New cards
return root
This function gets a node and the root of the Binary Search Tree and inserts the node into the BST. Then, it returns the root after insertion.
Node* insert(Node *root, Node *element)
{
// Inserting into an empty tree.
if (root == NULL)
{
return element;
}
else
{
// element should be inserted to the right.
if (element->data > root->data)
{
// There is a right subtree to insert the node.
if (root->right != NULL)
root->right = insert(root->right, element);
// Place the node directly to the right of root.
else
root->right = element;
}
// element should be inserted to the left.
else
{
// There is a left subtree to insert the node.
if (root->left != NULL)
root->left = insert(root->left, element);
// Place the node directly to the left of root.
else
root->left = element;
}
// Return the root pointer of the updated tree.
_________________;
}
}
14
New cards
currentPtr != NULL
This function prints the inorder traversal of the tree pointed to by root.
void inorder(Node *currentPtr)
{
// Only traverse the node if it's not null.
if (__________________)
{
inorder(currentPtr->left); // Go Left.
cout<<" "<<currentPtr->data; // Print the root.
inorder(currentPtr->right); // Go Right.
}
}
15
New cards
inorder(currentPtr->left)
This function prints the inorder traversal of the tree pointed to by root.
void inorder(Node *currentPtr)
{
// Only traverse the node if it's not null.
if (currentPtr != NULL)
{
__________________________; // Go Left.
cout<<" "<<currentPtr->data; // Print the root.
inorder(currentPtr->right); // Go Right.
}
}
16
New cards
cout<<" "<<currentPtr->data
This function prints the inorder traversal of the tree pointed to by root.
void inorder(Node *currentPtr)
{
// Only traverse the node if it's not null.
if (currentPtr != NULL)
{
inorder(currentPtr->left); // Go Left.
______________________________; // Print the root.
inorder(currentPtr->right); // Go Right.
}
}
17
New cards
inorder(currentPtr->right)
This function prints the inorder traversal of the tree pointed to by root.
void inorder(Node *currentPtr)
{
// Only traverse the node if it's not null.
if (currentPtr != NULL)
{
inorder(currentPtr->left); // Go Left.
cout<<" "<<currentPtr->data; // Print the root.
_________________________; // Go Right.
}
}
18
New cards
root == NULL
This function gets the root of the tree and returns the number of nodes in the tree.
int numNodes(Node* root)
{
if (______________)
return 0;
return 1 + numNodes(root->left) + numNodes(root->right);
}
19
New cards
1 + numNodes(root->left) + numNodes(root->right)
This function gets the root of the tree and returns the number of nodes in the tree.
int numNodes(Node* root)
{
if (root == NULL)
return 0;
return _______________________________________;
}
20
New cards
int numNodesLeft
This function gets the root of a BST tree and an integer k. It returns the kth smallest value in the BST pointed to by root.
int findKthSmallest(Node* root, int k)
{
__________________ = numNodes(root->left);

if (numNodesLeft >= k)
return findKthSmallest(root->left, k);
else if (numNodesLeft == k-1)
return root->data;
else
return findKthSmallest(root->right, k-numNodesLeft-1);
}
21
New cards
numNodes(root->left)
This function gets the root of a BST tree and an integer k. It returns the kth smallest value in the BST pointed to by root.
int findKthSmallest(Node* root, int k)
{
int numNodesLeft = _______________________;

if (numNodesLeft >= k)
return findKthSmallest(root->left, k);
else if (numNodesLeft == k-1)
return root->data;
else
return findKthSmallest(root->right, k-numNodesLeft-1);
}
22
New cards
numNodesLeft >= k
This function gets the root of a BST tree and an integer k. It returns the kth smallest value in the BST pointed to by root.
int findKthSmallest(Node* root, int k)
{
int numNodesLeft = numNodes(root->left);

if (______________________)
return findKthSmallest(root->left, k);
else if (numNodesLeft == k-1)
return root->data;
else
return findKthSmallest(root->right, k-numNodesLeft-1);
}
23
New cards
findKthSmallest(root->left, k)
This function gets the root of a BST tree and an integer k. It returns the kth smallest value in the BST pointed to by root.
int findKthSmallest(Node* root, int k)
{
int numNodesLeft = numNodes(root->left);

if (numNodesLeft >= k)
return _________________________;
else if (numNodesLeft == k-1)
return root->data;
else
return findKthSmallest(root->right, k-numNodesLeft-1);
}
24
New cards
numNodesLeft == k-1
This function gets the root of a BST tree and an integer k. It returns the kth smallest value in the BST pointed to by root.
int findKthSmallest(Node* root, int k)
{
int numNodesLeft = numNodes(root->left);

if (numNodesLeft >= k)
return findKthSmallest(root->left, k);
else if (___________________)
return root->data;
else
return findKthSmallest(root->right, k-numNodesLeft-1);
}
25
New cards
root->data
This function gets the root of a BST tree and an integer k. It returns the kth smallest value in the BST pointed to by root.
int findKthSmallest(Node* root, int k)
{
int numNodesLeft = numNodes(root->left);

if (numNodesLeft >= k)
return findKthSmallest(root->left, k);
else if (numNodesLeft == k-1)
return __________________;
else
return findKthSmallest(root->right, k-numNodesLeft-1);
}
26
New cards
findKthSmallest(root->right, k-numNodesLeft-1)
This function gets the root of a BST tree and an integer k. It returns the kth smallest value in the BST pointed to by root.
int findKthSmallest(Node* root, int k)
{
int numNodesLeft = numNodes(root->left);

if (numNodesLeft >= k)
return findKthSmallest(root->left, k);
else if (numNodesLeft == k-1)
return root->data;
else
return ________________________________________;
}
27
New cards
1 -> 2 ->3 -> 4
2 -> 1 -> 3
3 -> 1 ->2
4 -> 1 -> 5
5 -> 4
Show the adjacency list representation for the following graph.
Show the adjacency list representation for the following graph.
28
New cards
d) O(n)
What is the worst-case runtime for searching for an element in a BST?

* a) O(1)


* b) O(logn)
* c) O(n^2)
* d) O(n)
29
New cards
a) O(1)
What is the best-case runtime for searching for an element in a BST?

* a) O(1)
* b) O(logn)
* c) O(n^2)
* d) O(n)
30
New cards
d) O(logn)
What is the worst-case runtime for searching for an element in an AVL tree?

* a) O(n)
* b) O(n^2)
* c) O(1)
* d) O(logn)
31
New cards
d) 3
The following numbers are inserted into an empty binary search tree in the given order: 8, 12, 4, 6, 32, 24, 10. What is the height of the binary search tree? (Height: Length of the longest path from the root to a leaf (# of edges on the longest path))

* a) 2
* b) 4
* c) 1
* d) 3
32
New cards
c) -2
Suppose we insert the following values into an (initially empty) AVL, in this order:

7, 5, 13, 9, 18, 26

Using the following balance factor formula, what is the balance factor at node 7 (the root) in the resulting AVL (before doing any rotations)?

BF = hL-hR

* a) +2
* b) -1
* c) -2
* d) +1
33
New cards
d) 50, 28, 32, 26, 20, 16, 24
Consider a binary max-heap implemented using an array. Which one of the following arrays represents a binay max-heap?

* a) 50, 24, 32, 26, 20, 16, 28
* b) 50, 28, 24, 26, 20, 16, 32
* c) 50, 24, 32, 26, 20, 16, 28
* d) 50, 28, 32, 26, 20, 16, 24
34
New cards
d) O(1)
In a binary max-heap containing n numbers, the maximum element can be found in time…

* a) O(n)
* b) O(n^2)
* c) O(logn)
* d) O(1)
35
New cards
c) O(logn)
What is the height (in Big-O notation) of a binary heap with n elements?

* a) O(n)
* b) O(n^2)
* c) O(logn)
* d) O(1)
36
New cards
c) O(nlogn)
What is the worst-case time complexity of heap sort?

* a) O(logn)
* b) O(n)
* c) O(nlogn)
* d) O(n^2)
37
New cards
b) Priority queue
Heap is a good data structure to implement ______________.

* a) Queue
* b) Priority queue
* c) Lists
* d) None
38
New cards
A→right
Complete the following leftRotate function with respect to the following binary tree:

Node\* leftRotate(Node \*A)

{

Node\* B = ______________;

Node\* T1 = B→left;

\
//rotate the nodes

B→left = A;

A→right = T1;

\
//return the new root

return B;

}
Complete the following leftRotate function with respect to the following binary tree:

Node\* leftRotate(Node \*A)

{

Node\* B = ______________;

Node\* T1 = B→left;

\
//rotate the nodes

B→left = A;

A→right = T1;

\
//return the new root

return B;

}
39
New cards
B→left
Complete the following leftRotate function with respect to the following binary tree:

Node\* leftRotate(Node \*A)

{

Node\* B = A→right;

Node\* T1 = _________________;

\
//rotate the nodes

B→left = A;

A→right = T1;

\
//return the new root

return B;

}
Complete the following leftRotate function with respect to the following binary tree:

Node\* leftRotate(Node \*A)

{

Node\* B = A→right;

Node\* T1 = _________________;

\
//rotate the nodes

B→left = A;

A→right = T1;

\
//return the new root

return B;

}
40
New cards
B→left = A, A→right = T1
Complete the following leftRotate function with respect to the following binary tree:

Node\* leftRotate(Node \*A)

{

Node\* B = A→right;

Node\* T1 = B→left;

\
//rotate the nodes

____________________;

____________________;

\
//return the new root

return B;

}
Complete the following leftRotate function with respect to the following binary tree:

Node\* leftRotate(Node \*A)

{

Node\* B = A→right;

Node\* T1 = B→left;

\
//rotate the nodes

____________________;

____________________;

\
//return the new root

return B;

}
41
New cards
return B
Complete the following leftRotate function with respect to the following binary tree:

Node\* leftRotate(Node \*A)

{

Node\* B = A→right;

Node\* T1 = B→left;

\
//rotate the nodes

B→left = A;

A→right = T1;

\
//return the new root

_______________;

}
Complete the following leftRotate function with respect to the following binary tree:

Node\* leftRotate(Node \*A)

{

Node\* B = A→right;

Node\* T1 = B→left;

\
//rotate the nodes

B→left = A;

A→right = T1;

\
//return the new root

_______________;

}
42
New cards
index 5
Consider the following arbitrary complete binary tree which is stored in an array. The root of the tree is at index 1. The tree has currently 11 nodes.

If you want to build a max heap from this array using heapify operation, from what index you need to start the process of percolate down? Write the index number based on the tree.
Consider the following arbitrary complete binary tree which is stored in an array. The root of the tree is at index 1. The tree has currently 11 nodes.

If you want to build a max heap from this array using heapify operation, from what index you need to start the process of percolate down? Write the index number based on the tree.
43
New cards
b) O(n)
What is the run-time to build a heap from an arbitrary array with n numbers using heapify?

a) O(n^2)

b) O(n)

c) O(logn)

d) O(nlogn)
44
New cards
d) O(nlogn)
What is the run-time to build a heap from an arbitrary array with n numbers WITHOUT using heapify?

a) O(n^2)

b) O(n)

c) O(logn)

d) O(nlogn)
45
New cards
index 0 = 25; index 1 = 6; index 2 = “empty”; index 3 = 2; index 4 = “empty”; index 5 = 9; index 6 = “empty”; index 7 = “empty”; index 8 = 3; index 9 = 1; index 10 = 14
Consider a hash table that uses the linear probing technique with the following hash function f(x) = (5x+4)%11. (The hash table is of size 11.)

If we insert the values 3, 9, 2, 1, 14, 6 and 25 into the table, in that order, show where these values would end up in the table by writing the values in the corresponding indices.
Consider a hash table that uses the linear probing technique with the following hash function f(x) = (5x+4)%11. (The hash table is of size 11.) 

If we insert the values 3, 9, 2, 1, 14, 6 and 25 into the table, in that order, show where these values would end up in the table by writing the values in the corresponding indices.
46
New cards
b) root
Top node in a tree is called the

* a) leaves
* b) root
* c) branch
* d) height
47
New cards
a) leaves
Nodes that have no children are called

* a) leaves
* b) height
* c) root
* d) branch
48
New cards
d) height
The ___________ of a tree is defined to be the length of the longest path from the root to a leaf in that tree.

* a) root
* b) leaves
* c) branch
* d) height
49
New cards
false
(T/F) A tree with only one node (the root) had a height of 1.
50
New cards
b) binary tree
What kind of tree is this?


1. each node can have at most ***2*** children
2. each node can have no child, one child, or two children

* a) AVL tree
* b) binary tree
* c) complete binary tree
* d) full binary tree
51
New cards
a) full binary tree
What kind of tree is this?


1. every node, other than the leaves, has two children
2. each node is either a leaf or has exactly two child nodes

* a) full binary tree
* b) binary tree
* c) AVL tree
* d) complete binary tree
52
New cards
c) complete binary tree
What kind of tree is this?


1. every level, except possibly the last, is completely filled
2. all nodes are as far left as possible

* a) binary tree
* b) AVL tree
* c) complete binary tree
* d) full binary tree
53
New cards
a) full
Determine if the tree depicted is full, complete, both full and complete, or neither.

* a) full
* b) complete
* c) full and complete
* d) neither full nor complete
Determine if the tree depicted is full, complete, both full and complete, or neither.

* a) full
* b) complete
* c) full and complete
* d) neither full nor complete
54
New cards
d) neither full nor complete
Determine if the tree depicted is full, complete, both full and complete, or neither.

* a) full
* b) complete
* c) full and complete
* d) neither full nor complete
Determine if the tree depicted is full, complete, both full and complete, or neither.

* a) full
* b) complete
* c) full and complete
* d) neither full nor complete
55
New cards
b) complete
Determine if the tree depicted is full, complete, both full and complete, or neither.

* a) full
* b) complete
* c) full and complete
* d) neither full nor complete
Determine if the tree depicted is full, complete, both full and complete, or neither.

* a) full
* b) complete
* c) full and complete
* d) neither full nor complete
56
New cards
c) full and complete
Determine if the tree depicted is full, complete, both full and complete, or neither.

* a) full
* b) complete
* c) full and complete
* d) neither full nor complete
Determine if the tree depicted is full, complete, both full and complete, or neither.

* a) full
* b) complete
* c) full and complete
* d) neither full nor complete
57
New cards
a) Depth First Search (DFS)
This tree traversal technique explores a path all the way to a leaf before backtracking and exploring another path.

* a) Depth First Search (DFS)
* b) Breadth First Search (BFS)
* c) Inorder Traversal
* d) Preorder Traversal
* e) Postorder Traversal
58
New cards
e) Breadth First Search (BFS)
This tree traversal technique explores levels in order. Every node in a level should be visited before going to the next level.

* a) Preorder Traversal
* b) Postorder Traversal
* c) Depth First Search (DFS)
* d) Inorder Traversal
* e) Breadth First Search (BFS)
59
New cards
b) Preorder Traversal
This tree traversal method uses DFS where the root is visited before its left and right subtrees.

* a) Fororder Traversal
* b) Preorder Traversal
* c) Inorder Traversal
* d) Postorder Traversal
60
New cards
a) Inorder traversal
This tree traversal method uses DFS where the root is visited between the subtrees.

* a) Inorder traversal
* b) Postorder traversal
* c) Fororder traversal
* d) Preorder traversal
61
New cards
c) Postorder traversal
This tree traversal method uses DFS where the root is visited after both subtrees.

* a) Inorder traversal
* b) Preorder traversal
* c) Postorder traversal
* d) Fororder traversal
62
New cards
p != NULL
Preorder traversal where the root is visited before its left and right subtrees.

void preorder(Node\* p)

{

if (____________)

{

cout<<p→data<<endl;

preorder(p→left_child);

preorder(p→right_child);

}

}
63
New cards
p→data
Preorder traversal where the root is visited before its left and right subtrees.

void preorder(Node\* p)

{

if (p != NULL)

{

cout<<____________<<endl;

preorder(p→left_child);

preorder(p→right_child);

}

}
64
New cards
preorder(p→left_child)
Preorder traversal where the root is visited before its left and right subtrees.

void preorder(Node\* p)

{

if (p != NULL)

{

cout<<p→data<<endl;

_____________________;

preorder(p→right_child);

}

}
65
New cards
preorder(p→right_child)
Preorder traversal where the root is visited before its left and right subtrees.

void preorder(Node\* p)

{

if (p != NULL)

{

cout<<p→data<<endl;

preorder(p→left_child);

____________________;

}

}
66
New cards
inorder(p→left_child)
Inorder traversal where the root is visited between the left and right subtrees.

void inorder(Node \* p)

{

if (p != NULL)

{

____________________;

cout<<p→data<<endl;

inorder(p→right_child);

}

}
67
New cards
p→data
Inorder traversal where the root is visited between the left and right subtrees.

void inorder(Node \* p)

{

if (p != NULL)

{

inorder(p→left_child);

cout<<__________<<endl;

inorder(p→right_child);

}

}
68
New cards
inorder(p→right_child)
Inorder traversal where the root is visited between the left and right subtrees.

void inorder(Node \* p)

{

if (p != NULL)

{

inorder(p→left_child);

cout<<p→data<<endl;

____________________;

}

}
69
New cards
postorder(p→left_child)
Postorder Traversal where the root is visited after the left and right subtrees.

void postorder(Node\* p)

{

if (p != NULL)

{

______________________;

postorder(p→right_child);

cout<<p→data<<endl;

}

}
70
New cards
postorder(p→right_child)
Postorder Traversal where the root is visited after the left and right subtrees.

void postorder(Node\* p)

{

if (p != NULL)

{

postorder(p→left_child);

_____________________;

cout<<p→data<<endl;

}

}
71
New cards
p→data
Postorder Traversal where the root is visited after the left and right subtrees.

void postorder(Node\* p)

{

if (p != NULL)

{

postorder(p→left_child);

postorder(p→right_child);

cout<<_________<<endl;

}

}
72
New cards
d) O(logn)
Normally if we search through n nodes, it takes O(n) time. But by using a binary search tree, the search space is halved resulting in what time?

* a) O(n^2)
* b) O(nlogn)
* c) O(n^3)
* d) O(logn)
73
New cards
true
(T/F) When building a Binary Search Tree (BST), new values less than the root go to the left and new values greater than the root go to the right.
74
New cards
true
(T/F) In a balanced binary tree, the height of the left and right subtree of any node differ by not more than 1.
75
New cards
true
(T/F) AVL trees are self-balancing BSTs.
76
New cards
true
(T/F) An AVL tree can have only balance factors of -1, 0, or 1 at every node in the tree.
77
New cards
false
(T/F) An AVL tree can have the height of the left and right subtrees differ by more than 1 for every node in the tree.
78
New cards
0, yes
What is the balance factor of the root of this tree? Is this tree an AVL tree?
What is the balance factor of the root of this tree? Is this tree an AVL tree?