0% found this document useful (0 votes)
75 views

Simulation of Recursion and Data Structures

The document provides an introduction to data structures and algorithms. It discusses different data structures like arrays, stacks, queues, linked lists and trees. It also explains sorting algorithms like bubble sort, selection sort, insertion sort and quick sort.

Uploaded by

Vikas Sonkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Simulation of Recursion and Data Structures

The document provides an introduction to data structures and algorithms. It discusses different data structures like arrays, stacks, queues, linked lists and trees. It also explains sorting algorithms like bubble sort, selection sort, insertion sort and quick sort.

Uploaded by

Vikas Sonkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Introduction to Data structures and Algorithms

2020-2021

Submit by: Submit to:


Akash Babu Vivek Shrivastava

Computer Science and Enginnering Page 1


Introduction to Data structures and Algorithms

Certificate

Computer Science and Enginnering Page 2


Introduction to Data structures and Algorithms

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.

Computer Science and Enginnering Page 3


Introduction to Data structures and Algorithms

ABSTRACT

To make the student easier to study how the operations on data


sturucture and various algorithms are performed.The data structures
can be stack,queue and linked list etc and algorithms are sorting like
bubble sort,insertion sort etc.

Aim behind implementation of this project to make a clear


understandability of various algorithms of data structures. Using a
web page this will simulates the data structure operations such as
searching, sorting, insertion, deletion etc. In array, stack, queue, and
linked list as well. Thus,our web page provides effective and efficient
knowledge of data structures. This also provide some theoretical
knowledge regarding the data structure.

Computer Science and Enginnering Page 4


Introduction to Data structures and Algorithms

CHAPTER 1
1. INTRODUCTION

Problem Definition

Aim behind implementation of this project to make a clear understandability of


various algorithms of data structures. Using a web page this will simulates the data
structure operations such as searching, sorting, insertion, deletion etc. In array,
stack, queue, and linked list as well. Thus our web page provides effective and
efficient knowledge of data structures. This also provide some theoretical
knowledge regarding the data structure.

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:

In computer science, a data structure is a particular way of storing and organizing


data in a computer so that it can be used efficiently.
Computer Science and Enginnering Page 5
Introduction to Data structures and Algorithms

Different kinds of data structures are suited to different kinds of applications,


and some are highly specialized to specific tasks. For example, B-trees are
particularly well-suited for implementation of databases, while compiler
implementations usually use hash tables to look up identifiers.

Data structures provide a means to manage large amounts of data efficiently,


such as large databases and internet indexing services. Usually, efficient data
structures are a key to designing efficient algorithms. Some formal design
methods and programming languages emphasize data structures, rather than
algorithms, as the key organizing factor in software design. Storing and retrieving
can be carried out on data stored in both main memory and in.

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.

Alternatively, a tree can be defined abstractly as a whole (globally) as an ordered


tree, with a value assigned to each node. Both these perspectives are useful: while a
tree can be analyzed mathematically as a whole, when actually represented as a
data structure it is usually represented and worked with separately by node (rather
than as a list of nodes and an adjacency list of edges between nodes, as one may
represent a digraph, for instance).

Computer Science and Enginnering Page 6


Introduction to Data structures and Algorithms

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.

Computer Science and Enginnering Page 7


Introduction to Data structures and Algorithms

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.

Computer Science and Enginnering Page 8


Introduction to Data structures and Algorithms
Selection Sort:
selection sort is a sorting algorithm, specifically an in-place comparison sort. It has
O(n2) time complexity, making it inefficient on large lists, and generally performs worse
than the similar insertion sort. Selection sort is noted for its simplicity, and it has
performance advantages over more complicated algorithms in certain situations,
particularly where auxiliary memory is limited.

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

Computer Science and Enginnering Page 9


Introduction to Data structures and Algorithms

Efficient for (quite) small data sets

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

Online; i.e., can sort a list as it receives it

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:

Quicksort, or partition-exchange sort, is a sorting algorithm developed by Tony Hoare


that, on average, makes O(n log n) comparisons to sort n items. In the worst case, it
makes O(n2) comparisons, though this behavior is rare. Quicksort is often faster in
practice than other O(n log n) algorithms.Additionally, quicksort's sequential and
localized memory references work well with a cache. Quicksort is a comparison sort and,
in efficient implementations, is not a stable sort. Quicksort can be implemented with an
in-place partitioning algorithm, so the entire sort can be done with only O(log n)
additional space used by the stack during the recursion.

Computer Science and Enginnering Page 10


Introduction to Data structures and Algorithms

CHAPTER 2

2. REQUIREMENT ENGINEERING

Systematic requirements analysis is also known as requirements engineering. It is


sometimes referred to loosely by names such as requirements gathering, requirements
capture, or requirements specification. The term requirements analysis can also be
applied specifically to the analysis proper, as opposed to elicitation or documentation of
the requirements, for instance.
Requirement engineering according to Lap ante (2007)
is "a sub discipline of systems engineering and software engineering that is concerned
with determining the goals, functions, and constraints of hardware and software
systems. In some life cycle models, the requirement engineering process begins with a
feasibility study activity, which leads to a feasibility report. If the feasibility study
suggests that the product should be developed, then requirement analysis can begin

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

Computer Science and Enginnering Page 11


Introduction to Data structures and Algorithms

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

public int[] bubbleSort(int[] data){

int lenD = data.length;

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;

Computer Science and Enginnering Page 13


Introduction to Data structures and Algorithms

3.1.2 Insertion Sort

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

void SortAlgo::insertionSort(int data[], int lenD)

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;

while(i>=0 && data[i]>key){

data[i+1] = data[i];

i = i-1;

data[i+1]=key;

3.1.3 Quick Sort

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

Computer Science and Enginnering Page 15


Introduction to Data structures and Algorithms
public int[] quickSort(int[] data){

int lenD = data.length,pivot=0,i,j=0,k=0;int lenD/2

if(lenD<2){

return data;}

else{ int[] L = new int[lenD];

int[] R = new int[lenD];

int[] sorted = new int[lenD];

pivot = data[ind];

for(i=0;i<lenD;i++){ if(i!=ind){

if(data[i]<pivot){

L[j] = data[i]; j++

else{ R[k] = data[i];

k++;

Computer Science and Enginnering Page 16


Introduction to Data structures and Algorithms
3.1.4.Selection Sort

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

public int[] selectionSort(int[] data){

int lenD = data.length;

int j = 0;

int tmp = 0;

Computer Science and Enginnering Page 17


Introduction to Data structures and Algorithms

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;}

Computer Science and Enginnering Page 18


Introduction to Data structures and Algorithms
3.2. Data Structures

3.2.1. Binary Search Tree

Figure 5:Binary Search Tree-Contain 4 buttons.insert (input) for give value


dynamically.insert(Random) for random values of input and search button for
searching any value that in the tree.delete button for deleting a specified node from
the tree.

Computer Science and Enginnering Page 19


Introduction to Data structures and Algorithms

Code

private BSTNode insert(BSTNode node, int data)

{if (node == null)

node = new BSTNode(data);

else{

if (data <= node.getData())

node.left = insert(node.left, data);

else node.right = insert(node.right, data);} return

node;}

public void delete(int k)

{ BSTNode p, p2, n;

if (root.getData() == k)

{BSTNode lt, rt;

lt = root.getLeft(); rt

= root.getRight();

if (lt == null && rt == null)

return null;

else if (lt == null)

{p = rt;

return p;}
Computer Science and Enginnering Page 20
Introduction to Data structures and Algorithms

else if (rt == null)

{p = lt;

return p;}

else

{ p2 = rt;

p = rt;

private BSTNode delete(BSTNode root, int k)

{if (isEmpty())

System.out.println("Tree Empty");

else if (search(k) == false)

System.out.println("Sorry "+ k +" is not present");

else{

root = delete(root, k);


System.out.println(k+ " deleted from thetree");}}

while (p.getLeft() != null) p =

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;}

Computer Science and Enginnering Page 22


Introduction to Data structures and Algorithms

3.2.2. Binary Tree Traversal

Figure 6:Binary Search Traversal-Contain 3 buttons. PreOrder,InOrder and PostOrder for


respective traversals

Code

public void preOrder(Node Root)


{ if(Root != null)
{ System.out.print(Root.item + " ");
preOrder(Root.leftChild);
preOrder(Root.rightChild);
}}

public void inOrder(Node Root)


{if(Root != null)

Computer Science and Enginnering Page 23


Introduction to Data structures and Algorithms
{ inOrder(Root.leftChild);

System.out.print(Root.item + " "); inOrder(Root.rightChild);


}}

public void postOrder(Node Root)


{ if(Root != null)
{ postOrder(Root.leftChild);
postOrder(Root.rightChild);
System.out.print(Root.item + " ");
}}

Computer Science and Enginnering Page 24


Introduction to Data structures and Algorithms

3.2.3. Linked List

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

public class LinkList {

Node first = null;

Node last = null;

int siz = 0;

Computer Science and Enginnering Page 25


Introduction to Data structures and Algorithms

public void insertEnd(int val) {

Node n = new Node();

if (first == null) {

first = n;

} else {

last.next = n;

n.data = val;

last = n; siz++;

public void insertBegin(int val) {

Node n = new Node(); n.next =

first;

if (first == null) {

last = n;

first = n;

n.data = val;

siz++;

}
Computer Science and Enginnering Page 26
Introduction to Data structures and Algorithms

public void deleteBegin() { if

(first == null) {

return;

first = first.next;

siz--;

public int size() {

return siz;

public boolean isEmpty() {

return first == null;

Computer Science and Enginnering Page 27


Introduction to Data structures and Algorithms

CHAPTER 4

4. SYSTEM ENVIRONMENT

4.1 Minimum Hardware Configuration

1. Pentium IV Processor
2. 512 MB RAM
3. 40GB HDD
4. 1024 * 768 Resolution Color Monitor
Note: This is not the “System Requirements”.

Computer Science and Enginnering Page 28


Introduction to Data structures and Algorithms

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.

Computer Science and Enginnering Page 29


Introduction to Data structures and Algorithms

6. REFFERNCE

.http://www.w3schools.com/
.http://www.GeeksforGeeks.com/

Computer Science and Enginnering Page 30


Introduction to Data structures and Algorithms

Computer Science and Enginnering Page 31

You might also like