Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Suppose you need to generate a random permutation of the ?rst integers. For example, {4, 3, 1, 5, 2} and {3, 1, 4, 2, 5} are legal permutations, but {5, 4, 1, 2, 1} is not, because one number (1) is duplicated and another (3) is missing. This routine is often used in simulation of algorithms. We assume the existence 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[0] to a[N-1] as follows: To ?ll a[i], generate random numbers until you get one that is not already in a[0], a[1], ..., a[i-1].

2. Same as algorithm (1), but keep an extra array called the used array. When a random number, ran, is ?rst put in the array a, set used[ran] = true. This means that when ?lling a[i] 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 ?rst algorithm.

3. Fill the array such that a[i] = i+1. Then for( i = 1;i n; ++i )swap( a[ i ], a[ randInt( 0,i)] );

a. Prove that all three algorithms generate only legal permutations and that all permutations are equally likely.

b. Give as accurate (Big-Oh) an analysis as you can of the expected running time of each algorithm.

c. Write (separate) programs to execute each algorithm 10 times, to get a good average. Run program (1) for = 250, 500, 1,000, 2,000; program (2) for = 25,000,  50,000,  100,000,  200,000,  400,000,  800,000;  and  program (3) for = 100,000, 200,000, 400,000, 800,000, 1,600,000, 3,200,000, 6,400,000.

d. Compare your analysis with the actual running times.

e. What is the worst-case running time of each algorithm?

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91642997

Have any Question?


Related Questions in Computer Engineering

Quesiton an important principle in information security is

Quesiton: An important principle in information security is the concept of layers of security, which is often referred to as layered security, or defense in depth. 1) Please explain the concept of layers of security. 2) ...

Question please review the description of the organization

Question: Please review the description of the organization that is the subject of your semester project. The description of that organization, CITY GENERAL HOSPITAL, is described in the instructions for Phase I that you ...

How does understanding various microsoft office

How does understanding various Microsoft Office applications enhance productivity in education, the workplace, and at home?

According to a recent article the average number of babies

According to a recent article the average number of babies born with significant hearing loss (deafness) is approximately four per 1,000 babies in a healthy baby nursery. The number climbs to an average of 30 per 1,000 b ...

Can someone please help me with this examthis is consists

can someone please help me with this exam This is consists of four questions. The questions are designed to test your understanding of certain concepts that were studied over the course of the semester. Please answer all ...

Question suppose you are building a java application for

Question : Suppose you are building a Java application for storing the names and ages of children in a family. Describe the strategy that you would use in order to determine the data types you would need for your applica ...

Suppose that you are given a sorted list of n elements

Suppose that you are given a sorted list of n elements followed by f(n) randomly ordered elements. How would you sort the entire list if a. f(n) = 2? b. f(n) = vn? c. How large can f(n) be for the entire list to be sorte ...

Question suppose we have a b-tree that holds keys and

Question : Suppose we have a B-Tree that holds keys and leaves. There are 100 million data records (N), and they are stored in the leaves (lowest level) of the B-Tree. Each leaf contains 100 data records. The leaves are ...

Question research the 2014 home depot data breach and

Question : Research the 2014 Home Depot data breach and provide insight on what happened and why it occured. Discussion should also provide insight into what the company is doing to recover for the data breach.

Question skyeducation will develop a new branch in the city

Question : SkyEducation will develop a new branch in the city for J2EE programming training. The information is given in the following table. (Ignore the crashing parameters.) Task a b c d e f g Predecessors - - - a b c ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As