Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Lecture 9: A simple recursive function - Richard Buckland UNSW

Loading...

Sign in or sign up now!
22,337
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Apr 9, 2008

We sum the numbers 0..n using gauss, the formula for an arithmetic progression, and finally using a simple recursive program. Apparently summing the numbers 0..n is important in computer science. Along the way we continue our discussion of style and craftsmanship, chainsaws, floats, doubles, longs, side effects. Skating.

Richard explains that this is not a C course. It is a computing course which happens to use C. C is our tool it is not our objective.

Category:

Education

Tags:

License:

Standard YouTube License

  • likes, 2 dislikes

Link to this comment:

Share to:

Top Comments

  • Actually this is not recursion. Your example is just repeatedly calling a function.

    Recursion is when a function calls itself. But the self-call needs to modify the n value. Eg n-1 or n+1, so each subsequent call modifies the n value and moves closer to the final output. Otherwise there would be an endless loop.

    If you look at 29:43 you will see the function calls itself with but with (n -1).

  • His shirt, "Microsoft security". Ha.

see all

All Comments (30)

Sign In or Sign Up now to post a comment!
  • Waste of time.

  • @nateaus In other words, they shouldn't have called the movie inception, they should have called it recursion.

  • @Izooify he is not personally seeing the comments now is he

  • I'll follow every lecture he says.

  • Hello Sir; I've beening following ur Lectures on YouTube But I've Gotten  Stuck Here on this lecture 9 my compiler is returning an error message : 'SUM' is asigned a value which is never used ? Please help me here my compiler is not recognizing 'n'

  • As a tack on to my prior statement (I ran out of room). This appears very similar to recursion because in fact it is. If it helps try imagine little Russian dolls in succession and if that helps here is a quote from "Back to the Future":

    "you're not thinking fourth dimensionally"

    Love Victor Cross

  • Dear nateaus.

    This appears very similar to recursion as the function is calling it's self. All though it is true that the function is passing n-1 into its self on the in function call in the new call that is treated the same way as n would be and that is where the increment is happening. The part that allows it not to run infinitely is the if statement at the top of the function searching for when n is o at which point it returns 0 and then terminates the original call and all subsequent calls.

  • @nateaus

    Interesting. I thought recursion when a method calls itself regardless of any counting mechanism.

  • @intindse Microsoft doesn't too.

Loading...

0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more