(Solved) : Data Structures Algorithm Midterm Due 9am 21 April 2018 1 True False T F Two Different Alg Q28382001 . . .


Data Structures and Algorithm Midterm Due 9AM 21 April 2018 1. True/False T/F Two different algorithms with the same big-O time complexity (assume O(n)) wl run in exactly same number operations, if you give them the same size input. By the definition of big-O, if f(n) O(n), we can also say that f(n)-o(m2) If two algorithms’ time complexities are O(n2) and O(n), it might be the case that the one with O(n 2) time complexity runs in fewer operations for small sizes of n. 2. Definition: TIN) = 0?(M) if there are positive constants c and n0 such that T(N)s cf (N) when Based on the above definition of big-O and for fin)-5n 2+10n O(nA2), show example values of c and n0 that will satisfy f(n) sc’nA2 when n 2 no. If an algorithm takes 2 seconds for input size 64 (2A6), how long will it take for an input size 1024 (2A10) if the worst case running time complexity of the algorithm is the following? 3. b. ?. d. O(n) 0(n^2) O(logion) 4. Find the Big-O running time of the following code fragments. b. for(int i-o i<n; i++){ ?. for (intjn-1000: jkn: j++) for (int k-n/2; k<n; k++) iffi>500) break; sumtt sum+t, 5. For a stack data structure that is implemented using a doubly linked list, execute the following operations in the order they are shown and draw what the underlying list looks like after each operation. Assume the implementation uses addToTail for push. push(1), push(5), push(8), pop, push(7) For a queue data structure that is implemented using a doubly linked list, execute the following operations in the order they are shown and draw what the underlying list looks like after each operation. Assume the implementation uses addToTail for enqueue enqueue (1, enqueue (5), enqueue (8), dequeu, push(7) Which of the following sorting algorithms will take the least time if the elements in the array are almost sorted? a) Insertion b) Selection c)Mergesort d) Heapsort What can we say about the pivot, if after the first partitioning of the quicksort algorithm, the array looks like this: 2 35179 12 11 10 20? 6. 7. 8. a) b) c) d) The pivot is 12 The pivot is either 7 or 9 The pivot is either 2 or 20 The pivot is 9 9. Which algorithm should we use if the swap operation is too costly? Show transcribed image text
Expert Answer
Answer to Data Structures Algorithm Midterm Due 9am 21 April 2018 1 True False T F Two Different Alg Q28382001 . . .
OR