Simulation of Recursion and Data Structures
Simulation of Recursion and Data Structures
2020-2021
Certificate
ACKNOWLEDGEMENT
I have taken efforts in this project. However, it would not have been possible without
the kind support and help of many individuals. I would like to extend my sincere
thanks to all of them.
I am highly indebted to Udemy for their guidance and constant supervision as well as
for providing necessary information regarding the course & also for their support in
completing the course.
I would like to express my gratitude towards my parents & member of Udemy for
their kind co-operation and encouragement which help me in completion of this
project.
I would like to express my special gratitude and thanks to industry persons for giving
me such attention and time.
My thanks and appreciations also go to Udemy team in help the course and people
who have willingly helped me out with their abilities.
ABSTRACT
CHAPTER 1
1. INTRODUCTION
Problem Definition
Objectives
To study how the operations on data structure and algorithms are
performed. And how the values are compared in a sorting algorithms and
swapped. Total Number of comparison and exchanges performed in a sorting
algorithm.
And the corresponding code performed while sorting.
.To get a clear idea about various data structures and operations on it.
And how can we implement a data structure.
Data Structure:
Tree:
A tree data structure can be defined recursively (locally) as a collection of nodes
(starting at a root node), where each node is a data structure consisting of a
value, together with a list of references to nodes (the "children"), with the
constraints that no reference is duplicated, and none points to the root.
Linked List:
Linked lists are among the simplest and most common data structures. They can be used
to implement several other common abstract data types, including lists (the abstract
data type), stacks, queues, associative arrays, and S-expressions, though it is not
uncommon to implement the other data structures directly without using a list as the
basis of implementation.
The principal benefit of a linked list over a conventional array is that the list elements
can easily be inserted or removed without reallocation or reorganization of the entire
structure because the data items need not be stored contiguously in memory or on disk.
Linked lists allow insertion and removal of nodes at any point in the list, and can do so
with a constant number of operations if the link previous to the link being added or
removed is maintained during list traversal.
On the other hand, simple linked lists by themselves do not allow random access to the
data, or any form of efficient indexing. Thus, many basic operations — such as obtaining
the last node of the list (assuming that the last node is not maintained as separate node
reference in the list structure), or finding a node that contains a given datum, or locating
the place where a new node should be inserted — may require scanning most or all of
the list elements.
Algorithms
Bubble Sort:
Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting
algorithm that works by repeatedly stepping through the list to be sorted, comparing each
pair of adjacent items and swapping them if they are in the wrong order. The pass
through the list is repeated until no swaps are needed,which indicates that the list is
sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of
the list. Because it only uses comparisons to operate on elements, it is a comparison sort.
Although the algorithm is simple, most of the other sorting algorithms are more efficient
for large lists.
The algorithm divides the input list into two parts: the sublist of items already sorted,
which is built up from left to right at the front (left) of the list, and the sublist of items
remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is
empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding
the smallest (or largest, depending on sorting order) element in the unsorted sublist,
exchanging it with the leftmost unsorted element (putting it in sorted order), and
moving the sublist boundaries one element to the right.
Insertion sort:
Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one
item at a time. It is much less efficient on large lists than more advanced algorithms
such as quicksort, heapsort, or merge sort. However, insertion sort provides several
advantages:
Simple implementation
Adaptive (i.e., efficient) for data sets that are already substantially sorted: the time
complexity is O(n + d), where d is the number of inversions
More efficient in practice than most other simple quadratic (i.e., O(n2)) algorithms such
as selection sort or bubble sort; the best case (nearly sorted input) is O(n)
Stable; i.e., does not change the relative order of elements with equal keys
In-place; i.e., only requires a constant amount O(1) of additional memory space
When humans manually sort something (for example, a deck of playing cards), most use a
method that is similar to insertion sort.[1]
Quick sort:
CHAPTER 2
2. REQUIREMENT ENGINEERING
2.1FEASIBILITY STUDY
Feasibility study conducted once the problem is clearly understood.
Feasibility study is a high level capsule version of the entire system-analysis and design
process The objective is to determine quickly and at the minimum expense how to solve
the problem and to determine the problem is solved. The system has been tested for
feasibility in the following ways.
Technical feasibility
Operational feasibility
Economical feasibility
CHAPTER 3
3. Sysem Requirement
3.1.Algorithms
3.1.1.Bubble Sort
Figure 1: Bubble sort-This contain the text field for input values.The fields in
comparisons and Exchanges gives the number of comparison and exchanges.it
highlight the current code which is executing.
Code
int tmp = 0;
Computer Science and Enginnering Page 12
Introduction to Data structures and Algorithms
for(int i = 0;i<lenD;i++){
for(int j = (lenD-1);j>=(i+1);j--){
if(data[j]<data[j-1]){
tmp = data[j];
data[j]=data[j-1];
data[j-1]=tmp;
return data;
Figure 2: Insertion sort-This contain the text field for input values.The fields in
comparisons and Exchanges gives the number of comparison and exchanges.it
highlight the current code which is executing.n gives no.of values,x,k and i are the
pointers.
Code
int key = 0;
int i = 0;
for(int j = 1;j<lenD;j++){
key = data[j];
Computer Science and Enginnering Page 14
Introduction to Data structures and Algorithms
i = j-1;
data[i+1] = data[i];
i = i-1;
data[i+1]=key;
Figure 3: Quick sort-This contain the text field for input values.The fields in
comparisons and Exchanges gives the number of comparison and exchanges.it
highlight the current code which is executing.,i and j are the pointers.stack area shows
the contents in the stack
Code
if(lenD<2){
return data;}
pivot = data[ind];
for(i=0;i<lenD;i++){ if(i!=ind){
if(data[i]<pivot){
k++;
Figure 4:Selection Sort-This contain the text field for input values.The fields in
comparisons and Exchanges gives the number of comparison and exchanges.it highlight
the current code which is executing.n gives no.of values.,k and i are the pointers.
Code
int j = 0;
int tmp = 0;
for(int i=0;i<lenD;i++){ j = i;
for(int k = i;k<lenD;k++){
if(data[j]>data[k]){
j = k;}}
tmp = data[i];
data[i] = data[j];
data[j] = tmp;}
return data;}
Code
else{
node;}
{ BSTNode p, p2, n;
if (root.getData() == k)
lt = root.getLeft(); rt
= root.getRight();
return null;
{p = rt;
return p;}
Computer Science and Enginnering Page 20
Introduction to Data structures and Algorithms
{p = lt;
return p;}
else
{ p2 = rt;
p = rt;
{if (isEmpty())
System.out.println("Tree Empty");
else{
p.getLeft();
p.setLeft(lt); return
p2;}}
if (k < root.getData()){
n = delete(root.getLeft(), k);
Computer Science and Enginnering Page 21
Introduction to Data structures and Algorithms
else
{ n = delete(root.getRight(), k);
root.setRight(n); }
return root;}
Code
Figure 7:Linked List-Contain 4 buttons. Ins front, Ins Rear Del front and Search for
insert from front,insert from Rear delete from Front and Search a specified value
respectively
Code
int siz = 0;
if (first == null) {
first = n;
} else {
last.next = n;
n.data = val;
last = n; siz++;
first;
if (first == null) {
last = n;
first = n;
n.data = val;
siz++;
}
Computer Science and Enginnering Page 26
Introduction to Data structures and Algorithms
(first == null) {
return;
first = first.next;
siz--;
return siz;
CHAPTER 4
4. SYSTEM ENVIRONMENT
1. Pentium IV Processor
2. 512 MB RAM
3. 40GB HDD
4. 1024 * 768 Resolution Color Monitor
Note: This is not the “System Requirements”.
5. CONCLUSION
From earlier classes itself,we were studying about the data structures and algorithms.
Some of us are just by hearting the code.ie, we don’t know how the working is going on
there.And also we didn’t get an idea about these things.
So our applet provides the clear and detail idea about the data structure and
algorithms,and more over how the operations are done in recursion algorithms and data
structure. And the animated representation makes more easier and better
understandability on this topic.Outcome of this applet is make easier and simple way to
understand about the algorithms.
6. REFFERNCE
.http://www.w3schools.com/
.http://www.GeeksforGeeks.com/