Programming Fundamentals III - Java - Final
T or F: A heap is a binary tree (in which each node contains a Comparable key value), with two special properties; an ORDER property and SHAPE property.
True
T or F: Algorithms like quick sort -- that work by dividing the problem in two, solving the smaller versions, and then combining the solutions -- are called divide and conquer algorithms.
True
T or F: Binary search can perform operations get, floorEntry and ceilingEntry on an ordered map implemented by means of an array-based sequence, sorted by key.
True
Which one of the following has all the correct SHAPE property of Heap? A) 1. All leaves are either at depth d or d-1 (for some value d). 2. All of the leaves at depth d-1 are to the right of the leaves at depth d. 3. (a) There is at most 1 node with just 1 child. (b) That child is the left child of its parent, and (c) it is the rightmost leaf at depth d. B) 1. All leaves are either at depth d or d-1 (for some value d). 2. All of the leaves at depth d-1 are to the left of the leaves at depth d. 3. (a) There is at most 1 node with just 1 child. (b) That child is the left child of its parent, and (c) it is the leftmost leaf at depth d. C) 1. All leaves are either at depth d or d-1 (for some value d). 2. All of the leaves at depth d-1 are to the right go the leaves at depth d. 3. (a) There is at most 1 node with just 1 child. (b) That child is the left child of its parent, and (c) it is the leftmost leaf at depth d. D) None of the above.
A) 1. All leaves are either at depth d or d-1 (for some value d). 2. All of the leaves at depth d-1 are to the right of the leaves at depth d. 3. (a) There is at most 1 node with just 1 child. (b) That child is the left child of its parent, and (c) it is the rightmost leaf at depth d.
Quick sort algorithm outline is: A) 1. Choose a pivot value. 2. Partition the array (put all value less than the pivot in the left part of the array, then the pivot itself, then all values greater than the pivot). 3. Recursively, sort the values less than the pivot. 4. Recursively, sort the values greater than the pivot. B) 1. Choose a pivot value. 2. Partition the array (put all value greater than the pivot in the right part of the array, then the pivot itself, then all values greater than the pivot). 3. Recursively, sort the values less than the pivot. 4. Recursively, sort the values greater than the pivot. C) 1. Choose a pivot value. 2. Partition the array (put all value less than the pivot in the right part of the array, then the pivot itself, then all values greater than the pivot). 3. Recursively, sort the values greater than the pivot. 4. Recursively, sort the values greater than the pivot. D) None of the above
A) 1. Choose a pivot value. 2. Partition the array (put all value less than the pivot in the left part of the array, then the pivot itself, then all values greater than the pivot). 3. Recursively, sort the values less than the pivot. 4. Recursively, sort the values greater than the pivot.
Which of the following algorithms do we use to search a key in BST? A) Algorithm Treesearch(k,v) if v.isExternal () return v if k < v.key() return TreeSearch(k, v.left()) else if k = v.key() return v else {k > v.key()} return TreeSearch(k, v.right()) B) Algorithm TreeSearch(k, v) if v.isExternal() return v if k = v.key() return v else { k > v.key()} return TreeSearch(k, v.right()) C) Algorithm TreeSearch(k, v) if v.isExternal() return v if {k > v.key()} return TreeSearch(k, v.right()) D) Algorithm TreeSearch(k, v) TreeSearch(k, v.left()) else if k = v.key() return v else {k > v.key()} return TreeSearch(k, v.right())
A) Algorithm TreeSearch(k, v) if v.isExternal() return v if k < v.key() return TreeSearch(k, v.left()) else if k = v.key() return v else {key > v.key()} return TreeSearch(k, v.right())
Which of the following has the correct ORDER property of HEAP? A) For every node n, the value in n is less than or equal to the values in its children (and thus is also greater than or equal to all of the values in its subtrees). B) For every node n, the value in n is greater than or equal to the values in its children (and thus is also greater than or equal to all of the values in its subtrees). C) For every node n, the value in n is equal to the values in its children (and thus is also greater than or equal to all of the values in its subtrees). D) This is red and black tree property not heap.
B) For every node n, the value in n is greater than or equal to the values in its children (and thus is also greater than or equal to all of the values in its subtrees).
AVL Tree performance with respect to time complexity is as follows: A) find takes O(n log n) time put takes O(n log n) time erase takes O(n log n) time B) find takes O(log n) time put takes O(log n) time erase takes O(log n) time C) find takes O(log) time put takes O(log) time erase takes O(log) time D) find takes O(n) time put takes O(n) time erase takes O(n) time
B) find takes O(log n) time put takes O(log n) time erase takes O(log n) time
To sort an array of length N using Merge sort following steps must be taken: A) 1. Divide the array into two halves. 2. Recursively, sort the left half. 3. Recursively, sort the left half. 4. Merge the two sorted halves. B) 1. Divide the array into two halves. 2. Recursively, sort the right half. 3. Recursively, sort the left half. 4. Merge the two sorted halves. C) 1. Divide the array into two halves. 2. Recursively, sort the left half. 3. Recursively, sort the right half. 4. Merge the two sorted halves. D) 1. Divide the array into ten halves. 2. Recursively, sort the left half. 3. Recursively, sort the right half. 4. Merge all the sorted halves.
C) 1. Divide the array into two halves. 2. Recursively, sort the left half. 3. Recursively, sort the right half. 4. Merge the two sorted halves.
A binary search tree is a binary tree storing keys (or key-value entries) at its internal nodes by satisfying which of the following: A) Let u, v, and w be three nodes such that u is in the left subtree of v and w is in the right subtree of v. We have key(u) >= key(v) >= key(w) B) Let u, v, and w be three nodes such that u is in the left subtree of v and w is in the right subtree of v. We have key(u) = key(v) = key(w) C) Let u, v, and w be three nodes such that u is in the left subtree of v and w is in the right subtree of v. We have key(u) <= key(v) <= key(w) D) None of the above.
C) Let u, v, and w be three nodes such that u is in the left subtree of v and w is in the right subtree of v. We have key(u) <= key(v) <= key(w)
T or F: AVL Tree is a binary search tree such that for every internal node v of T, the heights of the children of v can differ by at most 56.
False
T or F: Following is one of the properties of graph: In an undirected graph with no self-loops and no multiple edges m >= n(n - 1)/2 Proof: each vertex had degree at most (n-1)
False
T or F: General-purpose data structures are arrays, linked lists, trees, hash tables, quick sort, and stack
False
T or F: In BST the height h is O(n) in the worst case and O(n log n) in the best case.
False
T or F: Java stores only objects, not actual references
False
T or F: ceilingEntry takes O(n log n) time, using binary search.
False
T or F: The last node of a heap is the leftmost node of maximum depth.
False
T or F: 234 tree's time complexity is O(log n) regardless of if the data is ordered or unordered
True
T or F: A graph is a pair (V, E), where V is a set of nodes called vertices and E is a collection of pairs of vertices, called edges Vertices and edges are positions and store elements
True
T or F: Following are Adjacency List Structure: Edge list structure *incidence sequence for each vertex sequence of references to edge objects of incident edges Augmented edge objects *references to associated positions in incidence sequences of end vertices
True
T or F: If array and linked list is too slow then we should consider binary search tree
True
T or F: In a directed graph the order of the vertices in the pairs in the edge set matters.
True
T or F: In an undirected graph, the order of the vertices in the pairs in the edge set doesn't matter
True
T or F: Insertion for AVL tree is by expanding an external node
True
T or F: Is the following a valid algorithm for insertion sort? public static void insertionSort(Comparable[] A) { int k, j; Comparable tmp; int N = A.length; for(k = 1; k < N, k++) { tmp = A[k]; j = k -1; while((j >= 0) && (A[j].compareTo(tmp) > 0)) { A[j + 1] = A[j]; //move one value over one place to the right j--; } A[j + 1] = tmp; //insert 4th value in correct place relative to previous values } }
True
T or F: Removal of a node in AVL tree means the node removed will become an empty external node.
True
T or F: Specialized data structures are: stacks, queues, priority queues, graphs
True
T or F: The height f an AVL tree storing n keys is O(log n).
True
T or F: The idea behind selection sort is: 1. Find the smallest value in A; put it in A[0]. 2. Find the second smallest value in A; put it in A[1].
True
T or F: Using the following Heap algorithm we can remove the Max value: 1. Replace the value in the root with the value at the end of the array (which corresponds to the heap's rightmost leaf at depth d). Remove that leaf from the tree. 2. Now work your way down the tree, swapping values to restore the order property: each time, if the value in the current node is less than one of its children, then swap its value with the larger child (that ensures that the new root value is larger than both of its children).
True