Algorithms Final Exam (Cumulative)
List at least four characteristics of simple sorting algorithms:
-they are easy to understand -they are relatively slow - have excellent performance in specific instances -are all calculated with O(n^2)
What is basic process for mergesort?
???
What is a binary tree?
?????
Suppose you push 10, 20, 30, and 40 onto the stack. Then you pop 3 items. Which is left on the stack? A. 10 B. 20 C. 30 D. 40
A. 10
In open addressing, when a data item can't be placed ta the index calculated by the hash function, another location in the array is sought. How many methods of open addressing have we studied in this chapter? A. 3 B. 4 C. 5 D. 6
A. 3
The bubble sort algorithm alternates between A. comparing and swapping B. moving and copying C. moving and comparing D. copying and comparing.
A. Comparing and swapping
The partition algorithm runs in O(_________) time. A. N B. N^2 C. N*logN D. logN
A. N
Hash tables, a type of data structure with array associated with a hash function, are used for search at ___ in Big O notations A. O(1) B. O(lohN) C. O(N) D. O(N*logN)
A. O(1)
Inserting a new element to an unsorted array runs in ________ time A. O(1) B. O(N) C. O(N^2) D. O(logv2N)
A. O(1)
Inserting a new link to an unsorted linked list runs in _____________ time A. O(1) B. O(N) C. O(N^2) D. O(logv2N)
A. O(1)
Bubble sorting performance efficiency is in big O notation: A. O(n^2) B. O(N) C. O(N/2)
A. O(N^2)
Binary search takes ____ time, which is quite efficient: A. O(logN) B. O(N) C. O(N*logN) D. O(N^2)
A. O(logN)
Insertion and deletion in a tree require what big O time? A. O(logN) B. O(N) C. O(N*logN)
A. O(logN)
Partitioning is the underlying mechanism of one advanced sorting algorithm: A. quicksort B. shellsort C. merge sort D. selection sort
A. Quicksort
The ratio of the number of items in a table to __ is called the load factor. A. The table's size B. Probe length C. Steps D. A prime number
A. The table's size
In a database, a field is A. A specific data term B. A specific object C. A part of record D. A part of algorithm
A. a specific data term
What do all three simple sorting algorithm use as data store structure? A. array B. stack C. queue
A. array
A double-ended linked list: A. can be accessed from either end B. is a different name for a doubly linked list. C. has pointers running both forward and backward between links D. has its first link connected to its last link.
A. can be accessed from either end
During the process of building a hash table, a cell is already occupied by a data item with some other key. This is a ___ A. Collision B. Conflict C. Pileup D. Crash
A. collision
In a singly linked list, a next value (reference) of null signals the _________ of the list A. end B. beginning C. first D. head
A. end
To travese a linked list, you start at ______ and then go from link to link, using each link's next field to find the next link. A. first/head B. first link C. any link D. last link
A. first/head
Finding a node in a binary search tree involves going from node to node, asking: A. how big the node's key is in relation to the search key B. how big the nodes key is compared to its right or left children. C. What leaf node we want to reach. D. what level we are on
A. how big the node's key is in relation to the search key
A class A. Is a blueprint for many objects B. represents a specific real-world object C. will hold specific values in its fields D. specifies the type of a method
A. is a blueprint for many objects
Each node in a heap satisfies the heap condition, which states that every node's key is ___ the keys of its children. A. Larger than or equal to B. Larger than C. Smaller than D. Equal to
A. larger than or equal to
A linked list consists of one linkedList object and a number of Link objects. Which object only contains a reference? A. linkedList B. first link C. middle link D. last link
A. linkedList
Shellsort is not quite as efficient as quicksort and other O(N*logN) sorts (advanced sorting algorithms), for very large files. However, it is good for _________ arrays, perhaps up to a few thousand items. A. medium-sized B. small C. ordered
A. medium-sized
A priority queue might be used to hold: A. passengers to be picked up by a taxi from different parts of the city B. keystrokes made at a computer keyboard C. squares on a chessboard in a game program D. planets in a solar system simulation
A. passengers to be picked up by a taxi from different parts of the city
To add/insert a new item if the stack is not full is an operation called: A. push B. pop C. peek
A. push
Partitioning is: A. putting all elements larger than a certain value on one end of the array B. dividing an array in half C. partially sorting parts of an array. D. sorting each half of an array separately
A. putting all elements larger than a certain value on one end of the array
___ is an attempt to keep clusters from forming. The idea is to probe more widely separated cells, instead of those adjacent to the primary hash site. A. Quadratic probing B. Double hashing C. Linear probing
A. quadratic probling
Because heaps are weakly ordered, some operations are difficult or impossible. Besides its failure to support traversal, a heap also does not allow convenient searching for a specified key. A. True B. False
A. true
In computer science, a perfect hash function for a set S is a hash function that maps distinct elements in S to a set of integers, with no collisions. A. True B. False
A. true
In separate chaining it's normal to put N or more items into an N cell array; thus, the load factor can be 1 or greater. A. True B. False
A. true
In a complete binary tree with 20 nodes, and the root considered to be at level 0, how many nodes are there at level 4? A. 4 B. 5 C. 6 D. 7
B. 5
There's a simple relationship between the number of nodes in the heap tree and the ____ that codes the path to the last node A. Hex number B. Binary number C. Decimal number
B. Binary number
which type of Linked list would be best for implementing a queue? A. double-ended list B. doubly-ended linked list C. singly linked list
B. Doubly-ended Linked list
A binary tree is a search tree if: A. every non-leaf node has children whose key values are less than or equal to the parent. B. Every left child has a key less than the parent and every right child has a key greater than or equal to the parent. C. In the path from the root to every leaf node, the key of each node is greater than or equal to the key of its parent. D. A node must have at least two children.
B. Every left child has a key less than the parent and every right child has a key greater than or equal to the parent.
In object-oriented programming, an object A. Is a class B. May contain data & methods C. Is a program D. May contain classes
B. May contain data & methods
Deleting a link from a linked list runs in _________ time A. O(1) B. O(N) C. O(N^2) D. O(logv2N)
B. O(N)
Finding an item in both an array and a linked list runs in _________ time A. O(1) B. O(N) C. O(N^2) D. O(logv2N)
B. O(N)
The heap operations all operate in ___ time A. O(1) B. O(logN) C. O(N) D. (N*logN)
B. O(logN)
To delete a node with two children in a binary tree, you need to find its successor on the __________ A. left subtree B. right subtree C. both D. either side of subtree
B. Right subtree
In the selection sort: A. the largest keys accumulate on the left (low indices) B. a minimum key is repeatedly discovered C. a number of items must be shifted to insert each item in its correctly sorted position. D. the sorted items accumulate on the right
B. a minimum key is repeatedly discovered
Which of the following is not true? A reference to a class object: A. can be used to access public methods in the object. B. has a size dependent on its class C. has the data type of the class. D. does not hold the object itself
B. has a size dependent on its class
The disadvantage of mergesort is that... A. it is not recursive B. it uses more memory C. although faster than the insertion sort, it is much slower than quicksort D. it is complicated to implement compared to other advanced sorting algorithms
B. it uses more memory
In the insertion sort, after an item is inserted in the partially sorted group, it will: A. never be moved again B. never be shifted to the left. C. often be moved out of this group. D. find that its group is steadily shrinking.
B. never be shifted to the left
To remove the item from the stack if it is not empty is an operation called: A. push B. pop C. peek
B. pop
Assume an array is numbered with index 0 on the left. A queue representing a line of movie-goers, with the first to arrive numbered 1, has the ticket window on the right. Then: A. there is no numerical correspondence between the index numbers and the movie-goer numbers. B. the array index numbers and the movie-goer numbers increase in opposite left-right directions C. the array index numbers correspond numerically to the locations in the line of movie-goers D. the movie-goers and the items in the array move in the same direction
B. the array index numbers and the movie-goer numbers increase in opposite left-right directions
One difference between a priority queue and an ordered array is that: A. the lowest priority item cannot be extracted easily from the array as it can from the priority queue B. the array must be ordered while the priority queue need not be. C. the highest priority item can be extracted easily from the priority queue but not from the array D. all of the above
B. the array must be ordered while the priority queue need not be.
Assume we create a singly linked list and then we hae added three nodes/links consecutively. Which node/link contains the memory address of the middle node/link? A. the object with only reference B. the newly-added link/node C. the link/node at the tail D. the second link/node
B. the newly-added link/node
Which application can use stack data structure? A. printing B. undo/redo C. keystroke D. deleting a file
B. undo/redo
In recursion, a condition which ends recursive call and returns a value is called _____ case
Base
A subtree of a binary tree always has: A. a root that is a child of the main tree's root B. a root unconnected to the main tree's root C. fewer nodes than the main tree D. a sibling with the same number of nodes
C. Fewer nodes than the main tree
Deleting an element from an array (sorted or unsorted) runs in _______ time A. O(1) B. O(N) C. O(N^2) D. O(logv2N)
C. O(N^2)
No one so far has been able to analyze the shellsort's efficiency theoretically, except in special cases. Based on experiments, there are various estimates, which range from ___________ down to ___________ A. O(n), O(N*N) B. O(N^2/3), O(N^7/8) C. O(N^3/2), O(N^7/6)
C. O(N^3/2), O(N^7/6)
The best table sizes for a hash table are ___ A. Even numbers B. Odd numbers C. Prime numbers D. A huge integer
C. Prime numbers
Which of the following is true? A. The pop operation on a stack is considerably simpler than the remove operation on a queue. B. The contents of a queue can wrap around, while those of a stack cannot. C. The top of a stack corresponds to the front of a queue. D. In both the stack and the queue, items removed in sequence are taken from increasingly high index cells in the array.
C. The top of a stack corresponds to the front of a queue.
The shellsort works by: A. partitioning the array B. swapping adjacent elements C. dealing with widely separated elements D. starting with the normal insertion sort
C. dealing with widely separated elements
An unbalanced tree is one: A. in which most of the keys have values greater than the average. B. whose behavior is predictable C. in which the root or some other node has many more left children than right children, or vice versa. D. That is shaped like an umbrella
C. in which the root or some other node has many more left children than right children, or vice versa.
If the data is small and almost sorted, which of the following sorting algorithms is the best? A. bubble sort B. selection sort C. insertion sort
C. insertion sort
A queue might be used to hold: A. the items to be sorted in an insertion sort. B. reports of a variety of imminent attacks on the star ship Enterprise C. keystrokes made by a computer user writing a letter. D. symbols in an algebraic expression being evaluated.
C. keystrokes made by a computer user writing a letter.
When you create a reference to a link in a linked list, it A. must refer to the first link B. must refer to the link pointed to by current C. must refer to the link pointed to by next
C. must refer to the link pointed by next
To read the vale from the top of the stack without removing it is an operation called: A. push B. pop C. peek
C. peek
If we do not know in advance how much data, what scheme is better choice to build a hash table? A. Double hashing B. Linear probing C. Separate chaining D. Quadratic probing
C. separate chaining
Which statement is WRONG about stack and queue? A. they are actually logical data structures B. they can be built only on array C. stack is LIFO and queue is FIFO D. priority is no more FIFO
C. stack is lifo and queue is fifo
Which operation is the most time consuming? A. copying B. comparing C. swapping
C. swapping
Assuming larger keys on the right, the partition is: A. the element between the left and right subarrays B. the key value of the element between the left and right subarrays C. the left element in the right subarray D. the key value of the left element in the right subarray
C. the left element in the right subarray
The term priority in a priority queue means that: A. the highest priority items are inserted first. B. the programmer must prioritize access to the underlying array. C. underlying array is sorted by the priority of the items D. the lowest priority items are deleted first.
C. the underlying array is sorted by the priority of the items
Suppose you insert 15, 25, 35, and 45 into queue. Then you remove three items. Which is left? A. 15 B. 25 C. 35 D. 45
D. 45
Shellsort is based on the _________ sort. A. partition B. Quick C. selection D. insertion
D. Insertion
Heapsort runs in __ time. A. O(1) B. O(N) C. O(N*N) D. O(N*logN)
D. O(N*logN)
In Java, an object is A. is created by invoking class constructor B. created with keyword new C. specific instance of a class D. all of the above
D. all of the above
Array is a very basic data structure. Which is NOT true about array? A. once declared its size, you cannot change its size B. array is reference variable, which means its value is memory address C. array is not allowed a gap between elements D. array can be expanded and shrunk as needed.
D. array can be expanded and shrunk as needed.
In the insertion sort, "partially sorted" means that: A. some items are already sorted, but they may need to be moved. B. most items are in their final sorted positions, but a few still need to be sorted. C. only some of the items are sorted D. group items are sorted among themselves, but items outside the group may need to be inserted in it
D. group items are sorted among themselves, but items outside the group may need to be inserted in it
In data structure: heap is a kind of ___ A. Queue B. Linked list C. Stack D. Tree
D. tree
Finding and deleting a smallest/largest item in a sorted linked list takes _______ time (big o notation)
O(1)
What is mergesort efficiency in big O notation?
O(n*logn)
Why do we use binary tree?
Trees combine the quick searching of ordered arrays with the quick insertion/deletion of linked lists.
Push is an operation to _____ an item on the top of the stack
add
Both stacks and queues are _______ data structure. They are implemented by using array, linked list or other data structure. There are no such things called stacks or queues existing in computer memories.
conceptual
What principle/approach does mergesort use?
divide and conquer technique
A special case, which causes errors if not handled correctly, must be considered for insertion and deletion routines when a list is ______
empty
Access to the links in a linked list is usually through the _____ link
first
priority queue is defined by the item with the lowest/highest key is always at the ______
front
Recursion is a programming technique in which a method (function) calls __________
itself
The recursive binary search and __________ are examples of the divide-and-conquer approach to solving a problem.
mergesort
Stacks and queues share one feature: access is restricted, which means only ____ item is read or removed at a given time.
one
A _______ is a data storage structure that uses the first in first out protocol.
queue
pop is an operation to _______ an item at the top of the stack
remove
Linear search is also called _________ search
sequential
Array must be __________ for binary search
sorted
A _______ is a data storage structure that uses the last in first out protocol.
stack
A divide-and-conquer approach usually involves a method that contains two recursive calls to itself, one for each half of the problem.
true
A recursive method calls itself repeatedly, with different argument values each time.
true
Both triangle numbers and factorials can be calculated using either a recursive method or a simple loop.
true
In mergesort, 1-element subarrays of a larger array are merged into 2-element subarrays, 2 element subarrays are merged into 4 element subarrays, and so on until the entire array is sorted.
true
Merging two sorted arrays means to create a third array that contains all the elements from both arrays in sorted order.
true
The factorial of a number is the product of itself and all numbers smaller than itself.
true
To solve the puzzle of the Towers of Hanoi, recursion is used to get a subtree.
true
peek is an operation to _______ an item at the top of the stack
view