Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
89 Cards in this Set
- Front
- Back
Sorting based on binary comparisons of the
objects to be sorted admits this as a lower bound to the worst-case complexity of the solution. a. O(nlg n) b. Ω(n lg n) c. Ω(n) d. All of these are appropriate answers e. None of these is an appropriate answer |
b. Ω(n lg n)
|
|
Sorting algorithms that sort objects “in place”
require this much storage allocation. a. O(nlg n) b. O(n²) c. O(n) d. O(1) e. None of these is an appropriate answer |
d. O(1)
|
|
All of these sorting algorithms sort objects “in
place” except: a. INSERTION-SORT b. MERGE-SORT c. HEAP-SORT d. BUBBLE-SORT e. ATROCIOUS-SORT |
b. MERGE-SORT
|
|
All of these sorting algorithms sort objects in
optimal worst-case time except: a. MERGE-SORT b. HEAP-SORT c. INSERTION-SORT d. All of these are optimal algorithms e. None of these is an optimal algorithm |
c. INSERTION-SORT
|
|
In a max-heap, the largest element is stored
at _____. a. a leaf b. an internal node c. the root d. the “right-most” node e. the “left-most” node |
c. the root
|
|
In a min-heap, the largest element is stored
at _____. a. a leaf b. an internal node c. the root d. the “right-most” node e. the “left-most” node |
a. a leaf
|
|
Building a max-heap from an unordered
array can be done in ____ time. a. O(n lg n) b. O(n²) c. O(n) d. O(1) e. None of these is an appropriate answer |
c. O(n)
|
|
Building a min-heap from an unordered
array can be done in ____ time. a. O(n lg n) b. O(n²) c. O(n) d. O(1) e. None of these is an appropriate answer |
c. O(n)
|
|
________ is based on a technique similar to
the way many people sort a hand of playing cards. a. MERGE-SORT b. INSERTION-SORT c. ATROCIOUS-SORT d. BUBBLE-SORT e. HEAP-SORT |
b. INSERTION-SORT
|
|
Heaps are useful in their own right — they
can be used to implement this data structure: a. dictionary b. priority queue c. ordered list d. stack e. set |
b. priority queue
|
|
ATROCIOUS-SORT from the homework has this
as its best-case running time: a. Θ(n lg n) b. Θ(n²) c. Θ(n) d. Θ(1) e. All of these are appropriate answers |
c. Θ(n)
|
|
Linear time sorting is possible because ____.
a. objects can be sorted without binary comparisons b. the linear time lower bound to sorting is not valid c. one can always “tweak” the system clock d. All of these are valid answers e. None of these is a valid answer |
a. objects can be sorted without binary
comparisons |
|
A ______ is a full binary tree that represents
the comparisons between elements that are performed by a particular sorting algorithm. a. heap b. binary search tree c. decision tree d. 2-3 tree e. B-tree |
c. decision tree
|
|
COUNTING-SORT determines, for each input
element x, the number of elements less than x. This information is then used to place x directly into its position in the output. Therefore, COUNTING-SORT is an “in place” sorting algorithm. Assess the validity of this conclusion. a. It is a valid conclusion. b. It is not a valid conclusion. |
b. It is not a valid conclusion.
|
|
COUNTING-SORT depends on this key
assumption about the numbers to be sorted: a. They are in reverse order b. They are in correct order c. They are all distinct d. They are all integers in {0, 1, … , k} e. All of these are appropriate answers |
d. They are all integers in {0, 1, … , k}
|
|
RADIX-SORT is the algorithm that was once
used by _______ machines. a. typewriting b. voting c. flying d. perpetual-motion e. card-sorting |
e. card-sorting
|
|
RADIX-SORT requires that the intermediate
sorting algorithm (the one that sorts on the basis of the digits) be _______, which means that “numbers with the same value appear in the output array in the same order as they do in the input array.” a. efficient b. stable c. optimal d. linear e. transparent |
b. stable
|
|
BUCKET-SORT assumes that the input is
generated by a random process that distributes element uniformly over this range: a. {0,1, … , k}, i.e., natural numbers up to k b. {1,2, … , k}, i.e., positive integers up to k c. [0,1], i.e., the closed unit segment d. [0,1), i.e., the closed unit segment except 1 e. (0,1], i.e., the closed unit segment except 0 |
d. [0,1), i.e., the closed unit segment except 1
|
|
BUCKET-SORT has an expected time
complexity of Q(n). In theory, it can have a worst-case time complexity of _______, although this is highly improbable. a. O(n²) b. O(2ⁿ) c. O(n!) d. All of these are appropriate answers e. None of these is an appropriate answer |
a. O(n²)
|
|
A hash table is effective for implementing a
dictionary, a data structure that supports this/these functionality/functionalities: a. INSERT b. SEARCH c. DELETE d. All of these answers are appropriate e. None of these answers is appropriate |
d. All of these answers are appropriate
|
|
In an ordinary array, we store the element
whose key is k in position k of the array. By contrast, in a hash table, we use a(n) ______ to generate from the key k a value h(k) to index into the hash table. a. random number generator b. Turing machine c. automaton d. oracle e. hash function |
e. hash function
|
|
The expected time to search for an element
in a hash table is O(1) under reasonable assumptions. However, the worst-case search time is _________. a. Θ(n) b. Θ(n²) c. Θ(2ⁿ) d. Θ(lg n) e. Θ(n lg n) |
a. Θ(n)
|
|
The analysis of hash table operations is
performed in terms of the ratio of n, the number of elements in the table, and m, the number of slots in the table. This ratio is called the _______. a. golden mean b. load factor c. key factor d. All of these are appropriate answers e. None of these is an appropriate answer |
b. load factor
|
|
Hash functions assume that the keys are
natural numbers. This assumption is not too severe because: a. all keys are numerical anyway (no reinterpretation necessary) b. all keys are stored in binary anyway (readily interpreted as binary numbers) c. all keys are physical entities that have numeric dimensions (readily convertible to natural numbers) d. All of these are appropriate answers e. None of these is an appropriate answer |
b. all keys are stored in binary anyway
(readily interpreted as binary numbers) |
|
Hash functions that use the division method,
e.g., h(k) = k mod m, are fast but have the disadvantage of having to avoid certain values of m. Assess the validity of this statement: a. It is a valid statement b. It is not a valid statement |
a. It is a valid statement
|
|
Hash functions that use the multiplication
method, e.g., h(k) = m (k A mod 1), may be slower but have the advantage of not having to avoid certain values of m. Assess the validity of this statement. a. This is a true statement. b. This is a false statement. |
a. This is a true statement.
|
|
In open addressing, the action of examining
a slot in the hash table is known as a(n) _____. a. collision b. probe c. successful landing d. examination e. rehash |
b. probe
|
|
The technique known as linear probing
suffers from the increasing probability of primary clustering. This is when long runs of _____ hash table slots build up. a. empty b. occupied c. vacated d. oversized e. garbage-collected |
b. occupied
|
|
The analysis of open-address hashing
resulted in the expected number of probes in an unsuccessful search to be at most ______, where the load factor a is assumed to be less than 1. a. α + 1 b. α – 1 c. α² d. 1/(1 – α) e. 2α |
a. α + 1
|
|
Hash tables are an excellent manifestation
of this seeming “law” in algorithm design that described opposite tendencies insofar as two important resources are concerned. a. Bentley's Rule: “The first 90% of the code takes 90% of the time. The remaining 10% takes the other 90% of the time.” b. Wirth's Law: “Software gets slower faster than hardware gets faster.” c. Knuth's Optimization Principle: “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” d. Pareto Principle: “For many events, roughly 80% of the effects come from 20% of the causes.” e. Time-Space Tradeoff: “What you gain in time, you lose in space tradeoff, and vice-versa.” |
e. Time-Space Tradeoff: “What you gain in
time, you lose in space tradeoff, and vice-versa.” |
|
What is an abstract data type that stores elements, each of which is assigned a specific order of importance
|
priority queue
|
|
Which data structure supports priority queue in Θ (lg n) time and supports insert and delete max?
|
heap
|
|
In a heap data structure, how do you determine the height of a node?
|
the number of nodes along the longest simple path from that node to a leaf
|
|
How do you determine the height of a heap?
|
it is the height of the root (the number of nodes along the simplest path from the root to a leaf)
|
|
In a heap, given the node is at A[i], where is the left child stored in the array?
|
A[2i]
|
|
In a heap, given the node is at A[i], where is the right child stored in the array?
|
A2[i+1]
|
|
In a heap, given the node A[i], where is the parent of the parent stored in the array?
|
A[i/2]
|
|
In a heap, where is the root stored in the array?
|
A[1]
|
|
What is the time complexity for heap sort?
|
Θ (n lg n)
|
|
What is the immediate lower bounds of a sort based on?
|
the need to examine all items Ω (n)
|
|
What is a way to model sorting algorithms based on binary comparisons?
|
decision tree
|
|
How many leaves are in a decision tree?
|
as many different possible outcomes based on the number of elements to be sorted, n!
|
|
In a decision tree, how can you determine the worst-case complexity of the algorithm?
|
the longest path from root to some leaf
|
|
In a decision tree, how can you determine the best-case complexity of the algorithm?
|
the shortest path from root to some leaf
|
|
Any binary tree of height, h, has a maximum number of how many leaves?
|
2^h
|
|
Any decision tree for sorting n elements has what height?
|
Ω (n lg n)
|
|
All binary comparisons have a lower bounds of __________. Give 2 examples of binary comparison sort
|
Ω (n lg n). heap-sort, merge-sort
|
|
Which sorting algorithms can beat binary comparisons?
|
counting sort, radix sort, bucket sort
|
|
Why are counting sort, radix sort, and bucket sort faster than binary comparisons?
|
because they sort linearly -- O(n)
|
|
What is counting sort dependent on?
|
values to be sorted are integers {0, 1, 2, ..., k}
|
|
What is the maximum value of k when using counting sort?
|
2^32
|
|
What was the original purpose of radix sort?
|
to sort cards that were punched for the 1890 census
|
|
What is the process of radix sort?
|
sort each digit, beginning with least significant digit (ones place), then sort to the left
|
|
What is the basic time complexity of radix sort?
|
O(n+k)
|
|
Given the maximum number of digits, d, what is the time complexity of radix sort?
|
O(dn + dk), where n is the number of elements and k is the range of digits. This becomes O(n) because d is constant and k = O(n)
|
|
Why is radix sort not appropriate for more than numbers?
|
because it's based on counting sort
|
|
What do we assume when using bucket sort?
|
that all values are distributed evenly in the interval [0, 1)
|
|
What is the best case time complexity for bucket sort?
|
O (n)
|
|
What is an effective way to implement a dictionary?
|
hash table
|
|
What is an ordinary array?
|
elements whose key, k, is stored in position k of the array
|
|
What is direct addressing?
|
Given a key, k, the element whose key k is found in the kth position of the array
|
|
What data structure is a generalization of ordinary arrays?
|
hash tables
|
|
Which mathematical methods can be used to compute a hash function?
|
multiplication method and division method
|
|
What is meant by a "collision" in a hash function?
|
when two unique keys hash to the same table entry
|
|
What are two forms of hash tables can prevent collisions?
|
chaining and open addressing
|
|
What is a stipulation when using a hash table?
|
all keys are unique (no elements have the same key)
|
|
What is the average search time of a hash table?
|
O(1)
|
|
What is the worst search time of a hash table?
|
O(n) -- linear, all items much be searched
|
|
What is the worst-case search time of hash table with chaining?
|
O(n)
|
|
What is the best time search of hash table with chaining?
|
O(1)
|
|
What is the worst time deletion of hash table with chaining?
|
O(1) if doubly linked, O(n) if singly linked
|
|
What is a disadvantage to using hash tables?
|
high cost -- must keep more slots in table than number of keys
|
|
What is load factor?
|
the percentage of elements as compared to possible slots in a hash table (# elements/# slots)
|
|
Under what conditions would the search be worst case when using a hash table with chaining?
|
Θ(n)
|
|
What is the tight bounds for hashing with chaining?
|
Θ(1+α), where α is the number of unsuccessful examinations
|
|
What are the advantages to using the division method for hash tables?
|
fast since it requires only one division operation
|
|
What is the disadvantage to using the division method for hash tables?
|
have to avoid certain powers of m (best to use primes): h(k) = k mod m
|
|
What is the formula for the division method for hash tables?
|
h(k) = k mod m
|
|
What is the formula for the multiplication method for hash tables?
|
h(k) = m (k x A mod 1), where A is a constant (0..1)
|
|
What is the advantage of the multiplication method for hash tables?
|
value of m is not critical
|
|
What is the disadvantage of the multiplication method for hash tables?
|
slower than division method
|
|
How does open addressing differ from chaining?
|
open addressing stores keys directly in table ( slot h(k) contains key k), and chaining must use a hash function to compute the slot
|
|
What is a disadvantage to open addressing?
|
when adding, deleting, or searching, must probe locations based on k until NIL is found. When deleting, you can't just change value to NIL because that value could be part of a probe (must assign value of "deleted")
|
|
How can uniform hashing be created in open addressing?
|
by guaranteeing the probe sequence is some permutation of the m slots
|
|
What are three examples of ways to implement uniform hashing?
|
linear probing, quadratic probing, and double hashing
|
|
What is the worst case complete search of a binary tree?
|
Θ(lg n)
|
|
What is the worst case search of a linear chain within a binary tree?
|
Θ(n)
|
|
What is the time complexity of going up or down a path of a binary tree?
|
O(h)
|
|
REVIEW Ch. 12 SLIDES!!!
|
REVIEW Ch. 12 SLIDES!!!
|