473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Rate of Growth Assignment.

Hello everyone!

I have an assignment in my Java class to gauge and compare the "order of growth" of two different sections of code. Below is the actual assignment:

"The following code fragment (adapted from a Java programming book) creates a random permutation of the integers from 0 to N-1. Determine the order of growth of its running time as a function of N. Compare its order of growth with Shuffle.java from Section 1.4."


and here is the code the assignment talks about:

Expand|Select|Wrap|Line Numbers
  1. int[] a = new int[N]; 
  2. boolean[] taken = new boolean[N]; 
  3. int count = 0; 
  4. while (count < N) 
  5.    int r = StdRandom.uniform(N); 
  6.    if (!taken[r]) 
  7.    { 
  8.        a[r] = count; 
  9.        taken[r] = true; 
  10.        count++; 
  11.    } 
My main question is, how do I go about computing the order of growth? and what would that code look like? If you guys could point me in the right direction that would be much appreciated. I'll provide links to some of the other classes if needed:

StdRandom: http://www.cs.princeton.edu/introcs/...StdRandom.java

Shuffle: http://www.cs.princeton.edu/introcs/...t/Shuffle.java

Thanks again!
Apr 30 '09 #1
2 4276
chaarmann
785 Expert 512MB
The order of growth means, informally speaking, how much slower your program becomes if you increase the value of N, compared to your other program.

Just call your program with different values of N. Before calling it, measure the time with System.currentTimeMillis(). After it ends, measure the time the same way again. The difference then tells you how long the program needed for execution.

Then do the same with Shuffle.java and compare growth in time of both programs.
May 1 '09 #2
JosAH
11,448 Expert 8TB
You can also take a bit more analytical approach; for loop pass i (i starting at zero) you have the probability i/n of picking an already taken number, so on average you take p*(i/n)^p == (i/n)/(1-(i/n)) == i/(n-i)+1 turns to complete loop pass i.

Sum that turn over all i in [0,n] and you'll see that if n approaches infinity the sum approaches infinity much faster. Say, for n == 10 you get:

(0/10+1/9+2/8+3/7+4/6+5/5+6/4+7/3+8/2+9/1)+10 turns

The other method only requires n swaps which is equal to the last term of the above sum.

kind regards,

Jos
May 1 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dave Serrano | last post by:
I have a question about altering tables and growth of the database and transaction log. I have a database which is approximately 35GB. I had to make a change to a column in the largest table...
10
by: Generic Usenet Account | last post by:
I have worked out a very simple method for tracking the "memory growth" of a process at run time. It involves a header file and a shell script. Here's the header file: ////////// Header File...
6
by: masri999 | last post by:
Hello, I need to monitor every 15 minutes growth in data file and log file . Since mdf and intial file sizes are set to high value, measuring these values at 15 min interval will not provide the...
14
by: Chung Leong | last post by:
Just noticed this link on the side while reading this group on Google: "PHP Programmers at $10/hr" So sad...
0
by: Thomas F.O'Connell | last post by:
Matthew, Here's some more feedback on our use of pg_autovaccum. It's clear that it's working and that it's helping, but even after increasing our max_fsm_pages substantially (to in excess of...
18
by: junky_fellow | last post by:
Hi all, Is there any way by which we mat determine the direction of stack growth (from higher address to lower address Or from lower address to higher address) ? I know this question is...
2
by: fatimahtaher | last post by:
Hi, I am new to C# programming and my first assignment requires me to calculate total interest paid on a loan. The user will input the loan, the interest rate per month, and the monthly payment....
2
by: katara | last post by:
how can i find out the growth rate of table, oracle 8 os window abhi
6
by: Angel Tsankov | last post by:
Hi, I remember reading in a book (or in an article) that the optmial buffer growth factor is about 1.6. Now I need to find this book but I can't remember its title. Can someone help me with this?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.