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

  Calculate the size of the state space as a function of n

n vehicles occupy squares (1, 1) through ( n , 1) (i.e., the bottom row) of an n × n grid. The vehicles must be moved to the top row but in reverse order

  Create time algorithm-minimum time required to finish task

Create the O(|V | + | E |) time algorithm which, given times ti and the dependencies, determines minimum time required to complete all the tasks.

  Find maximum possible amount of money by optimal strategy

Removes it from row permanently, and receives value of coin. Find out the maximum possible amount of money we can definitely win if we move first.

  Explain consensus algorithm

"Consensus algorithm": A group of ten people need to decide which one flavor of ice cream they will all order, out of three options.

  Prepare the initial linked list of students and grades

Write a C program which initially presents menu of choices for the user. Menu must consist of the following choices: Prepare the initial linked list of students and grades.

  Insertion sort and merged using standard merging mechanism

Using "insertion sort" and then merged using standard merging mechanism, where k is value to be determined. How must be we select k in practice?

  Implementation of graph

Give the two input nodes after the graph has been built from the command prompt.

  Show result of inserting keys using linear probing

Show the result of inserting these keys using linear probing, using quadratic probing with c1 = 1 and c2 = 3, and using double hashing with h2(k) = 1 + (k mod (m ¡ 1)).

  Algorithm to read arbitrary number of data records

Write the algorithm to read arbitrary number of data records, each comprising name, age, and code.

  List of common data structures

Make a list of some of the common data structures provided by C#. You should have a minimum of 4 different data types.

  Explain how to modify knuth-morris-pratt algorithm

Explain how to modify Knuth-Morris-Pratt algorithm to support patterns with these wild cards, and analyze modified algorithm. Your algorithm must find first substring in text which matches the pattern.

  Describe why algorithm runs in linear time-adjacency matrix

Rreached from every other vertex. Describe why your algorithm runs in linear time (O(V2) on an adjacency matrix; O(E+V) on an adjacency list).

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