Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Find the worst-case time complexity for the OddMedian algorithm below Show al work You may use the facts that you can add an element
1. Find the worst-case time complexity for the OddMedian algorithm below Show al work You may use the facts that you can add an element to an array in () remove an element from an array in ?(1), find the size of an array in ?(1), and find the minimum or maximum of an array of size x in ?(2:) time. You may assume that lo and hi both have () elements during every iteration of the for loop Input: data: an array with an odd number of integers Input: n: the length of data (odd) Output: element m in data such that (n 1)/2 elements are smaller and (n -1)/2 elements are larger 1 Algorithm: OddMedian 2 med data l s fori 1 to n 1 do 6 if datai1lmed then if lo has less than i/2 elements then Add datali 1 to lo 9 else Add med to hi Add datali 1 to lo med max(lo) Remove med from lo 10 12 13 14 15 else 16 17 18 19 end if hi
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started