Give an algorithm that takes n lines as input

Assignment Help Data Structure & Algorithms
Reference no: EM131206225

Text Book - Algorithm Design by Jon Kleinberg and Eva Tardos

Chapter 5 - Divide and Conquer

Exercises-

Q1. You are interested in analyzing some hard-to-obtain data from two separate databases. Each database contains n numerical values-so there are 2n values total-and you may assume that no two values are the same. You'd like to determine the median of this set of 2n values, which we will define here to be the nth smallest value.

However, the only way you can access these values is through queries to the databases. In a single query, you can specify a value k to one of the two databases, and the chosen database will return the kth smallest value that it contains. Since queries are expensive, you would like to compute the median using as few queries as possible.

Give an algorithm that finds the median value using at most O(log n) queries.

Q2. Recall the problem of finding the number of inversions. As in the text, we are given a sequence of n numbers a1,..., an, which we assume are all distinct, and we define an inversion to be a pair i < j such that ai > aj.

We motivated the problem of counting inversions as a good measure of how different two orderings are. However, one might feel that this measure is too sensitive. Let's call a pair a significant inversion if i < j and ai > 2aj. Give an O(n log n) algorithm to count the number of significant inversions between two orderings.

Q3. Suppose you're consulting for a bank that's concerned about fraud detection, and they come to you with the following problem. They have a collection of n bank cards that they've confiscated, suspecting them of being used in fraud. Each bank card is a small plastic object, containing a magnetic stripe with some encrypted data, and it corresponds to a unique account in the bank. Each account can have many bank cards corresponding to it, and we'll say that two bank cards are equivalent if they correspond to the same account.

It's very difficult to read the account number off a bank card directly, but the bank has a high-tech "equivalence tester" that takes two bank cards and, after performing some computations, determines whether they are equivalent.

Their question is the following: among the collection of n cards, is there a set of more than n/2 of them that are all equivalent to one another? Assume that the only feasible operations you can do with the cards are to pick two of them and plug them in to the equivalence tester. Show how to decide the answer to their question with only O(n log n) invocations of the equivalence tester.

Q4. You've been working with some physicists who need to study, as part of their experimental design, the interactions among large numbers of very small charged particles. Basically, their setup works as follows. They have an inert lattice structure, and they use this for placing charged particles at regular spacing along a straight line. Thus we can model their structure as consisting of the points {1, 2, 3, . . . , n} on the real line; and at each of these points j, they have a particle with charge qj. (Each charge can be either positive or negative.)

They want to study the total force on each particle, by measuring it and then comparing it to a computational prediction. This computational part is where they need your help. The total net force on particle j, by Coulomb's Law, is equal to

1419_Img.png

It's not hard to analyze the running time of this program: each invocation of the inner loop, over i, takes O(n) time, and this inner loop is invoked O(n) times total, so the overall running time is O(n2). The trouble is, for the large values of n they're working with, the program takes several minutes to run. On the other hand, their experimental setup is optimized so that they can throw down n particles, perform the measurements, and be ready to handle n more particles within a few seconds. So they'd really like it if there were a way to compute all the forces Fj much more quickly, so as to keep up with the rate of the experiment. Help them out by designing an algorithm that computes all the forces Fj in O(n log n) time.

Q5. Hidden surface removal is a problem in computer graphics that scarcely needs an introduction: when Woody is standing in front of Buzz, you should be able to see Woody but not Buzz; when Buzz is standing in front of Woody,... well, you get the idea.

The magic of hidden surface removal is that you can often compute things faster than your intuition suggests. Here's a clean geometric example to illustrate a basic speed-up that can be achieved. You are given n non vertical lines in the plane, labeled L1,..., Ln, with the ith line specified by the equation y = aix + bi. We will make the assumption that no three of the lines all meet at a single point. We say line Li is uppermost at a given x-coordinate x0 if its y-coordinate at x0 is greater than the y-coordinates of all the other lines at x0: aix0 + bi > ajx0 + bj for all j ≠ i. We say line Li is visible if there is some x-coordinate at which it is uppermost-intuitively, some portion of it can be seen if you look down from "y =∞."

Give an algorithm that takes n lines as input and in O(n log n) time returns all of the ones that are visible. Figure 5.10 gives an example.

Q6. Consider an n-node complete binary tree T, where n = 2d - 1 for some d. Each node v of T is labeled with a real number xv. You may assume that the real numbers labeling the nodes are all distinct. A node v of T is a local minimum if the label xv is less than the label xw for all nodes w that are joined to v by an edge.

You are given such a complete binary tree T, but the labeling is only specified in the following implicit way: for each node v, you can determine the value xv by probing the node v. Show how to find a local minimum of T using only O(log n) probes to the nodes of T.

Q7. Suppose now that you're given an n × n grid graph G. (An n × n grid graph is just the adjacency graph of an n × n chessboard. To be completely precise, it is a graph whose node set is the set of all ordered pairs of natural numbers (i, j), where 1≤ i ≤ n and 1≤ j ≤ n; the nodes (i, j) and (k, l) are joined by an edge if and only if |i - k|+|j - l|= 1.)

1716_Img1.png

We use some of the terminology of the previous question. Again, each node v is labeled by a real number xv; you may assume that all these labels are distinct. Show how to find a local minimum of G using only O(n) probes to the nodes of G. (Note that G has n2 nodes.)

Reference no: EM131206225

Questions Cloud

What was the general sequence of events : Who was Pope'/Po'pay? What was his history and why was he important? How did the revolt go? What was the general sequence of events? How long did the revolts keep the Spanish out?
Calculate paul monthly claim under : 1. Calculate Paul's monthly claim under his income protection insurance cover if he decides not to take up the offer to return to work on a part-time basis.
Develop a program to perform the analysis appearing : Using the results of given problem, develop a program to perform the analysis appearing in Example (b) for cast steel.
Who have no identifiable living descendants : ANTHROPOLOGY 1510 - THE WAYS OF HUMANKIND: AN ANTHROPOLOGICAL PERSPECTIVE" SPRING 2016 - Consider the issues at hand and post a statement of your thoughts on it. Should human remains be left alone entirely? Is it acceptable to excavate and study th..
Give an algorithm that takes n lines as input : Give an algorithm that takes n lines as input and in O(n log n) time returns all of the ones that are visible. Figure 5.10 gives an example
Calculate net income : Presented below are changes in the account balances of Al-Othman Company during the year, except for Retained Earnings. The only entries in Retained Earnings were for net income and dividends. Al-Othman declared dividends of $8,250 and paid divide..
What challenges does such a brand recall rate present : Why was it logical for UPS to have four different marketing approaches? How important is a brand recall rate of 97% to 98% for UPS? What challenges does such a brand recall rate present to competitors?
Management of a product line : You have been asked to take over management of a product line by your Division Manager.  Your Cost model for this product line is C = 50(x) + 59,500, where "x" represents units produced during a particular sales period and "C" represents total Costs.
What is the total materials cost of entire roofing project : How many pounds of 1-inch roofing nails will the job require, and what is the cost? How many 10-foot lengths of drip edge will finish the job, and at what cost? Finally, what is the total materials cost of the entire roofing project?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implementation of graph

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

  Question about pointerlists

Whenever the pointer of a list or a tree is manipulated, procedure that performs this operation must be considered to be in a critical section.

  Formula to compute number of address bus conductors

If an address bus needs to be able to address 8-devices, how many conductors will be needed? What if each of those devices also requires to be able to talk back to the I/O control device?

  Making visual studio.net web application

Make a Visual Studio.NET 2005 web application with 2-aspx forms. Add a Menu control and a Label control to form. Populate the Menu control with data stored in the "Font" column and show your name in the Label control.

  Kind of switching to configure switch to use

Your network's traffic load is very high all times, day and night. What kind of switching do you configure switch to use?

  Find the longest monotonically

Describe an O(n) time algorithm that, given a set S of n distinct numbers and a positive integer k ≤ n, determines the k numbers in S that are closest to the median of S.

  Question about unix commands

Assume you have a document called records.txt having the list of employee id and workers names. Every line contains a single employee id immediately followed by the employee name in the format Last name, First name.

  Find the price of the pizza per square inch

Given the radius, in inches, and price of a pizza, design an algorithm to find the price of the pizza per square inch.

  What is the most favorite loop structure, and why

Give an example of how you might use a C array to solve a real life business problem.

  Creating an effective physical design

Class, do IT database designers necessary to understand data volumes and number of users of database in order to create an effective physical design?

  Using command line options in bash shell script

Design a script that will permit the user to enter one of several choices from the command line. The specific requirements are as follows:

  Question 1write the selection sort algorithm as a template

question 1write the selection sort algorithm as a template function using the less than operator to compare two

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