# Recursion

recursion code examples in swift language.

## How to Find all subsequences with sum equals to K

[Question] : In a given array find all possible sequence whose sum is certain number: For example:- [4,8,4] Target Sum = 8 So Output will be [4,4] 

## Multilevel recursion in swift

Here we will discuss two level recursion in swift. If there is statement before the recursive function it will print in sequence & vice versa. Here is example code with print statement –

## How to Generate subarrays using recursion

[Question]: We haveGiven an array, generate all the possible subarrays of the given array using recursion for example :

## How to reverse an array using recursion ?

[Question] : Reverse array using recursion Example: [1,2,3] = [3,2,1]. Approach #1 using two variables : – // Approach#2: Using single pointer/variable so we written base case which blocks on n/2, we are just increasing the element by +1 on every recursion till half of the array.

## How to print n times using recursion

So here we have used recursion The names which is before function will print FIFO & vice versa

## Recursion examples in swift

A function which calls itself in the body & solve the problem is called recursion. we will take some example to understand #1 Print numbers from 1 to N Because Print is before recursion function it will print 1 to n #2 Print numbers from N to 1 #3 Sum of first N numbers #4 …