Question: Consider the following algorithm, given some input vector x of length n. total-30; while n > 0 if x(n) 0 total = total + x(n)

Consider the following algorithm, given some input vector x of length n. total-30; while n > 0 if x(n) 0 total = total + x(n) n = n-1; else total = total - x(n) end end (a) Derive in Big-O notation, the computational cost of the algorithm. Hints: What is the worst case? In the worst case, how many times do we invoke the loop, and how many operations occur each time? What is the total number of operations? Convert your result to Big-O notation (b) If we use the sorting algorithm Quicksort on the vector x before calling r ning the algorithm above, what would be the Big-O complexity of the overall algorithm
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
