Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java. Rank the three algorithms in terms of expected running time (for large n) and give an explanation to justify your ranking. Thank you! Suppose

Java. Rank the three algorithms in terms of expected running time (for large n) and give an explanation to justify your ranking. Thank you!

image text in transcribed

Suppose you need to generate a random permutation of the first N integers For example, 14, 3, 1, 52) and {3, 1, 4, 2, 5} are legal permutations, but [5, 4, 1, 2, 1 is not, because one number () is duplicated and another (3) is missing. This routine is often used in simulation of algorithms. We assume the exis- tence of a random number generator, r, with method randInt (i, j), that generates integers between i and j with equal probability. Here are three algorithms 1. Fill the array a from a[O] to a[n-1 as follows: To fill ai], generate random numbers until you get one that is not already in a [0], a[i],... , ali-1] 2. Same as algorithm (1), but keep an extra array called the used array. When a random number, ran, is first put in the array a, set used [ran] - true. This means that when filling ali] with a random number, you can test in one step to see whether the random number has been used, instead of the (possibly) i steps in the first algorithm. 3. Fill the array such that a[i] = i + 1 . Then for( i = 1; i

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

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions