Final

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Priority Queue in Simple Linked List insertion at the front is (a) deleteMin is (b)

(a) O(1) (b) O(n)

For binary tree of height h, min height is (a) and we want to avoid height (b)

(a) O(logN) (b) O(N)

Priority Queue in Binary Search Tree insertion is in average (a) deleteMin is in average (b)

(a) O(logN) (b) O(logN)

Priority Queue in Sorted Linked List insertion is (a) deleteMin is (b)

(a) O(n) (b) O(1)

For binary tree of height h, min # of leaves

1

For binary tree of height h, max number of nodes

2^(h + 1) - 1

For binary tree of height h, max number of leaves

2^h

If graph is MST and has 99 vertices, how many edges?

98

Which graph algorithms run in O( |V|^2 ) worst case? (no heaps)

Dijkstra, Prim

Queue

FIFO

Stack

LIFO

runtime complexity of Dijkstra's algorithm when the implementation is based on a binary min-heap.

O( (|E| + |V| ) log |V| )

worst case of Kruskal

O( |E| log |E| ) (by heap operations)

best case of Prim algorithm (with binary heaps)

O( |E| log |V| )

best case of Kruskal

O( |V| )

If you have... 50,000 words 52 = 26 upper + 26 lower up to length 12 per word what is running time complexity?

O(12 * (52 + 50,000) )

postorder, preorder, and inorder are

O(N)

AVL worst case of buildTree

O(NlogN)

running time for building BST

O(NlogN)

AVL worst case of find, insert

O(logN)

Euclid's algorithm is

O(logN)

BFS uses

Queue

Recurrence Relation for Merge Sort and Quick Sort (best case)

T(N) = 2T(n/2) + O(n) This is: O(NlogN)

Recurrence Relation for Selection Sort and Quick Sort (worst case).

T(N) = T(n-1) + O(n) This is: O(N^2)

Master Theorem

T(N) = a T(N/b) + O(N^d)

Rule 2: Complexity

T1(n) * T2(n) = O( f(n) * g(n) )

11. Which of the following could be used as an efficient priority queue? (a) binary search tree (b) hash table (c) linked list (d) queue (e) stack

a

17. For an insertion of a single item into an n-item AVL tree, the maximum number of rotations (double rotations count as one rotation) is (a) 1 (b) 2 (c) approximately log n (d) approximately 1:44 log n (e) none of the above

a

27.) Primary clustering occurs in a.) Linear Probing b.) Double Hashing c.) Quadratic Probing d.) Separate Chaining

a

6.) Program A worst-case running time is 150nlogn and B worst-case running time is n2. Which of the following are true? a.) Program A will run faster than program B in worst-case scenario. b.) Program B will run faster than program A in worst-case scenario. c.) Programs A and B have the same worst-case time complexity. d.) None of the above

a

How much extra space is used by heapsort? (a) O(1) (b) O(log n) (c) O(n) (d) O(n2 ) (e) none of the above

a

Which of the following data structures uses a sentinel? (a) binary heap (b) hash table (c) queue (d) stack (e) none of the above use sentinels

a

19.) Which operation is not efficiently supported by min-heaps? a.) DeleteMin b.) Find c.) FindMin d.) Insert e.) All of the above are sufficiently supported

b

24.) Which operation is O(n) worst case in a max-heap? a.) DeleteMax b.) FindMin c.) FindMax d.) None of the above

b

29.) Which operation is not efficiently supported by heaps? a.) Insert b.) Find c.) Delete max d.) Find min

b

8. Which traversal does not use a stack? (a) inorder (b) level order (c) postorder (d) preorder (e) all of these traversals uses a stack

b

9. Which data structure is generally used to implement a symbol table? (a) binary search tree (b) hash table (c) priority queue (d) queue (e) stack

b

What is the basic algorithm used for external sorting? (a) finding the median (b) merging (c) selection (d) all of the above (e) none of (a), (b), and (c)

b

Which of the following data structures does not yield an ecient comparison-based sort? (a) AVL tree (b) hash table (c) priority queue (d) all can be used for ecient sorting (e) none can be used for ecient sorting

b

Which of the following functions grows fastest? (a) n + log n (b) n log n (c) n log n (d) n (e) There is a tie among two or more functions for fastest growth rate

b

Which of the following functions grows fastest? (a) n log n (b) 2^n (c) log n (d) n^2 (e) n^20

b

Which operation is not eciently supported by priority queues? (a) Delete Min (b) Find (c) Find Min (d) Insert (e) All of the above are eciently supported

b

1. Which of the following data structures requires more than constant average time for insertions? (a) hash table (b) queue (c) search tree (d) stack (e) all of the above have constant time insertion algorithms

c

12. Which of the following does the binary heap implement? (a) binary search tree (b) hash table (c) priority queue (d) queue (e) stack

c

19. Items 7, 3, 11, 9, and 13 are inserted into an AVL tree. What happens when 12 is inserted? (a) no rotation is needed (b) a single rotation between some node and its left child is performed (c) a single rotation between some node and its right child is performed (d) a double rotation with a node, its left child, and a third node is performed (e) a double rotation with a node, its right child, and a third node is performed

c

26.) The minimum and maximum height for AVL-tree with n nodes is: a.) O(1) b.) O(n) c.) O(log n) d.) none of the above

c

4. Which of the following is true about the height of a node? (a) The height of a node is one less than the height of its parent (b) The height of an empty tree is 0 (c) The height of a leaf is 0 (d) The height of a tree can be larger than its depth (e) all of the above are false

c

A recursive algorithm works by solving two half-sized problems recursively, with an additional linear-time overhead. The total running time is most accurately given by (a) O(log n) (b) O(n) (c) O(n log n) (d) O(n2 ) (e) none of the above

c

shell sort average case

conjectured

12.) Which of the following algorithms runs in O(NlogN) average time but quadratic worst-case time? a.) heap sort b.) insertion sort c.) merge sort d.) quick sort

d

25.) Which operation is O(log n) worst case in a max-heap? a.) DeleteMin b.) FindMin c.) FindMax d.) Insert a new element

d

What is the maximum number of nodes in a binary tree with L leaves? (a) 2L (b) 2L (c) 2L+1 (d) there is no maximum (e) none of the above

d

n elements are inserted one by one into an initially empty binary heap. The total running time is (a) O(n) worst case and O(n) average case (b) O(n) worst case and O(log n) average case (c) O(n) worst case and O(n log n) average case (d) O(n log n) worst case and O(n) average case (e) O(n log n) worst case and O(n log n) average case

d

11. Which of (a) to (d) is false about the binary search? (a) the input array must be sorted (b) successful searches take logarithmic time on average (c) unsuccessful searches take logarithmic time on average (d) the worst case for any search is logarithmic (e) all of the above are true

e

14. Which data structure is used by the compiler to implement recursion? (a) hash table (b) priority queue (c) queue (d) search tree (e) stack

e

3. The header node of a linked list (a) simplifies deletion (b) simplifies insertion (c) uses only constant extra space (d) two of the above (e) all three of (a), (b), and (c)

e

6b) Programs A and B are analyzed and found to have worst-case running times no greater than 150n log n and n2 , respectively. Which of the following statements does the analysis imply? a.) Program A will run faster on average for sufficiently large n. b.) Program B will run faster on average for small n. c.) Program A is probably simpler to code than program B. d.) There exists some input for which program B takes longer than program A. e.) none of the above

e

7. Which data structure is used to check for balanced parentheses? (a) binary search tree (b) hash table (c) priority queue (d) queue (e) stack

e

In median-of-three partitioning, where is the pivot placed before partitioning begins? (a) at the start of the array (b) at the middle of the array (c) at the end of the array (d) in a temporary variable (e) none of the above

e

Which of the following algorithms has the largest big-Oh differential between average-case and worst-case performance? (a) heapsort (b) insertion sort (c) mergesort (d) quicksort (e) quickselect

e

BFS and DFS are weighted or unweighted?

either

For binary tree of height h, min # of nodes

h + 1

Which algorithms run in O(N^2) worst case?

insertion, selection, quick, bucket

Elementary Sorting (name them)

insertion, selection, shell

Which algorithms have the same space memory?

insertion, selection, shell (1)

DFS does?

left subtree then the right subtree

Rule 3: Complexity

logkN = O(N) for any constant k

BFS does?

parent then child

Which of the following algorithms runs in O(NlogN) average time but quadratic worst-case time?

quick sort

which algorithms run in O(N^2) for best, average, and worst case?

selection

which algorithms run in O(N^2) for average, and worst case?

selection, insertion

Which algorithms are NOT stable?

selection, shell, quick, heap

shell sort worst case

subquadratic

dijkstra is

weighted, directed (makes the shortest path)

kruskal, prim are

weighted, undirected (makes an MST tree)

Which of the following operations is O(1) in a single-linked list with pointers at the front (first element) and at the end (last element)?

- Get the first element of the list. - Insert an element at the end of the list.

Priority Queue Sorting (name them)

heap

which algorithm run in O(NlogN) for best, average, and worst case?

heap and merge

Which algorithms are stable?

insertion and merge

runtime complexity of Dijkstra's algorithm when the implementation is not based on a binary min-heap.

O( |V|^2 )

If you have... 50,000 words 52 = 26 upper + 26 lower up to length 15 per word what is running time complexity?

O(15 * (52 + 50,000) )

If a > b^d then

O(N logba)

insertion best case

O(N)

If a = b^d then

O(N^d logN)

If a < b^d then

O(N^d)

shell sort best case

O(NlogN)

Rule 1: Complexity

T1(n) + T2(n) = O( max(f(n), g(n) ) ) same as T1(n) + T2(n) = O( f(n) )

10. For the linked list implementation of the stack, where are the pushes and pops performed? (a) Push in front of the first element, pop the first element (b) Push after the last element, pop the last element (c) Push after the last element, pop the first element (d) Push in front of the first element, pop the last element (e) Push after the first element, pop the rst element

a

For quicksort, what do I and J do when they see keys equal to the pivot? (a) I stops, J stops (b) I stops, J goes (c) I goes, J stops (d) I goes, J goes (e) I and J alternate between stopping and going

a

Which algorithm requires the most extra space memory?

merge (n)

Divide and Conquer Sorting (name them)

merge, quick

Which of the following can be done in O(LogN)?

- Find an element in a sorted array - Raising a number to the nth power - Computing the greatest common divisor of some integer and n

Which of the following can be done in O(N)?

- Find an element in an unsorted array - Find an element in a binary tree - Delete an element in an unsorted array.

DFS uses

Stack

where to start in kruskal?

from edges with smallest weight

where to start in dijkstra?

from given vertex (single source)

If graph is *NOT* MST and has 99 vertices, how many edges?

Cannot be determined with the given information

DFS and BFS complexity is

O( |V| + |E| )

30.) Which of the following are false?: The size of a hash table a.) should be a power of 2 for quadratic probing b.) should be a prime number for linear probing c.) should be about 2n for quadratic probing d.) should be about n for separate chaining e.) Two or more of the above are false

a

8. If the shortest path algorithm is run and a vertex is not reachable from the starting point, what happens? (a) a distance of infinity is reported (b) a distance of -1 is reported (c) a distance of zero is reported (d) the algorithm enters an in nite loop (e) the algorithm's results are unde ne

a

The running time of Build Heap is (a) O(n) worst case and O(n) average case (b) O(n) worst case and O(log n) average case (c) O(n) worst case and O(n log n) average case (d) O(n log n) worst case and O(n) average case (e) O(n log n) worst case and O(n log n) average case

a

Which of (a) to (d) is false: The size of a hash table (a) should be a power of 2 for quadratic probing (b) should be a prime number for linear probing (c) should be about 2n for quadratic probing (d) should be about n for separate chaining (e) two or more of the above are false

a

Which of the following algorithms solves the unweighted single source shortest path problem? (a) breadth first search (b) depth first search (c) Dijkstra's algorithm (d) Kruskal's algorithm (e) Prim's algorithm

a

size of a hash table for *separate chaining*

a prime number approximately equal to n

size of a hash table for *quadratic probing*

a prime number greater than 2n

size of a hash table for *double hashing*

a prime number greater than n

size of a hash table for *linear probing*

a prime number greater than n

BFS and DFS can be used on

any graph

10. Which of the following statements is true? (a) A topological ordering exists in every directed graph (b) Every acyclic graph has at least one topological ordering (c) Every acyclic graph has exactly one topological ordering (d) Every acyclic graph has at most one topological ordering (e) none of the above

b

10.) Which of a) to d) is true: The size of a hash table with n keys a.) should be n for double-hashing b.) should be a prime number greater than n for linear probing c.) should be a prime number and less than 2n for quadratic probing d.) none of these

b

28.) Which of the following algorithms runs in O(N^2) worst case? a.) heap sort b.) insertion sort c.) merge sort d.) shell sort

b

3. Which of the following does not use a queue? (a) negative weighted shortest path algorithm (b) positive weighted shortest path algorithm (c) topological sort (d) unweighted shortest path algorithm (e) all of the above use a queue

b

30.) Which of the following algorithms is stable? a.) heap sort b.) insertion sort c.) shell sort d.) selection sort

b

31.) Which sorting algorithm has the same worst-case time bounds (in Big-Oh notation) as heap sort? a.) insertion sort b.) merge sort c.) quick sort d.) shell sort

b

33.) What is the worst-case time complexity of insertion sort? a.) O(n) b.) O(n^2) c.) O(log n) d.) None of the above

b

Which of the following algorithms runs in quadratic average time? (a) heapsort (b) insertion sort (c) mergesort (d) quicksort (e) shellsort

b

Which of the following algorithms, implemented as in the text, runs in O(n) time when presented with an array of n identical elements? (a) heapsort (b) insertion sort (c) mergesort (d) quicksort (e) shellsort

b

Which of the following costs are equal in a probing hash table? (a) insertion and successful search (b) insertion and unsuccessful search (c) successful search and unsuccessful search (d) insertion, successful search, and unsuccessful search (e) none of the above

b

Which sorting algorithm has the same average and worst-case time bounds (in Big-Oh) as heapsort? (a) insertion sort (b) mergesort (c) quicksort (d) shellsort (e) none of the above

b

Non - Comparison Sorting (name them)

bucket, radix

11.) Which of the following algorithms requires the most extra space memory (not in place algorithm)? a.) insertion sort b.) selection sort c.) merge sort d.) shell sort

c

14.) What is the recurrence relation for selection sort? a.) T(N) = T(N-1) + O(1) b.) T(N) = 2T(N/2) + O(1) c.) T(N) = T(N-1) + O(N) e) none of the above

c

18.) A minimum element is deleted from a (min) binary heap with n elements. The running time worst case of this operation is a.) O(n) b.) O(n^2) c.) O(log n) d.) O(n log n)

c

19b.) Which of the following operations is not efficiently supported by a singly-linked list? a.) accessing the element in the current position b.) insertion after the current position c.) insertion before the current position d.) moving to the position immediately following the current position

c

25.) Indicate the running time complexity of radix sort in a set of 50000 words of English letters (52 = 26 upper + 26 lower cases) up to length 12 per word. a.) O(50000*(52 + 12)) b.) O(52*(12 + 50000)) c.) O(12*(52 + 50000)) d.) none of the above

c

32.) Which one uses divide and conquer sorting? a.) Insertion b.) Selection c.) Merge sort d.)Heap sort

c

5. Insertion of a node into a doubly linked list requires how many changes to various Next and Prev pointers? (a) no changes (b) 1 Next, 1 Prev (c) 2 Next, 2 Prev (d) 3 Next, 3 Prev (e) none of the above

c

where to start in prim?

from any vertex

8.) Which of the following operations is not O(1) in a single-linked list with pointers at the front (first element) and at the end (last element)? a. Get the first element of the list. b. Insert an element at the end of the list. c. Remove the last element of the list. d. All of the above operations are O(1).

c

9.) For the linked list implementation of the queue, where are the enqueues and dequeues performed? a.) Enqueue in front of the first element, dequeue the first element. b.) Enqueue after the last element, dequeue the last element. c.) Enqueue after the last element, dequeue the first element. d.) Enqueue in front of the fist element, dequeue the last element.

c

Which of the following algorithms solves the positive weighted single source shortest path problem? (a) breadth rst search (b) depth rst search (c) Dijkstra's algorithm (d) Kruskal's algorithm (e) Prim's algorithm

c

13.) Which of the following algorithms is non-stable? a.) Heap sort b.) Selection sort c.) Shell sort d.) All of the above

d

2. Which of the following problems is not known to be solvable in linear time? (a) topological sort (b) unweighted shortest path in general graphs (c) weighted shortest path in acyclic graphs (d) weighted shortest path in cyclic graphs (e) all are solvable in linear time

d

27.) Which of the following is the strongest lower bound for sorting when ordering information is obtained only by adjacent comparisons? a.) O(NlogN) b.) O(N^2) c.) Ω(NlogN) d.) Ω(N^2) e.) none of the above

d

29.) Which of the following algorithms runs in O(NlogN) average time but quadratic worst-case time? a.) heap sort b.) insertion sort c.) merge sort d.) None of the above

d

31.) How are elements deleted in linear probing? a.) The element reference array[ i ]. element is made null b.) The HashEntry reference array[ i ] is made null c.) They are changed to zero d.) They are marked deleted e.) None of the above

d

9. Linked lists are used in (a) double hashing (b) linear probing (c) quadratic probing (d) separate chaining (e) all of the above

d

Rehashing can be used in (a) linear probing (b) quadratic probing (c) separate chaining (d) all of the above (e) none of (a), (b), and (c)

d

Which algorithm is used to compute minimum spanning trees? (a) breadth first search (b) depth first search (c) Dijkstra's (d) Kruskal's (e) none of the above

d

Which of the following statements about quadratic probing is true (expensive does not include trivial operations such as multiplication or division by powers of 2; computation of the hash function is not included in the cost)? (a) an expensive division must be performed (b) an expensive mod operator must be performed (c) an expensive multiplication must be performed (d) all of the above (e) none of (a), (b), and (c)

e


संबंधित स्टडी सेट्स

Government and Economics Unit 2 Quiz 3: How a Bill Becomes Law

View Set

Chapter 7 (Arrays and Strings) - Exercises

View Set

MC 1100 medical front office procedure quiz revie

View Set

N210/220 Assignment 3: Health & Physical Assessment

View Set

General Mathematics - Number Systems and Sets

View Set

NovSpA - DLU1 - Tpc02A - Cuando nací: Los 12 meses del año

View Set

Vocabulary Unit 4 Argumentative and Persuasive Text

View Set

Loops(for loop, while loop, do while loop) - Basic Java Tutorials For Selenium WebDriver

View Set

Module 5: Cancer and the Immune System

View Set

Nervous/Musculoskeletal System Part 1 quiz

View Set