Posts

Showing posts with the label Implementing recursive technique

Divide and Conquer an Algorithm design technique

Image
Hey, this is  Shubham Mishra . In our previous post of  Algorithm and its analysis , we have discussed all the algorithm, its designing and many another part. In the same post, In the algorithm designing section, I have mentioned a step that is 'Algorithm Strategy' for selecting a technique to design an algorithm. Out of all the, one very most popular among all is Divide and Conquer. Now, let's start with divide and conquer technique for algorithm designing. In this technique, a problem is, Broken down into smaller sub-problems. The sub-problems are solved independently. Merge all the solutions of all sub-problems to get the solution to the original problem. Basically, If a problem seems too big but if the problem needs repetitive steps then it's better to divide the big problem and solve sub-problems. The sub-problems once solved then combine the solutions of sub-problems to get the result for the original problem. Now let's understand it with the ...

Introduction to Recursion (A way to write an function in Computer Science world)

Image
Hi, I am Shubham Mishra a computer science engineer, passionate about writing technical posts. While writing posts for algorithms such as  Merge Sort  and others, I thought that I should write a post on Recursion, which is a way to write a function where a step is repeated for multiple times. But before reading this I would like you to read my previous post  Data Structure and Types . Now start with the term Recursion. When a function is defined in terms of itself that is it is called even inside its own body then it is called a Recursive function. Don't be confused just scroll down and see below picture for a better understanding. Suppose you want to calculate the factorial of '4'. The factorial is calculated by multiplying the terms itself with all the numbers below to it till one. It is as '4 * 3 * 2 * 1 * 1'. The '1' extra is the Factorial(0) = 1. The factorial function will work as it will return '1' if the factorial is called for zero (...