TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Flowgorithm

Recursion in Flowgorithm Flowchart

Flowgorithm

Overview

In this tutorial, we will understand Recursion using Flowgorithm flowchart. In the earlier example using Function, we have noticed that the Main flowchart calls the function. We will design a recursive function called RSum to compute the sum of n natural numbers.

Recursive Function

A recursive function is a function that invokes itself. Recursion occurs when the function defines in the terms of itself. Flowgorithm supports recursion. We will use the Call statement within the function definition to call itself.

Mathematical Notation

The Sum of n natural numbers can be denoted as the following Mathematical notation:

\LARGE Sum = 1 + 2 + 3 + ... + (n-2) + (n-1) + n

 

\LARGE Sum = \sum_{i=1}^{n} i

Alternatively, we can define the sum series as:

\LARGE Sum = n + (n-1) + (n-2) + ... + 3 + 2 + 1

Recursive calls

Let’s design a recursive function to compute the sum of N positive numbers called RSum. We need to define the base case and the recursive case.

Sum of n numbers in recursive format:

Base case: When n= 1 the sum is 1. This is the halting case. We should tell the function to stop the recursive calls.

Recursive case:

RSum = n + RSum(n-1)

This in turn changes in the next recursion:

RSum = n + (n-1) + RSum(n-2)

and so on until we reach the base case.

Example Flowchart

The Main function prompts the user for the number N. The Main function invokes the recursive function with the parameter N. RSum is the recursive function.

Main Flowchart

Recursive Flowchart Flowgorithm

Recursive function: RSum

The recursive function RSum calls itself to compute the sum of N natural numbers.

The function parameter is Integer N. The function returns the sum. We can notice that the function invokes itself.

Recursive Function Call

Sample Output

Execute the Main flowchart and verify the output.

 

Recursive Function Output

If the flowchart input is N the flowchart output of the recursive function should be:

N*(N+1)/2

For example, for input 10 the output should be :

= 10*(10+1)/2

= (10*11)/2

= 55

That’s it. We have successfully created a flowchart with a recursive function using Flowgorithm. The common error in designing the recursive functions is Infinite recursion.

Infinite recursion: Infinite Recursion Example

—

Flowgorithm Tutorials

Flowgorithm flowchart tutorials on this website:

https://www.testingdocs.com/flowgorithm-flowchart-tutorial/

Flowgorithm Website

For more information on the Flowgorithm tool, please visit the official website at:

http://flowgorithm.org/

Related Posts

Print Triangle Pattern Flowchart

Flowgorithm /

Print Triangle Pattern Flowchart

Flowgorithm Breakpoint Symbol

Flowgorithm /

Flowgorithm Conditional Breakpoint Statement

File Read Declare Variables

Flowgorithm /

Flowgorithm Read Numbers from File Example

File Search Input File Flowgorithm

Flowgorithm /

Search Text File Flowchart Example

Flowgorithm Turtle Graphics Symbols

Flowgorithm /

Flowgorithm Turtle Graphics Symbols

‹ Arrays in Flowgorithm Flowchart› Populate String Array with User Input

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version