COSC 3100 Final Study Guide - Questions
Q: How many nodes would be found in a full binary tree that has four levels? A. 7 B. 8 C. 15 D. 16
15
Q: Which one of the following statements regarding heaps and/or trees is not true? A. In a max heap the value of each node is greater than or equal to the values of its children (if any). B. In a min heap the value of each node is less than or equal to the values of its children (if any). C. The dequeue operation in a max heap removes the largest item from the heap. D. A complete binary tree is also considered a full binary tree.
A complete binary tree is also considered a full binary tree.
Q. Which one of the following statements correctly describes sort stability? A. A sort is stable if it gives the same results each time it is executed against the same data. B. A sort is stable if the data retains its relative input order in the output with other data that has the same key value. C. A sort is stable if it will execute for both numeric and string key fields. D. A sort is stable if it always runs in the same amount of time against the same data.
A sort is stable if the data retains its relative input order in the output with other data that has the same key value.
Q: Which one of the following statements best describes closed hashing in hash tables? A. All collisions are resolved within the hash table. B. A separate structure such as a linked list is used to resolve collisions. C. Many collisions are clustered around a single hash table element. D. The hashing function will prevent any collisions from occurring.
All collisions are resolved within the hash table.
Hashing Algorithm: Division/Modulus
Divides the key by the array size and uses the remainder as the address
Hashing Algorithm: Folding
Divides the key value into parts and the parts are manipulated to determine the address
Q: Which one of the following statements regarding binary trees is not correct? A. All subtrees must also be binary trees. B. All nodes (except the leaves) are capable of having at most two children. C. Each node has one and only one parent. D. A binary tree cannot have cycles.
Each node has one and only one parent.
Q: A priority queue can be implemented using either a sorted array or a heap. Which one of the following statements is correct regarding the time complexities for these data structures? A. Enqueueing and dequeueing a heap are each O(lg n); Enqueueing and dequeueing a sorted array are each O(1). B. Enqueueing and dequeueing a heap are each O(lg n); Enqueueing and dequeueing a sorted array are each O(n). C. Enqueueing and dequeueing a heap are each O(lg n); Enqueueing a sorted array is O(n) and dequeueing a sorted array is O(1). D. Enqueueing a heap is O(n) and dequeueing a heap is O(1); Enqueueing and dequeueing a sorted array are each O(lg n).
Enqueueing and dequeueing a heap are each O(lg n); Enqueueing a sorted array is O(n) and dequeueing a sorted array is O(1).
Q: Which one of the following statements does not correctly describe a binary tree? A. Every node must have one and only one parent. B. The leaves have no children. C. There can be no cycles. D. Every subtree must be a tree itself.
Every node must have one and only one parent.
Q: Which one of the following formulas will correctly determine the minimum height (Hm) of a binary tree given a number of nodes (N)? A. Hm=2^N-1 B. Hm=2^N+1 C. Hm=[log2N]-1 D. Hm=[log2N]+1
Hm=[log2N]+1
Q: Which one of the following statements regarding a binary search on an array is not correct? A. The values in the array must be in sequence. B. It is more efficient than a sequential search. C. If the search value is less than the middle value, then the last value is set to the value at the (middle -1) element. D. If the search value is greater than the middle value, then the middle value is set to the value at the (first + 1) element.
If the search value is greater than the middle value, then the middle value is set to the value at the (first + 1) element.
Q: In an application program using a Priority Queue data structure implemented using a heap, the elements stored in the Priority Queue are objects of a structure named Movie. Which one of the following statements is correct regarding this application/Priority Queue combination? A. In order to determine the largest Movie object, the Movie structure must contain an overloaded operator that determines what it means for one Movie object to be greater than another Movie object. B. In order to determine the largest Movie object, the Priority Queue class template must contain an overloaded operator that determines what it means for one Movie object to be greater than another Movie object. C. In order for the largest Movie object to reside in the first element of the Priority Queue, all elements of the priority queue are sorted in descending order. D. In order for the largest Movie object to reside in the first element of the Priority Queue, a sorted linked listed is used in the Priority Queue in order to maintain that order.
In order to determine the largest Movie object, the Movie structure must contain an overloaded operator that determines what it means for one Movie object to be greater than another Movie object.
Q: In the heapify function of the Priority Queue class template one would find this comparison: if(elements[leftChild] > elements[rightChild]) What impact occurs due to the greater than operator (>)? A. In the Priority Queue class template one must code an overloaded greater than operator. B. In the struct coded in the Priority Queue class template declaring the data type that will be placed into the Priority Queue, an overloaded greater than operator must be coded. C. In the struct coded in the application program declaring the data type that will be placed into the Priority Queue, an overloaded greater than operator must be coded. D. There is no impact
In the struct coded in the application program declaring the data type that will be placed into the Priority Queue, an overloaded greater than operator must be coded.
Q: Why is a function pointer used in the hash table constructor code? A. It is the most efficient place for the code. B. It allows multiple hashing functions to exist for the same hash table. C. It allows the user of the hash table to use his own hashing function for the hash table. D. It forces the hash table to use the chaining method to resolve collisions.
It allows the user of the hash table to use his own hashing function for the hash table.
Q: Which one of the following is not a property of an AVL tree? A. It is a binary search tree. B. It must be a full or complete tree C. All subtrees must be AVL trees D. Each node in the tree must be AVL balanced.
It must be a full or complete tree
Q: Which one of the following list of time complexities is in the correct order from most efficient to least efficient? A. O(1), O(lgn), O(n), O(nlgn), O(n^2) B. O(n^2), O(nlgn), O(n), O(lgn), O(1) C. O(1), O(lgn), O(nlgn), O(n), O(n^2) D. O(n^2), O(n), O(nlgn), O(lgn), O(1)
O(1), O(lgn), O(n), O(nlgn), O(n^2)
Q: What would the theta time complexity be for the following algorithm? int sum = 0; for (int i=n; i>1; i/=2) sum += i; A. O(1) B. O(lgn) C. O(n) D. O(n^2)
O(lgn)
Q: What is the time complexity of a bubble sort algorithm? A. O(n) B. O(lgn) C. O(nlgn) D. O(n^2)
O(n^2)
Q: What is the time complexity of a heap sort algorithm? A. O(n) B. O(lgn) C. O(nlgn) D. O(n^2)
O(nlgn)
Q: In a priority queue's overloaded constructor one will find the following code: for ( int i = ( heapsize - 2 ) /2; i >= 0; i-- ) heapify( i ); Which one of the following statements best describes what this code does? A. Starting with the last node, the heapify function is executed for each node in the array in reverse order. B. Starting with the parent of the last node, the heapify function is executed for each parent node in the array in reverse order. C. Starting with the first node, the heapify function is executed for each node in the array in forward order. D. Starting with the parent of the first node, the heapify function is executed for each parent node in the array in forward order.
Starting with the parent of the last node, the heapify function is executed for each parent node in the array in reverse order.
Hashing Algorithm: Subtraction
Subtracts a constant from the key value to determine the address
Q. Which one of the following statements is not true regarding a hash table? A. It is a data structure that allows for very fast access to data. B. In order to locate an item in a hash table, a hashing function must be used to convert a key value into an integer index. C. The data must be in sequence on the key field when loaded into a hash table. D. It is possible for multiple key values to hash to the same index.
The data must be in sequence on the key field when loaded into a hash table.
Q: In a priority queue's class template there are two constructors, the default constructor and an overloaded constructor. Which one of the following statements best describes the difference between the two constructors? A. The default constructor builds a priority queue from an array passed to it and the overloaded constructor builds an empty priority queue. B. The default constructor builds an empty priority queue and the overloaded constructor builds a priority queue from an array passed to it. C. The default constructor builds an empty priority queue and the overloaded constructor builds a priority queue from an existing priority queue. D. The default constructor builds a priority queue from an existing priority queue and the overloaded constructor builds an empty priority queue.
The default constructor builds an empty priority queue and the overloaded constructor builds a priority queue from an array passed to it.
Q: If the height of the left subtree is HL and the height of the right subtree is HR, which one of the following statements is true regarding AVL trees? A. The difference between HL and HR must be zero. B. The difference between HL and HR must be one. C. The difference between HL and HR must be two. D. The difference between HL and HR must be -1, 0, or +1.
The difference between HL and HR must be -1, 0, or +1.
Q: In the heap sort algorithm, once the list is a valid heap, what is done? A. The first element of the list is moved to the sorted side of the list since it is the lowest value in the list. B. The first element of the list is moved to the sorted side of the list since it is the highest value in the list. C. The last element of the list is moved to the sorted side of the list since it is the lowest value in the list. D. The last element of the list is moved to the sorted side of the list since it is the highest value in the list.
The first element of the list is moved to the sorted side of the list since it is the highest value in the list.
Q: Assume an application program processes automobiles for a used car lot. The application stores the automobile information in a hash table that uses the chaining collision resolution method. When the 50 cars on the lot are inserted into the hash table, 50 collisions occur. What is the most likely cause for this? A. The hash table is not allocated large enough. B. The hash function is not calculating different indices for any of the automobiles. C. The collision resolution method is calculating the same index for all automobiles. D. The linked lists containing the data are filling up.
The hash function is not calculating different indices for any of the automobiles.
Q: In the enqueue function of a Priority Queue class template, one would find the following code. int i = heapsize; for ( ; (i != 0) && elements[ (i - 1) /2 ]<= newElement;i = ( i - 1 ) /2 ) elements[ i ] = elements[ ( i - 1 ) /2 ] After this code has executed, what does the value of i represent? A. The index of the largest element of the Priority Queue B. The index in the Priority Queue where the item being enqueued will be placed. C. The value of the largest element in the Priority Queue D. The current value of the element where the new element being enqueued will be placed.
The index in the Priority Queue where the item being enqueued will be placed.
Q: Which one of the following statements is not true regarding the function used to insert a node into a binary search tree? A. The left or right branch is followed down the tree, depending on the value of the new node, until a null subtree is found. B. All inserts take place at a leaf or leaflike node. C. Data is inserted onto left or right branch depending on insert value and node value. D. The insert function must be a recursive function since a binary search tree is a recursive data structure.
The insert function must be a recursive function since a binary search tree is a recursive data structure.
Hashing Algorithm: Midsquare
The key value is multiplied by itself and the address is selected from the middle of the resulting number
Hashing Algorithm: Direct
The key value is the address
Q: Which one of the following is not a characteristic of a graph? A. A directed graph is one in which the line segments depict a direction of flow from one node to another. B. An undirected graph is one in which the line segments depict no direction of flow from one node to another. C. The only way to depict a graph in a computer program is to use a two-dimensional array. D. A graph consists of a group of nodes and the line segments connecting them.
The only way to depict a graph in a computer program is to use a two-dimensional array.
Q: Which one of the following statements concerning the pivot in a quick sort is not correct? A. All of the values of the array elements on the left of the pivot must be less than the value of the pivot. B. All of the values of the array elements on the right of the pivot must be greater than or equal to the value of the pivot. C. The same number of array elements must be on the right of the pivot as are on the left of the pivot. D. The pivot's location may be determined by (first+last)/2 where first is the index of the first element in the list/sublist and last is the index of the last element in the list/sublist.
The same number of array elements must be on the right of the pivot as are on the left of the pivot.
Q: Which one of the following statements is not true regarding the sorting process for an array using the bubble, insertion, and selection sort algorithms? A. The array in divided into two parts, the sorted side and unsorted side. B. There is an invisible wall separating the sorted and unsorted sides. C. As the processing continues, the sorted side gets larger and the unsorted side gets smaller. D. The sort is complete once the sorted side is larger than the unsorted side.
The sort is complete once the sorted side is larger than the unsorted side.
Q: Which one of the following conditions correctly identifies when a collision occurs during an insertion into a hash table. The code references pertain to the code we developed/used in class. A. The index calculated in the HashTable's insert function by the hash function is -1. B. The start index in the linked List's insert function is equal to the nullptr (NULL). C. The start index in the linked List's insert function is not equal to the nullptr (NULL). D. A false is returned from the linked List's find function.
The start index in the linked List's insert function is not equal to the nullptr (NULL).
Hashing Algorithm: Pseudorandom
They key value is used in a formula that transposes it into an address
Q: When using recursive functions to implement the various operations in a binary search tree class template (BST), it is necessary to include two functions, a private recursive function and a public non-recursive user interface function. Which one of the following statements best describes the reason for doing this? A. Recursive functions are less efficient than iterative functions so this improves the efficiency of the BST. B. This prevents an application program that uses the BST from having to deal with nodes and node pointers. C. Recursive functions cannot be called from an application program that uses a BST. D. If one function is good, then two functions must be better.
This prevents an application program that uses the BST from having to deal with nodes and node pointers.
Q: Which one of the following statements is not true regarding time complexities of algorithms? A. Time complexities allow us to compare the relative efficiency of different algorithms. B. The intersection of the execution time graphs of two algorithms with different time complexities is known as the cross-over point. C. Two different algorithms with the same time complexity will always execute in exactly the same amount of time. D. A time complexity is actually an infinite set of the functions that represent the time it takes for algorithms to execute.
Two different algorithms with the same time complexity will always execute in exactly the same amount of time.
Q. An AVL tree is considered right of left if A. a subtree of the tree that is left high, is right high. B. a subtree of the tree that is right high, is left high. C. a subtree of the tree that is left high, is also left high. D. a subtree of the tree that is right high, is also right high.
a subtree of the tree that is left high, is right high.
Time Complexity Code: O(n^2)
for (i=0; i<n; i++) { for (j=0; j<n; j++) sum++; }
Time Complexity Code: O(nlg n)
for (i=0; i<n; i++) { for (j=n; j>0; j/=2;) sum++; }
Time Complexity Code: O(n)
for (i=0; i<n; i++;) sum++;
Time Complexity Code: O(lg n)
for (i=n; i>0; i/=2;) sum++;
Q: Assume the following insert is done in an application program where myLot is a HashList object and car is an instance of the struct Auto. myLot.insert(car); The insert function in HashList contains the following code where newObject is the passed parameter, in this case car: int location = hashfunc( newObject ); table[location].insert( newObject ); Where is the insert function located that is referenced in the last line of code? A. in the application program B. in the HashTable class C. in the List class D. in the either the HashTable class or the List class
in the List class
Q: If a node (Node1) to be deleted in a binary search tree contains two subtrees, which one of the following statements best describes what one must do to delete it? A. locate the largest node (Node2) in the right subtree of Node1 and move its data to Node1. Then delete Node2. B. locate the largest node (Node2) in the left subtree of Node1 and move its data to Node1. Then delete Node2. C. locate the largest node (Node2) in the left subtree of Node1 and attach it as the left subtree of the smallest node in the right subtree of Node1. Then delete Node1. D. locate the smallest node (Node2) in the right subtree of Node1 and attach it as the right subtree of the largest node in the left subtree of Node1. Then delete Node1.
locate the largest node (Node2) in the left subtree of Node1 and move its data to Node1. Then delete Node2.
Q: A coding scheme is considered immediately decodable if A. the sequence of bits representing a character are all the same length. B. no sequence of bits that represents a character is a suffix of a longer sequence of bits representing another character. C. no sequence of bits that represents a character is a prefix of a longer sequence of bits representing another character. D. there are no repeating bit patterns in the sequence of bits that represents a character.
no sequence of bits that represents a character is a prefix of a longer sequence of bits representing another character.
Q: When balancing an AVL tree that is considered right of left, which one of the pairs of rotations is used? A. rotate left, then rotate left again B. rotate left, then rotate right. C. rotate right, then rotate right again. D. rotate right, then rotate left.
rotate left, then rotate right.
Q: A sorting method in which all data are checked for the smallest item which is then placed in the sorted portion of the array of data is called a(n) A. selection sort B. insertion sort C. bubble sort D. regressive sort
selection sort
Time Complexity Code: O(1)
sum=1;
Q: Which one of the following functions in the PriorityQueue class contains an execution of the heapify function at the root node only? A. the default constructor B. the overloaded constructor C. the enqueue function D. the dequeue function
the dequeue function
Q: In a graph, adjacent refers to A. two vertices that have an edge that directly connects them. B. a sequence of edges between vertices that allows you to move from a vertex, back to itself. C. a property in which there is a path that exists between any vertex to all of the remaining vertices without regard for direction. D. a vertex that has an edge to itself.
two vertices that have an edge that directly connects them.
Q: Which one of the following statements is a correctly written prototype for a function pointer called fp? A. (void *fp) (string, int); B. void (*fp) (string, int); C. void* fp (string, int); D. *void fp (int, int);
void (*fp) (string, int);