Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given a sequence x 1 , x 2 , dots, x n of n real numbers between 0 and 1 ( inclusive )

You are given a sequence x1,x2,dots,xn of n real numbers between 0 and 1(inclusive). You want
to reorder the numbers such that the sum of the difference between each pair of adjacent elements
is less than 2. That is, you want to find a permutation y1,y2,dots,yn where
i=1n-1|yi-yi+1|2.
For example, if we have the sequence 0.9,0.2,0.8,0.1,0.3, the sum of differences is
|0.9-0.2|+|0.2-0.8|+|0.8-0.1|+|0.1-0.3|=0.6+0.6+0.7+0.3=2.2>2.
If we rearrange the numbers as 0.2,0.9,0.8,0.1,0.3, the sum is then
|0.2-0.9|+|0.9-0.8|+|0.8-0.1|+|0.1-0.3|=0.7+0.1+0.7+0.2=1.72.
Design an algorithm that finds such an order in O(n) time.
Hint: Split the interval 0,1 into n smaller ranges. The BuCKet-SorT algorithm might provide
inspiration. (Note however that BUCKET-SoRT is not a sorting algorithm!)
Rubric.
In English, describe an algorithm that rearranges the sequence such that the given sum is
less than 2.
Prove that the sequence created by your algorithm satisfies the difference requirement.
Justify that your algorithm runs in O(n) time.
Expected response length: up to one page.
Please do this question i'm so stuck
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

9. How are they similar to you? (specifically)

Answered: 1 week ago

Question

13. What are their tastes? (refined, middle class, or subsistence)

Answered: 1 week ago