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.

Recommended Answers

All 5 Replies

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.

So you think that this diagram is correct?

It doesn't matter. The assignment is stupid and a waste of your time.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.