- Name: Zuhra Olimjonova
- Topic: Recursion
This repository contains my homework on topic Recursion, written in Java language.
Recursion is a way of coding which method calls itself. It also can be described as climbing a staircase as you will go up on it until you reach the top one(the stopping condition) or you will go down on it until you reach the last one(the stopping condition). The recursive function must contain two parts: a base case and a recursive case. If there is no base case it leads the function to continue calling itself and run infinitely: causing stack overflow.
Recursion is mostly used for tree problems(I learned this from a Discrete Mathematics class which I took at the University) , and some mathematical problems like fibonacci numbers, factorial and others. In some cases recursion is way much easier; example: factorials 5!=5 x 4! ; 4!=4 x 3! ; ….(goes like this until it reaches 1! and returns 1 (1!=1), in other words the stopping condition).
However, using recursion every time is also incorrect. Simple calculations, swapping values, or others can also be found in easy and productive ways. It also runs in much less time and will reduce the storage amount.
Personal opinion: I personally do not use it in my programs yet, but believe that learning recursive will widen my coding knowledge and help me understand more advanced topics in programming later on.
In conclusion, recursion is an essential part of programming. It helps to solve the difficulties of the hard problems and makes it readable. However using it by knowing how naturally we need it makes a huge difference. Also when applying recursion, we must always include base case(condition) and recursive case to make it correct.
Zuhra Olimjonova