Data Structures Exam II Chapters 22-27
The height of an empty tree is _______.
-1
The balance factor of every node in an AVL tree may be _________. Please select all that apply.
0 1 -1
1 & 3 is _________.
1
For a sorted list of 1024 elements, a binary search takes at most _______ comparisons.
11
Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the postorder traversal of the elements?
12 21 92 45 4 3
Suppose you insert the numbers 1, 2, 3, 4, 5 into an AVL tree in this order, what is the preorder traversal of the tree?
2 1 4 3 5
Suppose a list is {2, 9, 5, 4, 8, 1}. After the first pass of bubble sort, the list becomes
2, 5, 4, 8, 1, 9
For an Integer object with value 20, what is its hashCode?
20
What is the preorder traversal of the elements in an AVL tree after inserting 3, 4, 45, 21, 92, 12 in this order?
21 4 3 12 45 92
Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the inorder traversal of the elements?
3 4 12 21 45 92
Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the preorder traversal of the elements after deleting 45 from the tree?
3 4 21 12 92
1 << 2 is _________.
4
Suppose you choose the first element as a pivot in the list {5 2 9 3 8 4 0 1 6 7}. Using the partition algorithm in the book, what is the new list after the partition?
4 2 1 3 0 5 8 9 6 7
Suppose a heap is stored in an array list as follows: {100, 55, 92, 23, 33, 81}. The parent of 81 is _______.
92
Which of the following statements are true?
A binary tree is complete if every level of the tree is full except that the last level may not be full and all the leaves on the last level are placed left-most. Each node is greater than or equal to any of its children. A heap is a complete binary tree.
________ is a data structure to store data in sequential order.
A list
The time complexity for search, insertion, and deletion is O(logn) for a(n) ___________.
AVL tree
When a new node is inserted to the end of a linked list, will head and tail be changed?
All of the above
When a new node is inserted to the head of a linked list, will head and tail be changed?
All of the above.
Why is the analysis often for the worst case? Please select all that apply.
Average-case analysis is ideal, but difficult to perform, because it is hard to determine the relative probabilities and distributions of various input instances for many problems. Worst-case is not representative, but worst-case analysis is very useful. You can show that the algorithm will never be slower than the worst-case. Best-case is not representative.
A(n) __________ (with no duplicate elements) has the property that for every node in the tree the value of any node in its left subtree is less than the value of the node and the value of any node in its right subtree is greater than the value of the node. Please select all that apply.
Avl tree Binary search tree
In a(n) ________, the element j to be removed is always at the root.
Binary heap
In a(n) ________, the element just inserted is always at the leaf.
Binary search tree
The worst time-complexity for search, insertion, and deletion in a(n) ________ is O(n).
Binary search tree
Suppose list1 is an ArrayList and list2 is a LinkedList implemented using a doubly-linked list. Analyze the following code: A: while (list1.size() > 0) list1.remove(list1.size() - 1); B: while (list2.getSize() > 0) list2.removeLast();
Code fragment A runs as fast as code fragment B.
Suppose list1 is an ArrayList and list2 is a singly LinkedList. Analyze the following code: A: while (list1.size() > 0) list1.remove(list1.size() - 1); B: while (list2.size() > 0) list2.removeLast();
Code fragment A runs faster than code fragment B.
______________ approach is the process of solving subproblems, then combining the solutions of the subproblems to obtain an overall solution. This naturally leads to a recursive solution. However, it would be inefficient to use recursion, because the subproblems overlap. The key idea behind dynamic programming is to solve each subproblem only once and store the results for subproblems for later use to avoid redundant computing of the subproblems.
Dynamic programming
True or False? Two objects are equal if their hash codes are equal.
False
Which of the following operations are supported by a list? Please select all that apply.
Find how many elements are in this list. Retrieve an element from this list. Find whether an element is in this list. Insert a new element to this list. Delete an element from this list.
A Huffman tree is constructed using a ____________ algorithm.
Greedy
In the implementation of LinkedList, which of the following is false?
If a linked list contains one element, head points to the node and tail is null.
What is the return type for the hashCode() method?
Int
If a node has a balance factor -2 and its left child node has a balance factor 1 or 0. This node is _____.
LR imbalance
The ________ of a path is the number of the edges in the path.
Length
When a collision occurs during the insertion of an entry to a hash table, ______ finds the next available location sequentially.
Linear probing
Which of the following statements are true? Please select all that apply.
MyArrayList and MyLinkedList are two concrete implementations of MyList. MyArrayList is implemented using an array. The array is dynamically created. If the capacity of the array is exceeded, create a new larger array and copy all the elements from the current array to the new array. MyLinkedList is implemented using a linked structure. A linked structure consists of nodes. Each node is dynamically created to hold an element. All the nodes are linked together to form a list.
In the implementation of MyStack and MyQueue, which of the following are true? Please select all that apply.
MyQueue contains a linked list for storing elements. MyStack contains an array list for storing elements.
A heap is represented using an array. Is the array {1, 2, 4, 5, 9, 3} a heap?
No
In the implementation of BST, which of the following are true? Please select all that apply.
Node has a property named left that links to the left subtree and a property named right that links to the right subtree and a property named element. Node is defined as a static inner class inside BST because it does not reference any instance data fields in BST. Node is defined as an inner class inside BST. BST contains a property named root. If tree is empty, root is null.
What is the time-complexity for the addFirst method?
O(1)
What is the time-complexity for the addLast method?
O(1)
What is the time-complexity for the removeFirst method?
O(1)
The time complexity for the Towers of Hanoi algorithm in the text is ________.
O(2^n)
The time complexity for the recursive Fibonacci algorithm in the text is ________.
O(2^n)
The time complexity for the Euclid's algorithm is ________.
O(logn)
The best-time complexity for bubble sort is _____________.
O(n)
The best-time complexity for insertion sort is _____________.
O(n)
The time complexity for deleting an element from a binary search tree is _______.
O(n)
The time complexity for inserting an element into a binary search tree is _______.
O(n)
The time complexity for searching an element in a binary search tree is _______.
O(n)
The time complexity for the Fibonacci algorithm using the dynamic programming approach is ________.
O(n)
The time to merge two sorted lists of size n is _________.
O(n)
What is the time-complexity for the add(int index, T element) method?
O(n)
What is the time-complexity for the get(int index) method?
O(n)
What is the time-complexity for the remove(int index) method?
O(n)
What is the time-complexity for the removeLast method?
O(n)
The worst-time complexity for bubble sort is _____________.
O(n*n)
The worst-time complexity for insertion sort is _____________.
O(n*n)
The worst-time complexity for quick sort is _________.
O(n*n)
The average-time complexity for heap sort is _________
O(nlogn)
The average-time complexity for merge sort is _________.
O(nlogn)
The average-time complexity for quick sort is _________.
O(nlogn)
The worst-time complexity for heap sort is _________
O(nlogn)
The worst-time complexity for merge sort is _________.
O(nlogn)
If each key is mapped to a different index in the hash table, it is called
Perfect hashing
Which data structure is appropriate to store patients in an emergency room?
Priority queue
Which of the following are true? Please select all that apply.
Question 1 of 3 ; 3 of 3 points Multiple Choice Quiz 24.9: Question 1 Unlimited tries Which of the following are true? Please select all that apply. Since the insertion and deletion operations on a stack are made only at the end of the stack, you can use either an ArrayList or a LinkedList. However, ArrayList has less overhead than LinkedList. Since deletions are made at the beginning of the list, it is more efficient to implement a queue using a LinkedList than an ArrayList. A stack can be viewed as a special type of list, where the elements are accessed, inserted, and deleted only from the end, called the top, of the stack. A queue represents a waiting list. A queue can be viewed as a special type of list, where the elements are inserted into the end (tail) of the queue, and are accessed and deleted from the beginning (head) of the queue.
Suppose the rule of the party is that the participants who arrive earlier will leave earlier. Which data structure is appropriate to store the participants?
Queue
Which data structure is appropriate to store customers in a clinic for taking flu shots?
Queue
If a node has a balance factor 2 and its right child node has a balance factor 1 or 0. This node is _____.
RR imbalance
The __________ algorithm does not compare keys.
Radix sort
Which of the following is correct to create a TreeNode for integer 50. Please select all that apply.
TreeNode<Integer> node = new TreeNode<Integer>(50); TreeNode<Integer> node = new TreeNode<>(50);
A new element is always inserted into a leaf node.
True
If two strings are equal, the two strings have the same hash code.
True
True or False? Assume N and hashCode are positive and N is an integer of power of 2, hashCode % N is the same as hashCode & (N - 1).
True
True or False? Two objects have the same hash codes if they are equal.
True
True or False? You can traverse the elements in a BST using a foreach loop.
True
A heap is represented using an array list. Is the array list {64, 42, 59, 32, 39, 44} a heap?
Yes
The _________ of a node is the height of its right subtree minus the height of its left subtree.
balance factor
An input that results in the shortest execution time is called the _____________.
best-case input
A __________ (with no duplicate elements) has the property that for every node in the tree the value of any node in its left subtree is less than the value of the node and the value of any node in its right subtree is greater than the value of the node.
binary search tree
What is the return type for the search function?
boolean
The _________ is to visit the nodes level by level. First visit the root, then all children of the root from left to right, then grandchildren of the root from left to right, and so on.
breadth-first traversal
In the implementation of MyArrayList, which of the following are true? Please select all that apply.
capacity never reduces unless you apply the trimToSize() method. Inside MyArrayList, a regular array is used to store elements. If the current capacity equals to size, capacity is doubled + 1 when a new element is added to MyArrayList
O(1) is ________.
constant time
What is the signature of the recursive method in BTView.java?
displayTree(BST.TreeNode<Integer>, double, double, double)
If a list is empty, which of following statements is false?
head != tail
An AVLTreeNode object contains the data fields _______. Please select all that apply.
height left right element
In the LinkedList class, which of the following statements are to append a string s to the end of the list?
list.add(s);
In the LinkedList class, which of the following statements is to insert a string s to the head of the list?
list.addFirst(s);
hash function
maps a key to an index in the hash table
The most efficient algorithm for sorting integer keys is __________.
radix sort
In the implementation of MyArrayList, which of the following are true? Please select all that apply.
size indicates the number of elements in the list. size is reduced by 1 if an element is deleted from the list. capacity is the length of the array used to store the elements in the list.
In the implementation of MyLinkedList, which of the following are true? Please select all that apply.
tail.next is always null. If a linked list is empty, head is null and tail is null. MyLinkedList has the properties named head and tail to point to the nodes in a linked list.
What is the number of iterations in the following loop: int count = 5; while (count < n) { count = count + 3; }
the ceiling of (n - 5) / 3
To add a new node, you need to start a process by first placing it as _______ and move it up to maintain the heap property.
the last node in the heap
To remove the root, you need to start a process by first placing _______ to the place of the root and move it down to maintain the heap property.
the last node in the heap
Analyzing algorithm efficiency is ________.
to estimate their growth function
A collision occurs _____________.
when two or more keys are mapped to the same hash value.
Suppose a heap is stored in an array list as follows: {100, 55, 92, 23, 33, 81}. After inserting 103, what is the content of the array list?
{103, 55, 100, 23, 33, 81, 92}