3310 - Chapters 9 through 15
If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed? ABCD ABDC DCBA DCAB
DCBA
Quicksort's worst-case case cost is O(n^2) and its average-case cost is O(n log n). This means that the fraction of input cases with cost O(n^2) must: Drop as n grows Never happen Happen only once Be less than 1 in nn
Drop as n grows
Hashing is good for which queries? Exact match queries Range queries Finding the maximum key value All of these None of these
Exact match queries
An advantage of linked lists over the array-based list implementation is: Expandability Low access cost to arbitrary positions None of these Zero overhead Optimal search speed
Expandability
A doubly linked list is a pair of singly linked lists that each interconnect the same nodes. True False
False
Bucket hashing works well for disk-based hash systems. True False
False
In a doubly linked list implementation, to access the predecessor of the current node we must start at the first node in the list. True False
False
In an array-based list implementation, to access the predecessor of the current node we must start at the first node in the list. True False
False
Linked lists are better than array-based lists when the final size of the list is known in advance True False
False
Open hashing has the advantage that it can answer range queries or questions like what is the largest key in the database. True False
False
The physical order in memory for the nodes of a linked list is the same as the order in which the nodes appear in the list. True False
False
The Stack is best characterized as: Last-In, First-Out First come, First Served First-In, First-Out Just-in-Time
Last-In, First-Out
Which data structure allows insertion only at the back, and removing only from the front? Queue Linked list Stack Tree Array-based list
Queue
One difference between a queue and a stack is: Queues use two ends of the structure; stacks use only one Stacks require linked lists, but queues do not Queues require linked lists, but stacks do not Stacks use two ends of the structure, queues use only one
Queues use two ends of the structure; stacks use only one
Radix sort processes one digit at a time, and it uses a Binsort to sort the nn records on that digit. However, any stable sort could have been used in place of the Binsort. True False
True
Selection Sort is generally faster than the Bubble Sort on the same input True False
True
Selection sort is simple, but less efficient than the best sorting algorithms. True False
True
Stack A has entries a, b, c (in that order with a on top), while Stack B is initially empty. When an entry is popped out of stack A, it can be printed immediately or pushed to stack B. When an entry is popped out of stack B, it can only be printed. Which of the following permutations of a, b, c is not possible to print? c a b a b c b c a b a c
c a b
To access the node at position ii in a singly-linked list takes one step takes two steps requires that all its successors be visited requires that all its predecessors be visited
requires that all its predecessors be visited
What is the average case cost for a search on a properly tuned hash system that stores n records? Θ(n^2) Θ(1) Θ(logn) Θ(n)
Θ(1)
Given a doubly linked list implementation, inserting a new element to the current position takes how long? Θ(nlogn) time Θ(1) time Θ(n) time Θ(logn) time
Θ(1) time
Given a linked list implementation, deleting the current element takes how long in the average case? Θ(n) time Θ(nlogn) time Θ(logn) time Θ(1) time
Θ(1) time
Given a linked list implementation, deleting the element at arbitrary position ii takes how long in the average case? Θ(n) time Θ(logn) time Θ(1) time Θ(nlogn) time Θ(i) time
Θ(i) time
The worst-case cost for Radix Sort when sorting nn keys with keys in the range 0 to r^3-1r 3 −1 is: Θ(nlogn) Θ(n^2) Θ(n) Θ(n^3)
Θ(n)
What is the best-case time for Insertionsort to sort an array of n records? Θ(n^2) Θ(logn) Θ(nlogn) Θ(n)
Θ(n)
Given an array-based list implementation, deleting the current element takes how long in the average case? Θ(nlogn) time Θ(1) time Θ(n) time Θ(logn) time
Θ(n) time
Given an array-based list implementation, deleting the element at arbitrary position ii takes how long in the average case? Θ(nlogn) time Θ(logn) time Θ(1) time Θ(n) time
Θ(n) time
Given an array-based list implementation, inserting a new element to the current position takes how long in the average case? Θ(1) time Θ(logn) time Θ(nlogn) time Θ(n) time
Θ(n) time
What is the running time of Selection Sort when the input is an array that is reverse sorted? Θ(n^2) Θ(logn) Θ(n) Θ(nlogn)
Θ(n^2)
What is the worst-case cost for Quicksort to sort an array of n elements? Θ(n^2) Θ(nlogn) Θ(logn) Θ(n)
Θ(n^2)
What is the best-case cost of Shellsort for an array whose size nn is a power of 2 when using divide-by-twos increments? Θ(n) Θ(n^2) Θ(logn) Θ(nlogn)
Θ(nlogn)
What is the worst-case time for Mergesort to sort an array of nn records? Θ(nlogn) Θ(n^n) Θ(n) Θ(logn) Θ(n^2)
Θ(nlogn)
The following sequence of operations is performed on a queue: enqueue(1), enqueue(2), dequeue, enqueue(1), enqueue(2), dequeue, dequeue, dequeue, enqueue(2), dequeue. The values will be output in this order: 2,1,2,2,1 2,2,1,1,2 1,2,1,1,2 1,2,1,2,2 2,2,1,2,2 2,1,2,2,2
1,2,1,2,2
The array-based implementation for Mergesort uses how many arrays? 1 2 n logn
2
The following sequence of operations is performed on a stack: push(1), push(2), pop, push(1), push(2), pop, pop, pop, push(2), pop. The values will be output in this order: 2,1,2,2,2 2,2,1,1,2 1,2,2,1,2 1,2,1,2,2 2,1,2,2,1 2,2,1,2,2
2,2,1,1,2
What is the best case input for Shellsort? A sorted array because each sublist is sorted in linear time A random array, without too much order or dis-order, which will keep things balanced A reverse sorted array because because all the sublists are sorted in linear time It doesn't matter, all inputs of a given size will cost the same
A sorted array because each sublist is sorted in linear time
Which of the following is true of closed hashing? Records are stored on a list associated with a slot in the hash table All records are stored directly within the hash table None of the above
All records are stored directly within the hash table
An exchange sort is: Any sort where only adjacent records are swapped Any sort where records are swapped rather than using another mechanism for rearranging the array Any \Theta(n^2)Θ(n 2 ) sort Any \Theta(n)Θ(n) sort Another name for Insertion Sort
Any sort where only adjacent records are swapped
Which list implementation is best to answer the question "What is the item at position ii?" Freelist Singly linked list Array-based list Doubly linked list
Array-based list
In the linked implementation of a queue, a new item would be added: After all other entries that are smaller than the new entry At the current position At the head At the rear After all other entries that are greater than the new entry
At the rear
Which of the following operations is performed more efficiently by a doubly linked list implementation than by singly linked list? Finding the node preceding the current node Removing the current node Searching an unsorted list for a given item Traversing a list to process each node
Finding the node preceding the current node
Queue behavior is typically referred to as: First-In, First-Out First Come, First Served Just-in-Time Last-In, First-Out
First-In, First-Out
It is an error to enqueue data onto a(n) _______ queue. Full Empty Initialized Array-based Linked
Full
It is an error to push data onto a(n) _______ stack. Linked Full Empty Array-based Initialized
Full
When is Quicksort a good choice for sorting an array? We need a reasonably fast algorithm with a good worst case In most standard situations where you want to sort many records Each record requires a small amount of memory None of the above
In most standard situations where you want to sort many records
What is one disadvantage of quadratic probing as a collision resolution method? Insertions can fail even if there are empty slots in the hash table You have to check whether or not a node needs to be split Primary clustering can degrade performance Memory usage increases with each insertion
Insertions can fail even if there are empty slots in the hash table
What is one disadvantage of quadratic probing as a collision resolution method? Primary clustering can degrade performance Memory usage increases with each insertion Insertions can fail even if there are empty slots in the hash table You have to check whether or not a node needs to be split
Insertions can fail even if there are empty slots in the hash table
In an array-based list, the successive elements in the list: Must not occupy contiguous space in memory Must occupy contiguous space in memory None of these Need not occupy contiguous space in memory
Must occupy contiguous space in memory
In a linked list, the successive elements in the list: Need not occupy contiguous space in memory Must not occupy contiguous space in memory Must occupy contiguous space in memory None of these
Need not occupy contiguous space in memory
The order of the input records has what impact on the number of comparisons required by Mergesort (as presented in this module)? None There is a constant factor difference There is a big difference, the asymptotic running time can change
None
In the linked implementation of a queue, a new item would be added to the: Front None of these Rear Current position
Rear
Which of the following is true of open hashing? Records are stored on a list associated with a slot in the hash table The algorithm running time is determined by probes of different table cells until an empty one is found All records are stored directly within the hash table
Records are stored on a list associated with a slot in the hash table
Which of the following is true of open hashing? The algorithm running time is determined by probes of different table cells until an empty one is found Records are stored on a list associated with a slot in the hash table All records are stored directly within the hash table
Records are stored on a list associated with a slot in the hash table
Which data structure allows insertion only at the top, and deletion only at the top? Stack Tree Linked list Queue Array-based list
Stack
Which of these will NOT affect the RELATIVE running times for two sorting algorithms? The amount by which the values are out of order The CPU speed The allowable range for the record values The number of records
The CPU speed
When is Insertion Sort a good choice for sorting an array? Each record requires a small amount of memory Each record requires a large amount of memory The processor speed is fast The array contains only a few records
The array contains only a few records
Which value of a queue is accessible? The lowest-valued item The rear item The front item The highest-valued item The root The bottom item The top item
The front item
After Quicksort completes the partition function, where is the pivot? The first position in the partition The middle position in the partition The last position in the partition Between the smaller values and the greater values in the partition
The last position in the partition
Which of these is a traditional measure for the cost of a sorting algorithm? The memory size The amount by which the values are out of order The number of records The number of comparisons
The number of comparisons
Which is the best definition for a probe sequence? It is another name for a hash function The order in which the hash function will visit the slots of the hash table It is another name for collision resolution The order in which collision resolution will visit the slots of the hash table
The order in which collision resolution will visit the slots of the hash table
Which is the best definition for a probe sequence? It is another name for collision resolution It is another name for a hash function The order in which the hash function will visit the slots of the hash table The order in which collision resolution will visit the slots of the hash table
The order in which collision resolution will visit the slots of the hash table
Which value of a stack is accessible? The front item The bottom item The lowest-valued item The rear item The top item The root The highest-valued item
The top item
(Assuming no duplicate key values:) The order of the input records has what impact on the number of comparisons required by Heapsort (as presented in this module)? None There is a constant factor difference There is a big difference, the asymptotic running time can change
There is a constant factor difference
An open hashing table has an array size of 106. What is the maximum number of records that can be stored in the table? 106 53 There is no maximum None of the above
There is no maximum
Which of the following is not a linear data structure? These are all linear data structures Stack Queue Array-based list Linked list
These are all linear data structures
Bubble Sort (as the code is written in this module) is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys. True False
True
Closed hashing works well for disk-based hash systems. True False
True
In a singly linked list implementation, to access the predecessor of the current node we must start at the first node in the list. True False
True
In Shellsort, how are the sublists sorted? Using bubble sort since that is the most appropriate sort in this situation Using Quicksort, because this is generally the fastest sort Using Shellsort since this is a recursive algorithm Using Insertion Sort because Shellsort generally makes each subarray reasonably close to sorted Using any sort that you like, it doesn't matter so long as they are sorted
Using Insertion Sort because Shellsort generally makes each subarray reasonably close to sorted
In Shellsort, how are the sublists sorted? Using bubble sort since that is the most appropriate sort in this situation Using Shellsort since this is a recursive algorithm Using Quicksort, because this is generally the fastest sort Using Insertion Sort because Shellsort generally makes each subarray reasonably close to sorted Using any sort that you like, it doesn't matter so long as they are sorted
Using Insertion Sort because Shellsort generally makes each subarray reasonably close to sorted
When is Selection Sort a good choice to use for sorting an array? When the array has only a few elements out of place When each component of the array requires a small amount of memory When the cost of a swap is large, such as when the records are long strings None of these answers
When the cost of a swap is large, such as when the records are long strings
In which case might the number of comparisons NOT be a good representation of the cost for a sorting algorithm? When there are lots of records When the CPU is really fast When the amount of available space is small When we are comparing strings of widely varying length
When we are comparing strings of widely varying length
In which cases are the growth rates the same for Insertion Sort? Best and Average only Worst, Average, and Best Worst and Average only Worst and Best only
Worst and Average only
What is a disadvantage of linear probing? The algorithm is difficult to program It can lead to allocating a lot of extra memory You tend to get secondary clustering You tend to get primary clustering
You tend to get primary clustering
To find an element with value XX in a linked list with n nodes requires how many nodes to be visited in the worst case? logn nodes n nodes Two nodes One node n^2 nodes
n nodes