Skip to content

Instantly share code, notes, and snippets.

@tushar-rishav
Last active September 5, 2015 17:09
Show Gist options
  • Save tushar-rishav/cc5f361018ffc48baf8b to your computer and use it in GitHub Desktop.
Save tushar-rishav/cc5f361018ffc48baf8b to your computer and use it in GitHub Desktop.
Delta Algo SIG

Delta's Special Interest Group for Algorithms

Session-I

Conceptual Question:
  1. Which of the below code snippets can give stackoverflow for very large value of 'n' ( Do not consider Python while answering this question ) : I)

        function foo(n){
          if(n > 0)
            return foo(n - 1);
        }

    II)

        function x(n){
          if(!n)
            return 0;
          n-=2;
          return x(n) + 1;
        }

    Options: A. I only B. II only C. Both I and II D. None.

  2. How a recursive function with no base case and an infinite iteration differ?

      function sum(long long n){  // recursive part with no base case
        return 1+sum(n+1);
      }
      n = 0;
      for(;;){                // iterative part with infinite iteration
        n+=1;
      }

    Analyse what will happen when the two snippets will be executed

Informative Questions:
  1. How a tail recursion optimisation can help in handling the maximum recursion depth?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment