1. Suppose you have an array S of size n, where each element in S represents...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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] 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]
Expert Answer:
Answer rating: 100% (QA)
To determine which candidate receives the most votes without assumptions about the candidates or the... View the full answer
Related Book For
Data Structures and Algorithms in Java
ISBN: 978-1118771334
6th edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
"internet radios" for streaming audio, and personal video recorders and players. Describe design and evaluation processes that could be used by a start-up company to improve the usability of such...
-
In Exercises find the second derivative of the function. f(x) = x sin x
-
Company A has a price-earnings ratio of 9 times and a payout ratio of 40%. Company B has a price earnings ratio of 22 times and a payout ratio of 5%. Which company's shares would be better for an...
-
What is a spending variance, and how is it used in responsibility reporting?
-
Copy your worksheet from Question 6 into another worksheet. Change the increase from 10% to 18%. Protect the worksheet, so that changes cannot be made. Question 6 Open a new spreadsheet. Type...
-
The list below indicates various audit, attestation, and assurance engagements involving auditors. 1. A report on the effectiveness of internal control over financial reporting as required by Section...
-
Without using row reduction, apply block operation on A to compute its inverse. [1 2000 3 50 00 A=0 0 2 00 0007 8 0 0056
-
Read the overview below and complete the activities that follow. When auditing inventory and cost of goods sold, auditors select the most appropriate procedures for the audit but typically follow the...
-
A bond has a 25-year maturity, an 8% annual coupon paid semiannually, and a face value of $1,000. The going nominal annual interest rate (r d ) is 6%. What is the bonds price?
-
Brighton Memorys stock is currently trading at $50 a share. A call option on the stock with a $35 strike price currently sells for $21. What is the exercise value of the call option? ($15.00) What is...
-
Assume that the real risk-free rate is r* = 3% and that the average expected inflation rate is 2.5% for the foreseeable future. The applicable MRP is 2% for a 20-year bond. What is the yield on a...
-
The yield on a 15-year TIPS is 3%, and the yield on a 15-year Treasury bond is 5%. What is the inflation premium for a 15-year bond?
-
Describe the effect of a change in each of the following factors on the value of a call option: (1) stock price, (2) exercise price, (3) option life, (4) risk-free rate, and (5) stock return standard...
-
Question 02: (a) Discuss these XRD results. . Ni Ni,C (b) (a) 30 40 50 60 70 80 Two Theta (20) Intensity (a.u.) (oot) (111) (0ozi (ooz) (220) (220)
-
g(x) = x 5 5x 6 a. Show that g(x) = 0 has a root, , between x = 1 and x = 2. b. Show that the equation g(x) = 0 can be written as x = (px + q) 1/r , where p, q and r are integers to be found. The...
-
Extend the previous project by providing a graphical animation of the skip-list operations. Visualize how entries move up the skip list during insertions and are linked out of the skip list during...
-
What is the longest (proper) prefix of the string "cgtacgttcgtacg" that is also a suffix of this string?
-
An independent set of an undirected graph G = (V,E) is a subset I of V such that no two vertices in I are adjacent. That is, if u and v are in I, then (u,v) is not in E. A maximal independent set M...
-
Which of the following is not one of the five major categories of fraudulent disbursements? 1. Payroll schemes 2. Expense reimbursement schemes 3. Shell company schemes 4. Billing schemes
-
Assume that your data analytics examination related to employee records resulted in the following summary table for employees with annual salaries greater than $75,000: Assume that your data...
-
Why was Adelphia cable company formed?
Study smarter with the SolutionInn App