ANSWER MULTIPLE CHOICE
What is the tightest(best) worst case runtime for retrieving the smallest element in a min heap?
a. O(n)
b. O(1)
c. O(log(n))
o(log(n))
min heap
Definition: A min-Max heap is a complete binary tree such that if it is not empty,each element has a data member called key.Alternating levels of this tree are min levels and max level,respectively.the root is on min level.
To add an element to a min-max heap perform following
operations:
1. Append the required key to the array representing the min-max
heap. This will likely break the min-max heap properties, therefore
we need to adjust the heap. 2. Compare this key with its parent: 1.
If it is found to be smaller (greater) compared to its parent, then
it is surely smaller (greater) than all other keys present at nodes
at max(min) level that are on the path from the present position of
key to the root of heap. Now, just check for nodes on Min(Max)
levels. 2. If the key added is in correct order then stop otherwise
swap that key with its parent
ANSWER MULTIPLE CHOICE What is the tightest(best) worst case runtime for retrieving the smallest element in...
a) What is the worst - case runtime complexity of finding the smallest item in a min - heap? b) What is the worst - case runtime complexity of finding the largest item in a min - heap?
Show that the worst-case runtime of the Algorithm Heapify is on an array of length n in Ω(log(n)). Note: Construct a heap A with n nodes and show that heapify is called recursively accordingly.
Select all the valid asymptotic runtime bounds for the following function f2 in the worst case: public static int f1 (int n) { int x = 0; for (int i = 0; i < n; i++) { x++; } return x; } public static int f2 (int n) { if (n <= 1) { return 1; } return f1(n) + f2(n/2) + f2(n/2); } Θ(n^2) O(n^2) Θ(log(n)) Θ(log^2(n)) Θ(nlog(n)) Ω(n) Ω(n^2)
Which big-O expression best characterizes the worst case time complexity of the following code? public static int foo(int N) ( int count = 0; int i1; while (i <N) C for (int j = 1; j < N; j=j+2) { count++ i=i+2; return count; A. O(log log N) B. O(log N2) C. O(N log N) D. O(N2)
What is the Big Oh of the list method remove() in best case and worst cases? The answers to these two questions, found on page 396 are O(1) and O(n). Why is the best case O(1) and worst case O(n) ?
C++
Question 9 5 pts Deleting the minimum element in a min-heap of N elements takes in average case O(N log N) O(1) O(N) Oſlog N) D Question 10 5 pts The time taken to find an element in an AVL tree of depth d is Old) 02) Oſlog d) Old log d) Question 11 5 pts Secondary clustering in a hash table occurs when using Linear probing Separate chaining Quadratic probing Double hashing Question 12 5 pts When sorting...
In the worst case, the very best that a comparison based sorting algorithm can do when sorting n records is Q (n^2) Q(log (n!)) (log n) O Q (n)
what is the worst case run time when finding the maximum value in a binary min heap(implemented using array ) containing N elements? worst case run time: explain:
4. In an array-based implementation of the ADT list, what is the best case performance of the contains method? a. O(1) b. O(log n) C. O(n) d. O(nº) 5. In an array-based implementation of the ADT list, what is the worst case performance of the contains method? a. O(n) b. O(n) C. O(log n) d. 0(1) 6. In an array-based implementation of the ADT list, what is the performance of the contains method when the entry is not in the...
Problem 2. Consider sorting n numbers stored in array A by first finding the smallest element of A and exchanging it with the element in A[1]. Then find the second smallest element of A, and exchange it with A[2]. Continue in this manner for the first n − 1 elements of A. a. Write pseudocode for this algorithm, which is known as selection sort. b. Why does it need to run for only the first n−1 elements, rather than for...