100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

Recursion in Data Structure

Rating
-
Sold
-
Pages
10
Uploaded on
28-01-2023
Written in
2022/2023

These notes are informative on the topic of recursion in data structures. They will be beneficial for students studying computer science and information technology.

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
January 28, 2023
Number of pages
10
Written in
2022/2023
Type
Class notes
Professor(s)
Lecturer arnold
Contains
All classes

Subjects

Content preview

P a g e |1




Recursion & Data Structures

Man is always seeking solutions to problems and is always also looking
for better solutions.
In computer science, there are different class of problems each requiring
different to problems solving techniques.
We have seen how we can use loops to solve some problems quite well.
Another approach to problem solutions is Recursion.


Recursion is a problem-solving technique that involves breaking a problem into
smaller instances of the same problem (also called subproblems) until we get
a small enough subproblem having a trivial solution.
We can say that recursion is “defining a problem in terms of itself” as it involves
a function calling itself with a base case to terminate the infinite loop.
Technically, recursion is a problem-solving technique where the ultimate
solution depends on solutions to smaller instances of the same problem.
The concept relys on the fact that a problem can be solved much easily and
in lesser time if it is represented in one or smaller versions.
Consider the mathematical expression y=x7
This can linearly be expressed as follows:
6
y=x.x
5
y=x.x.x .
4
y=X.x.x.x
3
y=X.X.x.x.x
2
y=X.X.X.x.x.x
1
y=X.X.X.X.x.x.x



Recursion in data structure

, P a g e |2




0
y=X.X.X.X.X.x.x.x

y=X.X.X.X.X.x.x.1

Iterative solution
Consider y=27 . Therefore X=2; the last term is Y0=1;

Let y=1;
for (int i=1;i<=7;i++){
y*=2;
}


Write the above in a method power (int x, int y)


Using Recursion to solve the above Power Problem
Recursive functions allow programmers to write efficient programs using a
minimal amount of code.
The downside is that they can cause infinite loops and other unexpected
results if not written properly.
For example, in the example above, the function is terminated if the number is 0 .

If proper cases are not included in a recursive function to stop the execution,
it will repeat forever, causing the program to crash or become unresponsive.


Therefore care must be taken when constructing a recursive algorithms.




Recursion in data structure
$7.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
Mnyazi

Get to know the seller

Seller avatar
Mnyazi Freelancer
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
3 year
Number of followers
0
Documents
119
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions