Question

In: Computer Science

Explain the benefits a recursive algorithm can provide. Discuss the negative aspects of using recursion.

Explain the benefits a recursive algorithm can provide.
Discuss the negative aspects of using recursion.

Solutions

Expert Solution

Following are the benefits of recursive algorithm.   

  • Recursion means calling the same function again from within the function. Therefore the function requires lesser number of variables and thus the code will be short.
  • Recursion is very simple and easy to understand.
  • Unnecessary function calls can be avoided using recursive functions.
  • A substitute for iterative solutions which are big and more complex.
  • Recursion is a very good choice when the input to the function is small.
  • Recursion helps in reducing time complexity.
  • A useful way of defining objects which have similar structure.
  • Nested loops can be avoided since the function calls itself.

Following are the negative aspects of using recursion.

  • There is a great great chance that the recursive function will keep on calling itself, unless you don't know where exactly to provide the return statement.
  • The memory allocation is much greater than that of iteration functions.
  • Not advisable to use recursive functions for small programs running on pc's, since recursion takes a lot of stack space.
  • The logical aspect of recursive functions are difficult to understand and debugging is also difficult.
  • These functions appears confusing for beginners.
  • Recursive functions can slower than iteration if not implemented properly.
  • There is chance of program crashing if the program runs out of memory.

Hope i have answered your question.

Regards


Related Solutions

Explain the measures that a country can take to protect itself from the negative aspects of...
Explain the measures that a country can take to protect itself from the negative aspects of free trade.
Java Programm please! Design and implement an algorithm using recursion and backtracking to sort an array...
Java Programm please! Design and implement an algorithm using recursion and backtracking to sort an array of integers into ascending order. Consider the given array as input and produce a sorted array as output. Each time you take an integer from the input array, place it at the end of the output array. If the result is unsorted, backtrack.
Ackermann’s function is a recursive mathematical algorithm that can be used to test how well a...
Ackermann’s function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Write a method ackermann(m, n), which solves Ackermann’s function. Use the following logic in your method: If m = 0, then return n + 1 If n = 0, then return ackermann(m-1, 1) Otherwise, return ackermann(m -1, ackermann(m, n - 1)) Test your method in a java program that displays the return values of the following method calls: ackermann(0, 0), ackermann(0,...
Explain the positive and negative aspects of using alternative time horizons when evaluating a firm's performance.
Explain the positive and negative aspects of using alternative time horizons when evaluating a firm's performance.
C++ Ackermann’s function is a recursive mathematical algorithm that can be used to test how well...
C++ Ackermann’s function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Write a function A(m, n) that solves Ackermann’s function. Use the following logic in your function: If m = 0 then      return n + 1 If n = 0 then       return A(m−1, 1) Otherwise,          return A(m–1, A(m, n–1)) Test your function in a driver program that displays the following values: A(0, 0)   A(0, 1)   A(1, 1)    A(1,...
what we have learned about the plusses and minuses (benefits and costs) of using recursion as...
what we have learned about the plusses and minuses (benefits and costs) of using recursion as a problem-solving technique for the types of programs you have encountered so far.
Provide three positive and three negative aspects of retaining an outside consultant for a project.
Provide three positive and three negative aspects of retaining an outside consultant for a project.
explain what an encryption algorithm is and what it can do to provide increased computer security...
explain what an encryption algorithm is and what it can do to provide increased computer security ?
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude <iostream>)
Recall the Matrix-Multiplication Algorithm for determining all-pairs distances in a graph. Provide a linear-time recursive implementation...
Recall the Matrix-Multiplication Algorithm for determining all-pairs distances in a graph. Provide a linear-time recursive implementation of the function void print_path(Matrix D[], int n, int i, int j); that takes as input the array of matrices D[1], D[2], . . . , D[n − 1] that have been computed by the algorithm, and prints the optimal path from vertex i to vertex j. Hint: for convenience you may use the notation Dr ij to denote the value D[r][i, j], i.e....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT