User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Computer Science and Software Design section within the Software Development category of DaniWeb, a massive community of 422,676 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,680 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Computer Science and Software Design advertiser: Programming Forums
Views: 372 | Replies: 0
Reply
Join Date: Sep 2007
Posts: 12
Reputation: -EquinoX- is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
-EquinoX- -EquinoX- is offline Offline
Newbie Poster

calculating the primitive steps of this loop

  #1  
Feb 12th, 2008
input = integer n, array a[1..n]
output = integer w, arrayb[1..w], array c[1..w]

w = 0
while (true){
    k = 1;
    while (a[k] is equal to nil) do
        k++;
         if k equals n +1 then halt algorithm
    end while
    w++;
    b[w] = a[k];
    c[w] = 1;
    a[k] = nil
    for j = k+1 through n do
         if a[j] and b[w] contain the same value then
               c[w] = c[w] + 1;
               a[j] = nil
         end if
    end for
end while
I am confused on how many times the inner while loop and the outer while loop executes how many times? As far as I can do the inner loop goes n(n+1)/2 times and the outer loop goes n times. is this right?? The way I found this solution is by writing this code into Java and prints out a counter on how many times the inner and outer while loop is executed. Though I am not quite sure if this is the right way, so I would like to make sure if you guys could give me a better tips. Thanks guys for all the comments and help.
Last edited by -EquinoX- : Feb 12th, 2008 at 6:58 pm.
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Computer Science and Software Design Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Computer Science and Software Design Forum

All times are GMT -4. The time now is 4:37 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC