Consider the following incomplete code fragment: Part A: What is output by the c
ID: 3671837 • Letter: C
Question
Consider the following incomplete code fragment:
Part A: What is output by the code fragment above when the Capitalized portions are completed as given below? Assume that Stack is implemented using a linked list, Queue is implemented using a circular array, and PriorityQueue is implemented using a max-heap.
Part B: What is the worst-case time complexity in Big-O notation for the resulting code fragments in a., b., and c. above? Assume arr is an array of N integers, and printing takes constant time.
Explanation / Answer
Answer for Question 1:
if the Statement 1 is stack : 4 8 9 5 3 6 7 1
if the Statement 2 is Queue : 1 7 6 3 5 9 8 4
if the Statement 3 is Priority Queue : 9 7 8 4 5 6 1 3
Time Complexity for Stack is O(n) times because
linked list will take O(n) times
Time Complexity for Queue is O(n) times because
Circular Array will take O(n) times
Time Complexity for Priority Queue is O(n) times
usinh max heapify will tae O(n) times.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.