Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Suppose you have an array S of size n, where each element in S represents a different vote for class president, where each
1. Suppose you have an array S of size n, where each element in S represents a different vote for class president, where each vote is given as an integer representing the student ID of the candidate. Without making any assumptions about who is running or how many candidates there are, design an O(n lg n) algorithm to determine which candidate receives the most votes. [10 points] 2. Consider a modification to the previous problem to a situation where we know the number k < n of candidates running. Design an O(n lg k) algorithm to determine which candidate receives the most votes. [10 points] 3. Given the input of the first problem, give an O(n) time algorithm to determine if some candidate received a majority ([]) of the votes. O(n) average or expected time is OK so the hint is to look for the median [10 points] 4. Given a list of n integers, describe how to find the n smallest items, listed in increasing order, in O(n) time. The input list is unsorted, but the output should be sorted. (Hint: n lg n and nlgn are both O(n).) [10 points]
Step by Step Solution
★★★★★
3.33 Rating (147 Votes )
There are 3 Steps involved in it
Step: 1
To determine which candidate receives the most votes without assumptions about the candidates or the...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