Exam 2
What is the smallest integer k such that nlogn is in O(n^k)?
2
Consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree. If R has a left child, where will the left child's position be in the array?
2∗i+1
Given a hash table size of 100 and the simple mod hash function, what slot in the table will 638 hash to?
38
Suppose that a particular algorithm has time complexity T(n)=n^2 and that executing an implementation of it on a particular machine takes t seconds for n inputs. Now suppose that we are presented with a machine that is 64 times as fast. How many inputs could we process on the new machine in t seconds?
8n
A dictionary is:
An ADT
Which of these is the best definition for a stable sorting algorithm?
An algorithm that does not change the relative ordering of records with identical keys
Which of these is a true statement about the worst-case time for operations on heaps?
Both insertion and removal are better than linear
A binary tree is another name for a BST.
False
If you are given the order of the nodes as visited by a preorder traversal and the order of the nodes as visited by a postorder traversal, do you have enough information to reconstruct the original tree? Assume that the nodes all have unique values.
False
The lower bound for the cost of sequential search is Ω(1) since this is the running time of the algorithm in the best case.
False
The upper bound and lower bounds of the sequential search algorithm is in O(n) and Ω(n)respectively.
False
There are some algorithms that do not terminate for certain inputs.
False
Which feature of heaps allows them to be efficienty implemented using an array?
Heaps are complete binary trees
Assume that an array consists of at least 20 elements. The worst case time (in the big-oh sense) occurs in linear search algorithm when
Item is: in the middle not in the array the last element
The order of the input records has what impact on the number of comparisons required by Bubble Sort (as presented in class)?
None
When implementing Insertion Sort, a binary search could be used to locate the position within the first i−1 records of the array into which record i should be inserted. Using binary search will:
Not speed up the asymptotic running time because shifting the records to make room for the insert will require Θ(i) time
In a max-heap containing n elements, what is the position of the element with the least value?
Possibly in any leaf node
A hash function must: (M = size of a hash table)
Return a value between 0 and M−1
When is Insertion Sort a good choice for sorting an array?
The array has only a few records out of sorted order
The lower bound for a problem is defined to be:
The best possible cost for any algorithm that solves the problem
BST search, insert, and delete operations typically run in time O(d). What is d?
The depth of the relevant node in the tree
Visiting each element in a tree is known as:
Traversing
A list can be used to implement a dictionary.
True
For all the algorithms for which we properly understand the running time analysis, the upper bound and lower bound will always be the same.
True
If you are given the order of the nodes as visited by a preorder traversal and the order of the nodes as visited by an inorder traversal, do you have enough information to reconstruct the original tree? Assume that the nodes all have unique values.
True
One good general-purpose solution to the problem of getting a key from a record is to store Key/Value pairs in the search structure
True
The Sequential Search algorithm is in O(n^2).
True
When you print out the nodes of binary tree, the leaf nodes appear in the same relative order for the preorder, inorder, and postorder traversals.
True
the best definition for collision in a hash table?
Two records with different keys have the same hash value
In which case might the number of comparisons NOT be a good representation of the cost for a sorting algorithm?
When we are comparing strings of widely varying length
In which cases are the time complexities the same for Selection Sort?
Worst, Average and Best
What is a disadvantage of linear probing?
You tend to get primary clustering
You must merge 2 sorted lists of size m and n, respectively. The number of comparisons needed in the worst case by the merge algorithm will be:
m+n−1
In the worst case, the total number of comparisons for Mergesort is closest to:
n log n
How many different ways can n distinct values be arranged?
n!
Determine Θ for the following code fragment in the average case. Assume that all variables are of type "int". a = b + c; d = a + e;
Θ(1)
What is the worst-case cost for Quicksort's partition step?
Θ(n)
The n nodes in a binary tree can be visited in:
Θ(n) time
Consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree. If R has a parent, where will the parent's position be in the array?
⌊(i−1)/2⌋