wtf is recursion?

how can I understand recursion?
I thought that I understand recursion in C ....but not in Javascript
Which book or video should I see or read to understand this recursion mess??

UFOs Are A Psyop Shirt $21.68

DMT Has Friends For Me Shirt $21.68

UFOs Are A Psyop Shirt $21.68

  1. 2 years ago
    Anonymous

    My first thought was to tell you to have a nice day. I am trying to stop being nasty and bothered by it but it's so painful to see the only Internet community where I manage to get enjoyment out of posting to get shitposts like this that will get 200 replies.

    • 2 years ago
      Anonymous

      Lol, I feel you. At least your post made me smile so the thread wasn't a complete waste.

    • 2 years ago
      Anonymous

      >get 200 replies
      why?

      • 2 years ago
        Anonymous

        Because it gives an opportunity for morons who took their first programming class 1 week ago to argue and feel smug by explaining recursion.
        AND it has a provocative image.
        If you know how IQfy works you know this is a recipe for a thread with a lot of replies. Not 300 because only current events and generals get that many replies before people get bored of it.

    • 2 years ago
      Anonymous

      There's a hide button. Besides, this is hardly the worst post.

  2. 2 years ago
    Anonymous

    It's a function that, in it's definition, calls itself until it checks if it's done and exits, usually they're stupid math dickwaving but they make sense for some kinds of problems, usually traversing directory structures, tree data structures, anything that looks like a branching tree.

    • 2 years ago
      Anonymous

      make it sound sound, but with code it becomes very confusing

      My first thought was to tell you to have a nice day. I am trying to stop being nasty and bothered by it but it's so painful to see the only Internet community where I manage to get enjoyment out of posting to get shitposts like this that will get 200 replies.

      suicide is kinda a recursion thing ?

    • 2 years ago
      Anonymous

      No they never make sense. All recursive functions crash.

  3. 2 years ago
    Anonymous

    how can I understand recursion?
    I thought that I understand recursion in C ....but not in Javascript
    Which book or video should I see or read to understand this recursion mess??

    • 2 years ago
      Anonymous

      i hate these new languages, all looks so messy...specially this zommer thing called javascript...it makes me angry, i wanna beat the shit out of my wife everytime i have to remember all this weird syntax...in my times, we use C, it was clean and smooth, it was perfect

      • 2 years ago
        Anonymous

        > C, it was clean and smooth, it was perfect
        really clean and smooth frick you are delusional c code is fricking giberish.If its so clean and smooth go teach a newbie c in 2 days .Guess what you cant.Lisp is clean and smooth c syintax is horrible.

    • 2 years ago
      Anonymous

      All that you need to know about recursion is that it will always crash your computer. Never do it, and force every single person who does do it to make a proper algorithm with a while or for function.

      • 2 years ago
        Anonymous

        tco

  4. 2 years ago
    Anonymous

    If you understand recursion in one language, you understand it in all of them. All it is, is a function calling itself. This causes it to repeat every part of the function that comes before the recursive call, as if you had constructed a while loop. Ideally, you would use something like an if statement to make the recursive call not be executed every time, so you could eventually terminate the loop. Also, you should probably want to minimize the number of times you recurse, otherwise you'll end up overflowing the stack (unless your language in question can perform an optimization to the contrary, like tail call optimization), but fundamentally it's just another way to do looping.

    • 2 years ago
      Anonymous

      wait...stack ..overflow ..is not a website?

      • 2 years ago
        Anonymous

        What behavior do you think the website was named after?

        recursion may not be a loop in the sense that it is not a factorial, because recursion is multidimentional, and factorials are not multidimentional?

        Please refrain from taking drugs right before posting on IQfy.

    • 2 years ago
      Anonymous

      recursion may not be a loop in the sense that it is not a factorial, because recursion is multidimentional, and factorials are not multidimentional?

  5. 2 years ago
    Anonymous
    • 2 years ago
      Anonymous

      thnks ..this is awesome

  6. 2 years ago
    Anonymous

    u have to turn off your brain and assume the recursive call works

    • 2 years ago
      Anonymous

      Ah, yes, the "leap of faith" technique.

  7. 2 years ago
    Anonymous

    100% OP please read SICP, the first and second chapter really touch on the difference between recursion and iteration. There's also conveniently a JavaScript version of the book.

    • 2 years ago
      Anonymous

      Javascript version of SICP? Do tell more.

    • 2 years ago
      Anonymous

      /thread

  8. 2 years ago
    Anonymous

    Recursion has (kind of) nothing to do with the language you use. The key to it is that you're doing the same thing over and over, usually with a number that gets smaller until you hit a base case. Take factorials:
    4! = 4 * 3!
    3! = 3 * 2!
    2! = 2 * 1!
    1! = 1 <- base case

    If you wanted to implement this in python, it would look something like
    def fac(n: int) -> int:
    return (1 if n == 1 else n * fac(n - 1))

    So when you run fac(5), the function calls fac(4) and so on. One weakness is that if you input a negative number, the base case will never be reached, and you'll be stuck in an infinite loop.p

    • 2 years ago
      Anonymous

      >One weakness is that if you input a negative number, the base case will never be reached, and you'll be stuck in an infinite loop
      Because you wrote your base case poorly. Actually, not only are you going to get an infinite loop on negative numbers, but on 0 as well. And yet 0! is well defined to be 1.

  9. 2 years ago
    Anonymous

    it's like a proof by induction but backwards

  10. 2 years ago
    Anonymous

    Put your entire method in a loop that counts down, the stop condition is that it hits the lowest index or otherwise can't continue. That's 90% of recursion algorithms

  11. 2 years ago
    Anonymous

    recursion is a subsect of loops, where loops are ran until a condition is met, recursion is ran until all elements have been touched. a "for x in y" loop may seem like recursion, but this loop can be programmatically stopped with a "break" statement which immediately returns False to the loop. recursion doesn't care about conditionals like that. the classic "rm -rf" uses "r" to indicate recursion, and this makes the remove command run against every element available (every file in the directory).

    • 2 years ago
      Anonymous

      break does not return false to a loop.
      It initiates an unconditional jump to the outside part of the loop.

    • 2 years ago
      Anonymous

      >recursion is a subsect of loops
      no it isn't
      recursion is actually more powerful than loops, there is no simple way to express many simple recursion schemes in terms of loops
      >where loops are ran until a condition is met, recursion is ran until all elements have been touched
      not the case. you can exit out of recursion any point you want. you don't have to recurse over some elements of a collection either.
      hylo :: (a -> b -> (b,a)) -> (a -> Bool) -> a -> b -> b
      hylo f stop x acc = if stop x then acc else let (acc',x') = f x acc in hylo f stop x' acc'

      is one way of encoding a hylomorphism, there is a function called stop (often integrated into the generating function f by replacing its type with a -> b -> Maybe (b,a)) which we literally check the iteration variables x and acc and stop recursing returning acc if that condition holds.

  12. 2 years ago
    Anonymous

    A method that calls itself.
    Everytime the method calls itself, the previous instance of itself has not yet been completed.
    So all recursive methods can use infinite amounts of data and crash your computer, making them pure trash.

  13. 2 years ago
    Anonymous

    [...]

    Why yes, i'm a ASM GOD from 1996, how could you tell?

  14. 2 years ago
    Anonymous

    >wtf is recursion?
    The great filter.

  15. 2 years ago
    Anonymous

    Worse than for loops and that should be enough to tell you to stay away.

  16. 2 years ago
    Anonymous

    Incoming recursion from Hell:
    let insert cmp l x =
    let rec loop rl = function
    | [] -> List.rev_append rl [x]
    | y :: ys ->
    if cmp x y <= 0 then
    List.rev_append rl (x :: y :: ys)
    else
    loop (y :: rl) ys in
    loop [] l
    ;;

    let mk_rand_list len =
    let rec loop l = function
    | 0 -> l
    | n -> loop (Random.int 100 :: l) (pred n) in
    loop [] len
    ;;

    let sort_by_insertion cmp l =
    let insert = insert cmp in
    List.fold_left insert [] l
    ;;

    let print_list pp oc l =
    Printf.fprintf
    oc "[%t]"
    (fun oc ->
    match l with
    | [] -> ()
    | x :: xs ->
    Printf.fprintf
    oc "%a%t" pp x
    (fun oc ->
    List.iter (fun x -> Printf.fprintf oc ",%a" pp x) xs))
    ;;

    let print_int oc = Printf.fprintf oc "%d";;

    let dump = Printf.fprintf stdout "%an" (print_list print_int);;

    let main () =
    let l = mk_rand_list 20 in
    dump l;
    let l = sort_by_insertion ( - ) l in
    dump l;
    flush stdout
    ;;

    let () = main ();;

  17. 2 years ago
    Anonymous

    https://haskell.mooc.fi/

  18. 2 years ago
    Anonymous

    OP, the pic is misleading you, that's more of an infinite loop

  19. 2 years ago
    Understands Recursion

    >to understand recursion, you musts...

  20. 2 years ago
    Anonymous

    dont bother, problably just learn in for stupid leetcode shit at job interviews, literally 0 use on real world.

    i remember doing complex deep recursions that loops through 5 tables before and i have never used it in real production applications

  21. 2 years ago
    Anonymous

    Step 1: understand recursion is a terrible idea

  22. 2 years ago
    Anonymous

    What do you mean you dont understand recursion? Its just a function that ends up calling itself, directly or indirectly.

  23. 2 years ago
    Anonymous

    something that nerds use cause they're too good to use while loops like a normal person

  24. 2 years ago
    Anonymous

    i know recursion but cant implement one in frontend

  25. 2 years ago
    Anonymous

    >how can I understand recursion?
    Use a stack like structure and trace it through you fricking spastic.

  26. 2 years ago
    Anonymous

    [...]

    If you're not even using the outcomes of a previous iteration for the next one, then plain loops have shit to do with recursion.

Your email address will not be published. Required fields are marked *