Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Use pseudocode to describe the recursive algorithm for solving the closest-pair problem as described in Example 12.

Short Answer

Expert verified

The minimum distance and the closest pair d.

Step by step solution

Achieve better grades quicker with Premium

  • Unlimited AI interaction
  • Study offline
  • Say goodbye to ads
  • Export flashcards

Over 22 million students worldwide already upgrade their learning with Vaia!

01

Definition of shortest distance

The distance between two array values is the number of indices between them.

02

Find the closest pair by the formula of shortest distance and midpoint

closest ((x1,y1),...,(xn,yn)list of points with n1)

If the list contains only two points, then the minimum distance is the distance between the two points and the two closest points are the two points in the list. if n=2then,d=(x2-x1)2+(y2-y1)2

Pair =(x1,y1),(x2,y2)

03

Divide the list into two sub lists and perform the algorithm

Divide the list into two sub lists and perform the algorithm on the sub lists first.

dwill represent the minimum distance between among the two sub lists.

The minimum is then the minimum dand the pair of points with one point in each sub list.

mwill represent the middle between the x-coordinates of the two sub lists and now, only need to check the points that are within dof mfor the pairs across the two sub lists.

m=xn/2+xn/2/2,dL, PairL:=closest((x1,y1),...,(xn/2,yn/2))

dR, pair

If , then d=dL.

d=dR

P'=sub list of points whose x-coordinates are within dof m.

For every point (x,y)in p

for every point (x',y') in P' after (x,y) such that

y'-y<d,a=(x'-x)2+(y'-y)2

If a<d thena=x,y,(x',y')

Finally, the minimum distance and the closest pair. return d, pair.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

A sequence \({a_1},{a_2},.....,{a_n}\) is unimodal if and only if there is an index \(m,1 \le m \le n,\) such that \({a_i} < {a_i} + 1\) when \(1{1 < i < m}\) and \({a_i} > {a_{i + 1}}\) when \(m \le i < n\). That is, the terms of the sequence strictly increase until the \(m\)th term and they strictly decrease after it, which implies that \({a_m}\) is the largest term. In this exercise, \({a_m}\) will always denote the largest term of the unimodal sequence \({a_1},{a_2},.....,{a_n}\).

a) Show that \({a_m}\) is the unique term of the sequence that is greater than both the term immediately preceding it and the term immediately following it.

b) Show that if \({a_i} < {a_i} + 1\) where \(1 \le i < n\), then \(i + 1 \le m \le n\).

c) Show that if \({a_i} > {a_{i + 1}}\) where \(1 \le i < n\), then \(1 \le m \le i\).

d) Develop a divide-and-conquer algorithm for locating the index \(m\). (Hint: Suppose that \(i < m < j\). Use parts (a), (b), and (c) to determine whether \(((i + j)/2) + 1 \le m \le n,\) \(1 \le m \le ((i + j)/2) - 1,\) or \(m = ((i + j)/2)\)

Give a big-O estimate for the size of f in Exercise \(1{20}\) if f is an increasing function.

Give a big- Oestimate for the functionf in Exercise 10 iff is an increasing function.

Give a big- Oestimate for the function fin Exercise34iffis an increasing function.

Find a closed form for the generating function for each of these sequences. (For each sequence, use the most obvious choice of a sequence that follows the pattern of the initial terms listed.)

a) \(0,2,2,2,2,2,2,0,0,0,0,0, \ldots \)

b) \(0,0,0,1,1,1,1,1,1, \ldots \)

c) \(0,1,0,0,1,0,0,1,0,0,1, \ldots \)

d) \(2,4,8,16,32,64,128,256, \ldots \)

e) \(\left( {\begin{array}{*{20}{l}}7\\0\end{array}} \right),\left( {\begin{array}{*{20}{l}}7\\1\end{array}} \right),\left( {\begin{array}{*{20}{l}}7\\2\end{array}} \right), \ldots ,\left( {\begin{array}{*{20}{l}}7\\7\end{array}} \right),0,0,0,0,0, \ldots \)

f) \(2, - 2,2, - 2,2, - 2,2, - 2, \ldots \)

g) \(1,1,0,1,1,1,1,1,1,1, \ldots \)

h) \(0,0,0,1,2,3,4, \ldots \)

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free