Describe why algorithm runs in on time

Assignment Help Data Structure & Algorithms
Reference no: EM1372062

Assume you have an array A of n items, and you want to find the k items in A closest to the median of A. For example, if A contains the 9 values {7, 14, 10, 12, 2, 11, 29, 3, 4} and k = 5, then the answer would be the values {7, 14, 10, 12, 11}, since the median is 10 and these are the five values in A closest to the value 10. Give an algorithm to solve this problem in O(n) time, and explain why your algorithm runs in O(n) time. You may use the selection algorithms discussed in the book and the notes as subroutines of your solution. (Hint: you may want to call the selection algorithm more than once.)

Reference no: EM1372062

Questions Cloud

What is non-verbal communication : What is non-verbal communication and how does one improve it and how can one be self-aware of their non-verbal gestures?
Discuss the concept of marriage : Describe and critically discuss the concept of marriage from both the functionalist perspective and the conflict perspective. Provide at least one example for each.
Define subsidy : Mr. Smith, has fallen behind on his work, he has asked you to help to make a letter for a local business or economic project.
Contemporary norms associated with hegemonic masculinity : Determine the contemporary norms associated with the hegemonic masculinity and document the consequences of such norms for men and their families, and their relationships with women.
Describe why algorithm runs in on time : Assume you have the array A of n items, and you want to find k items in A closest to the median of A. Describe why your algorithm runs in O(n) time.
Disucss the influences of price elasticity of demand : Post a memo to explain the factors that contribute to the elasticity of goods. Also incorporate a real-life example of price elasticity of demand, and discuss how it impacts the economy.
Major methods of sociological research : Discuss how each of the major methods of sociological research - experiment, survey, participant observation, and secondary research - are suitable for helping us to answer different types of questions and to study different situations.
Source of knowledge in terms of strengths : Evaluate each source of knowledge in terms of its strengths and limitations as it applies to how your discipline obtains knowledge.
Explain algorithm from is optimal by proving lower bound : Illustrate that your algorithm from (a) is optimal by proving lower bound of n - k on number of comparisons required to solve the problem.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Efficient algorithm to achieve goal using few base stations

Certain points along the road, so that every house is within four miles of one of the base stations. Give an efficient algorithm that achieves this goal using as few base stations as possible.

  Design analgorithm that decides for each node

Design an O(n) algorithm that decides (schedules) for each node at which time slot to start sending data such that the total number of time (slots) is minimized.

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Computing total number of keys needed in symmetric cipher

Determine the total number of keys that are needed for organization if symmetric cipher is used.

  Explain sorting algorithm which is optimal in cost

Explain a sorting algorithm which is optimal with respect to this cost model and uses O(n) space. That is, time used by algorithm should exactly match lower bound

  Lazy version of eager decision tree learning algorithm

Suggest a lazy version of the eager decision tree learning algorithm ID3. What are the advantages and disadvantages of your lazy algorithm compared to the eager algorithm.

  Write the selection sort algorithm

Write the selection sort algorithm

  Explain types of information systems

Question 1. Explain five types of information systems, and give an example of each. Question 2. Describe three common reasons for a systems request. Try and find one not listed in the text.

  Explaining view of header and footer areas of worksheet

In which view can you see header and footer areas of worksheet?

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  C++ program to evaluate expressions combining set union

Create a C++ program to evaluate expressions combining set union, set intersection and parentheses

  Determining hash value of modified file

Determine hash value of modified file look like, as compared with original hash value?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd