Added: 10 months ago
From: thenewboston
Views: 18,703
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (129)

Sign In or Sign Up now to post a comment!
  • if(factorialUnderstanding == 0){cout << "FML" << endl;}

  • I learned how to do this in my brain before I knew what it was... sweet brag.

  • look at the call stack debug window and step through the code. that will help you see how the compiler interprets this code.

  • i try and explain this to you:

    factorial(5) returns 5*factorial(4)

    factorial(4) returns 4*factorial(3)

    factorial(3) returns 3*factorial(2)

    factorial(2) returns 2*factorial(1)

    factorial(1) returns 1

    and then it goes backwards to top like this 1*2*3*4*5 = 120 :) hope you understood this guys .

    p.s. thumbs up for Bucky :D

  • inception++?

  • INCEPTION: C++ Edition.

  • What is this program name? Is it Dev C++?

  • @theubunny if you look at the first video of this tutorial series, you'll see this is Code::Blocks

  • @theubunny codeblocks

  • factorialFinder(0);

  • Lets write it in other way:

    int fact(int x){ return (x<=1?1:x*fact(x-1));

    }

  • hi there sir bucky, i'm a computer science student from the Philippines and I thank you for making these tutorials. ^_^

  • bucky, if i graduate i'm sending you my first salary. you sir, rule :)

  • @johnthesman

    factorialFinder(5){a}

    {a}return x*factorialFinder(4){b};

    {b}return x*factorialFinder(3){c};

    {c}return x*factorialFinder(2){d};

    {d}return x*factorialFinder(1);

    {d} returns 1, which puts 1 into {c} where x is 2 and so returns 2, which can now put this into {b} where x is 3 and returns 6, which can now be put into {a} where x is 4 which returns 24, which can now return to the original factorialFinder and finally multiply the original 5 by 24, returning 120. Hope that makes sense.

  • I don't get this. Where is factorialFinder getting the final answer from? I can see that its multiplying 5 by 4 becuase of (x-1). BUT how does it know to multiply 20 by 3 and then 60 by 2? How is it storing the answer from before and multiplying it by the new one?

  • No, this couldn't be possible. I've understood recursion in 3 minutes, while was not able to in a semester...No, really, you are a PRO.

  • Your tutorials are great, crystal clear, keep the good work.

  • Oh my god... what the fuck, barbecue?

  • yeah... can't i just use a for loop and times the integer by a decrementing value?

  • @artashes999 There are certain algorithms that takes you 3 lines of code using recursion and 200 lines of code using iteration. You'll meet them someday and you'll thank Bucky for this tutorial.

  • FACT : No math skills , ==> No C++ Skills .

    the First Programming language that you should start with is Mathematics .

  • a function within a function,

    FUNCEPTION

  • Thanks!!

  • Thought about it for 5 minutes then got it.

  • Wouldn't this be way easier just using a for loop?

  • @ryangr0 Yes, this exact case would be easier using a loop.There are things tho that cant be made with regular loops.Say the user has to enter a number x and a number n and the program has to compute x^n (x*x*x n times).If you tried to do it with a loop like

    for (int i=1; i<=n;i++) {

    x=x*x } .Lets say x is 3 and n is 2.

    1 is less than 2, so now x=3*3 (9)

    2 is equal to 2, so now x(which is 9)=x*x, where both of them are 9 and you get 81 as a result.This can be done with recursion though.

  • @ryangr0 ye but not half as sexy

  • wtf did i just watch?

  • @t4nk0rn0t Apparently a programming tutorial? Didn't you even see the title? :P

  • Is there a reason why you would use this and not a While or For loop?

  • 1st watch = wait what

    2nd watch = nope

    3 watch = FUUUUUUUUUUUUUUU

  • i hate recursionnn!

  • Is it wrong that I'm 12?

  • brain... explosion..

  • BUCKY PLEASE TEACH ME MATLAB! IT STINKS! thank you..

  • Comment removed

  • oh my god. w. t. f. barbecue.

  • Linux doesn't crash... it goes and then says 'Segmentation Fault' No ending process or nothing... Linux > Windows alll day!

  • Comment removed

  • run bucky, run!

  • OMG! thats how they made The Matrix XD

  • Its a waving flag!! :D

  • Well explained! Could u please show how to program the divide-and-conquer algorithm on a game plan. It also uses recursion!

  • I watch this video for no-reason. I don't wanna learn C++; I wanna learn C. But anyways thank you for all your tutorials! Keep up great work!

  • OMGWTFBBQTACOSAUCEWALL

    lol

  • Yup I'm confused. I thought I understood this but I guess not. In this function, first of all it has two return statements. So when we hit the return x*factorialFinder(x-1) statement, isn't that going to send a value back to the function call statement? And let's say it doesn't, because it clearly isn't doing that. It runs through the function 5 times (for a call of 5) and then it gets down to x == 1 being true so it returns 1. Why isn't this just sending 1 back to the function call statement?

  • @ResidentBiscuit

    I have the exact same question...

  • @x34chaa Me too. And I'll add to that the question: Where is the result stored between the recursions? Clearly "x" cannot store it.

  • is there a way to count how much time it ran the function before it crashed? lol

  • For an explaination of recurrsion see the bottom of this comment...

    For an explaination of recurrison see the top of this comment...

  • @mgstanger Haha :P

    very clever

  • What IDE is he using?

  • @Mewigi CodeBlocks

  • i love recursion but they are realy hard to debug ^_^

  • Watermelon Hahaha!

  • now try to explain recursive maze solving algorithm. Damn yea.

  • if i want to calculate factorials of numbers from 1 to 16 everything is alright

    but if i go higher, it gets buggy

    it shows me negative numbers or just 0

    how can i fix that?

  • @JakobRobert00 Try using double instead of int, if you want bigger numbers. Full output of double you will get using this line in main function:

    cout << fixed << fact(170);

    Full function:

    double fact (int x) { if (x == 1) return 1; else return x*fact(x-1);

    }

    In the other hand, with double you won't be able to find factorials of numbers bigger than 170, because you would get 'inf' text. :)

  • This is easy.I want to learn game programming

  • @Chriscs7

    then you should learn something like allegro, dark gdk, opengl or directx

  • @linkinl1 Thanks :)

  • @Chriscs7 lol. The reason why it's easy is because of bucky's explanation. Some teachers actually teach the wrong way and start with odd examples like fibonacci sequence etc.

  • @willzurmacht Actually I knew this before xD,but bucky explains this good also.

  • Couldn't you just use a for loop with a negative step?

  • @TyrianSword

    for ( int x = 5; x > 1 ; x-- )

  • @TyrianSword In the case of looping backwards through a string, but there are times when that does the same thing as a positive increment case loop.

  • A method within a method.

    RECURSION

    Three years of Computer Science, learning Java, and I still don't fully grasp recursion. (And I still completely hate it)

  • @SchizoFilms Basically, I think (don't kill me if I'm wrong >_<) recursion means that the fuction will keep on running and running until your computer's memory is used up, and then it will result to a "Segmentation Fault".

  • @spidey678 Recursion means, that within a method/function, you call the same method/function (or one that calls the first one) to accomplish a backwards loop. If done right, it'll do anything you could do with a While or For loop, but backwards. If done wrong, it'll do anything you could do with a While(true) loop.

    But since it calls itself within itself, I made the inception joke.

  • @SchizoFilms you're not alone! You don't need to use recursive functions, as other programmers say, it's memory hog and nightmare to debug. So avoid using it  ;P

  • @willzurmacht Of course I'm not alone. Everyone hates recursion. But, for some reason, every programming curriculum ever covers it.

  • what if you pass in -1??

  • @Randude14 Program will crash

    

  • That was the most fun I've had doing a Bucky tutorial! I set mine up to say "5*4*3*2*1 aka 5! = 120". And had the same format work for whatever number I put! Microsoft here I come.... after several years of more learning.

  • Remember LIFO (last-in, first-out) and you'll understand recursion.

  • bucky i ♥ u :)

  • Oh NVM, ignore my last comment.

    Factorial is pretty easy, i've never done it before, but is just simple multiplication :)

    I get this now, thanks :D

  • This is the first tutorial of yours that I don't really get so far :(

    Does anyone know of any other tutorials that explain Recursion (ppossibly without confusing math) ?

  • WHATS GOING ON GUYS

    robot or automatic repeat at beginning of your tuts:P?

  • someone didn't understand it. LOLThat thing looked awesome!

  • i semi-understand this... wtf

  • MY BRAIN IS MELTING........

  • OMG WTF BBQ

    

  • please CONTINUE the tutorials !!!

  • Most computer science students like recursion.. idk what bucky is talking about.

  • @xFayte Well with regard to coding most dont as it reduces the efficiency of your program, depending on the size of your program.

  • @cm999 It's not really the size of the program that determines when it's a good idea to use recursion. Recursion can actually improve the efficiency of your program and the time it takes to write that program if used in the proper circumstances. That is to say, there are certain algorithms that can be improved by using recursion, and there are certain algorithms that will not be improved.

  • r u ever going to continue this c++ series ?????

  • @rgrainger09 he only posted this yesterday???

  • @jony1710 i know but he coverd all this 2 years ago...

  • So could you use recursion in the main function? Call the main function again?

  • i dunno, recursion sounds kinda awesome, its tricky

  • Wouldn't an iterative solution be faster?

  • Where could I download tis c++ he is using? 

  • @tibiaowned1 Google "code::blocks". It's an IDE and it also comes with a compiler.

  • @Turbolord he isn't using code::blocks ...

  • @tibiaowned1 yes he is

  • @tibiaowned1

    Do you mean the IDE?

  • @DeadSteal codeblcok found it thx anyway

  • @DeadSteal idk i mean everything so i could start programming like him :D

  • All recursive functions can be written as an iterative function so you never HAVE to write recursive functions but it sometimes makes the code much more easy to write and read. The factorial function can easily be written using a loop. If you want to count the words in all files inside some directory it is very intuitive to use a recursive algorithm.

  • is this tuts going to tackle gui's???

    

  • is there a benefit to that against having a while loop do the factorial?

  • I don't see why can't you just use a while/for/ statment.

  • I love recursion.

    I use it whenever I wouldn't need an incrimenter.

  • @freako9595 User interfaces are very hard to create. You typically have to pick a language, an SDK, a UI Kit, and then design from there. They're usually not very cross-platform and those that are tend to suck.

    That's why Bucky is presenting all these basic concepts using the built-in console. And every operating system will have a (very) different console, with very different features and presentation.

  • oddly enough i loved recursion back in school, found it easy but tricky at first

  • @freako9595 That requires much more code. Complicated if your a beginner.

  • 1:23 Soooo funny! :D

  • I think we need to go deeper

  • Compilers can compile themselves.

  • So you are going to do assembly programing tutorials after this, right!?!?!??!??!? :P

  • I love recursions!!! They make things so much easier!

  • zomg, i'm studying computer science for 2 years now... and this still confuses me oO

    But this is SOO well explained!

    This is the perfect way to make a sudoku-solver!

  • newBoston, have you watched my video that i pmmed you..it is in mychannel

  • ok i didnt get that at all!

  • it's like a dream within a dream.

    and the base case is "kick" otherwise ur program is in limbo state until you kill it.

  • @toughlightyear wtf are u smoking

  • @Streetdisciple27 It's a movie reference.

  • @toughlightyear INCEPTION! MUAHAHAHAH!

  • @toughlightyear yeah my teacher said that movie reminded her of recursion

  • What!?!?!?!

  • thats cool

  • Im going to be doing Comp Sci next year and i find recursion very fun.

  • Thank you Bucky.

  • first comment 83

Loading...
Alert icon
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