Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,290 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,235 people online right now. Registration is fast and FREE... Join Now!




Pls anyone show me the flow of data of this recursive-algrithm

 
Reply to this topicStart new topic

Pls anyone show me the flow of data of this recursive-algrithm

bazala123
post 15 Feb, 2008 - 11:12 PM
Post #1


New D.I.C Head

*
Joined: 15 Feb, 2008
Posts: 1

N = 5
x = 3
y = 5

Recur(N)
print (x, y)

Recur(N)
{
If (N==1)
return

Recur(N-1)
x = x+1

Recur(N-1)
y = x+y
}

Regarding above algorithm, how do data flow step by step...
Pls anyone show me that.
thx u in advance tongue.gif
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 15 Feb, 2008 - 11:51 PM
Post #2


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


I can show you how to get started:
CODE

call Recur(5)
  call Recur(4) -x
    call Recur(3) -x
      call Recur(2) -x
        call Recur(1) -x
        return
        x=3+1=4
        call Recur(1) -y
        return
        y=4+5=9
     call Recur(2) -y
       call Recur(1) -x
       return
       x=4+1=5
       call Recur(1) -y
       return
       y=5+9=14
     y=5+14=19
   call Recur(3) - y
     call Recur(2) - x
     ...etc...


The best thing to do is to write the program and put a few print statements in it to see whats going on.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 01:14AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month