Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Computational fairy tale what makes this recursive add bad?

Status
Not open for further replies.

wtr

Full Member level 5
Joined
May 1, 2014
Messages
299
Helped
29
Reputation
58
Reaction score
25
Trophy points
1,308
Activity points
4,108
There is this book that I’ve been reading for a bit of fun.

Computational Fairy Tales by Jeremy Kubica.

Within this book there is a section called computational Graffiti.

The following snippet

Code C - [expand]
1
2
3
4
Int RecursiveAdd (int n, int m) {
  If (m == 0) return n;
  Return RecursiveAdd(n, m-1) +1;
}


The book makes jest at the inefficiencies of it all.

I haven’t got the means to compute this atm, I want to know why this is BAD.
I can see the function gets called m+1 times.

Doesn’t the recursive add work exactly the same way as for (i==1; i<m; i++) ?

Is it inefficient because i cpu could just use sum and carry register on a multi bit word and therefore do this all in one clock cycle? with opcode +

Regards,
Wes
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top