Worst-case running time of algorithm

Assignment Help Basic Computer Science
Reference no: EM13968048

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?

Reference no: EM13968048

Questions Cloud

Determining the input size : An algorithm takes 0.5 ms for input size 100. How long will it take for input size 500 if the running time is the following (assume low-order terms are negligible)?
Determine the mesh current i1 : Consider the circuit shown in the figure below. Suppose that R1 = 6Ω , R2 = 13Ω and R3 = 17Ω. Determine the mesh current i1. Express your answer to three significant figures and include the appropriate units.
Depreciation is not recorded because the city has no cost. : Which of the following is true for reporting the gift within the government-wide financial statements?
Change in price when the quantity supplied is increased : Use differentials to approximate the change in price when the quantity supplied is increased from 10000 units to 10500.
Worst-case running time of algorithm : d. Compare your analysis with the actual running times. e. What is the worst-case running time of each algorithm?
How does this compare to other not for profit entities : On the internet and in the news you see many articles on non-profit companies and their contribution rates. For example, let us say that a firm returns 20% of its contributions to research and pays its CEO $700,000 per year.
Resize member function and zero-parameter : For the matrix class, add a resize member function and zero-parameter constructor.
Program to solve the selection problem : 1. Write a program to solve the selection problem. Let k = N/2. Draw a table showing the running time of your program for various values of N.
What role should kpis play in helping management : Strategic controls are an important factor in executing a strategy. Metric and KPI are quantitative measurements. What role should KPIs and other metrics play in helping management in strategic controls?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd