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

Question: Devise a Monte Carlo algorithm that determines whether a permutation of the integers 1 through n has already been sorted (that is, it is in increasing order), or instead, is a random permutation. A step of the algorithm should answer “true” if it determines the list is not sorted and “unknown” otherwise. After k steps, the algorithm decides that the integers are sorted if the answer is “unknown” in each step. Show that as the number of steps increases, the probability that the algorithm produces an incorrect answer is extremely small. [Hint: For each step, test whether certain elements are in the correct order. Make sure these tests are independent.]

Short Answer

Expert verified

Answer

The Monte Carlo algorithm is:

Procedure MonteCarloNotIncreasing

a1a2...an:(permutation of the integers through nand n1,

k: positive integer with kn)

fori:=1to.

If aiithen return true

return unknown

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

Given information  

A permutation of the integers1through nhas already been sorted (that is, it is in increasing order),or instead it is a random permutation

02

Definition and formulas

We call the algorithm “MonteCarloNotIncreasing” and the input is a permutationof the integersthrough and a positive integerk(kn).

03

Designing the Algorithm

The Monte Carlo algorithm is:

(a1a2...an:permutation of the integers throughnand n1,k: positive integer withkn)

In each step of the algorithm, we will check whether the consecutive elements of the permutations are in the correct increasing order (with a1=1, a2=2,...an=n).

If we get any element that is not in the correct position, then we return the value “true”

And the algorithm always stops after ksteps.

fori:=1ton.

Ifaiithen return true

If we don’t get any element in the incorrect position, then we return “unknown”.

return unknown

Combining all these steps, we obtain the algorithm:

Procedure MonteCarloNotIncreasing

(a1a2...an:permutation of the integers through and n1,

: positive integer withkn)

fori:=1to.

If aiithen return true

return unknown

One App. One Place for Learning.

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

Get started for free

Study anywhere. Anytime. Across all devices.

Sign-up for free