0

I have an assingment that sound like this:
Draw a block diagram of recursive function that sums first N even numbers, where N is entered from keybord or in procedure that calling a function.

I have posted the JPG of my solution.
But this is not going to work. This looks like a loop.
I need to put a base case at the right place. I thought that the good base case should be N>0 but somthing is very wrong here :-s

Can someone can help me?

P.S. Sorry if this is in wrong thread.

Attachments rekurzija.jpg 19.5 KB
3
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by sarehu
0

Recursion is just a loop, therefore whether you choose recursion or iteration is a detailed implementation choice.
I'd expect the diagram to look the same in both cases.

0

It's easy for you to say.
My pass on this exam depends to this assignment.

0

It is easy for me to say, since this question of how to format some particular style of block diagrams (whatever they are) will not improve your ability at computer science or programming in any manner whatsoever.

But I understand your situation. It is hard to give you a useful answer, though, since you haven't told us anything about what these "block diagrams" are supposed to look like. Why are there hexagons, rectangles, trapezoids?

The trouble with diagrams like these is in fact the question of how to diagram recursive processes. And it depends on how your recursive process is defined. Suppose (for the sake of an example) it is defined like this:

function evenSum(n) {
    if (n == 0) {
        return 0
    }
    else {
        return 2 * n + evenSum(n - 1)
    }
}

That implementation is certainly going to use the stack. The question is, how will your block diagram represent this situation? You could show the chain of recursive calls with an ellipsis to show that arbitrarily many can happen, depending on the value of n. Does your block diagram syntax support using an ellipsis? If not it seems like it wouldn't be fully describing the process.

You can't get any useful help unless you go into details about how your block diagram syntax works.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.