Beruflich Dokumente
Kultur Dokumente
Course Outcomes
SRSWTI 1
College of
Department of SRSWTI Engineering
Computer Engineering
College of
LIST OF EXPERIMENT Engineering
College of
Expt. No. Name of the Experiment
Engineering
1. Implementation of Stack using array.
SRSWTI 2
College of
Department of SRSWTI Engineering
Computer Engineering
College of
EXPERIMENT NO. 1 Engineering
College of
AIM : Implementation of Stack using array. Engineering
PROBLEM : WAP to perform stack operation using static memory allocation
STATEMENT
Operations on Stack:
SRSWTI 3
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
1. Check whether stack is full or not. (i.e. if(top==MAXSIZE))
College of
2. Otherwise increase the top by 1(else top=top+1)
Engineering
3. Insert the element, elem.
stack[top]=elem;
EXPERIMENT NO. 2
SRSWTI 4
College of
Department of SRSWTI Engineering
Computer Engineering
College of
STATEMENT Engineering
RESOURCES :
College of
Equipment/Machines - P IV and Above, Printer, Turbo C/C+
REQUIRED + Engineering
Consumables Printer Pages for printouts.
Application of Stack:
1. Expression Evolution
2. Expression conversion
1. Infix to Postfix
2. Infix to Prefix
3. Postfix to Infix
4. Prefix to Infix
3. Parsing
4. Simulation of recursion
5. Fuction call
SRSWTI 5
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
College
values. They can just as well precede or follow the of
operands. You
should note the advantage of prefix and postfix: the need for
precedence rules and parentheses are eliminated.
Engineering
(a + b) * (c - d) *+ab-cd ab+cd-*
b*b-4*a*c
40 - 3 * 5 + 1
Algorithm:
SRSWTI 6
College of
Department of SRSWTI Engineering
Computer Engineering
College of
are taken care of. Engineering
5. Afterwards look at the stack one last timeCollege of
to see if any
operators remain, pop them all and add them to the end of
the postfix string.
Engineering
6. Stop the process.
EXPERIMENT NO. 3
AIM : Implementation of Queue using array.
SRSWTI 7
College of
Department of SRSWTI Engineering
Computer Engineering
College of
structure, in which the first element is insertedEngineering
from one
College
end called REAR(also called tail), and the deletion of of
existing element takes place from the other Engineering
end called
as FRONT(also called head). This makes queue as FIFO
data structure, which means that element inserted first
will also be removed first.
Queue Representation:
As we now understand that in queue, we access both
ends for different reasons. The following diagram given
below tries to explain queue representation as data
structure
SRSWTI 8
College of
Department of SRSWTI Engineering
Computer Engineering
College of
one-dimensional array.
Engineering
College of
Basic Operations:
Engineering
Queue operations may involve initializing or defining the
queue, utilizing it, and then completely erasing it from
the memory. Here we shall try to understand the basic
operations associated with queues
ALGORITHM:
peek()
This function helps to see the data at the front of the
queue. The algorithm of peek() function is as follows
Algorithm
return queue[front]
end procedure
isfull()
SRSWTI 9
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
As we are using single dimension array to implement
queue, we just check for the rear pointer toCollege
reach at of
Engineering
MAXSIZE to determine that the queue is full. In case we
maintain the queue in a circular linked-list, the algorithm
will differ. Algorithm of isfull() function
Algorithm
end procedure
isempty()
Algorithm of isempty() function
end procedure
SRSWTI 10
College of
Department of SRSWTI Engineering
Computer Engineering
College of
procedure enqueue(data) Engineering
if queue is full
return overflow
College of
endif Engineering
rear rear + 1
queue[rear] data
return true
end procedure
Applications of Queue
Queue, as the name suggests is used whenever we
need to have any group of objects in an order in which
the first one coming in, also gets out first while the others
wait for there turn, like in the following scenarios:
SRSWTI 11
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
arrive, First come first served.
College of
Engineering
CONCLUSION : Queue is used when things dont have to be processed
immediately, but have to be processed in First In First
Out order like Breadth First Search. Queue data
structure adds elements using array and removed
elements also.
EXPERIMENT NO. 4
AIM : Implementation of Circular Queue using array.
SRSWTI 12
College of
Department of SRSWTI Engineering
Computer Engineering
College of
the elements are deleted from the queue. Engineering
College of
For example consider the queue below.
SRSWTI 13
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Graphical representation of a circular Engineering
queue is as
follows... College of
Engineering
SRSWTI 14
College of
Department of SRSWTI Engineering
Computer Engineering
College of
1) enQueue(value) - Inserting value Engineering
into the
Circular Queue College of
ALGORITHM:
In a circular queue, enQueue() is a functionEngineering
which is
used to insert an element into the circular queue. In a
circular queue, the new element is always inserted
at rear position. The enQueue() function takes one
integer value as parameter and inserts that value into the
circular queue. We can use the following steps to insert
an element into the circular queue...
SRSWTI 15
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Deletion is not possible!!!" and terminate theEngineering
function.
College of
Step 3: If it is NOT EMPTY, then
display queue[front] as deleted element andEngineering
increment
the frontvalue by one (front ++). Then check
whether front == SIZE, if it is TRUE, then set front = 0.
Then check whether both front - 1 and rear are equal
(front -1 == rear), if it TRUE, then set
both frontand rear to '-1' (front = rear = -1).
Step 6: Set i to 0.
SRSWTI 16
College of
Department of SRSWTI Engineering
Computer Engineering
College of
CONCLUSION : In a standard queue data structure re-bufferingEngineering
problem
occurs for each dequeue operation. To College solve this of
problem by joining the front and rear ends of aEngineering
queue to
make the queue as a circular queue Circular queue is a
linear data structure. It follows FIFO principle. In circular
queue the last node is connected back to the first node
to make a circle.
SRSWTI 17
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
EXPERIMENT NO. 5
College of
AIM : Implementations of singly Linked List. Engineering
PROBLEM : WAP to implement create, insert, delete and display
STATEMENT operations in linked list.
REQUIRED +
THEORY : Description
SRSWTI 18
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
College of
Engineering
Each link is linked with its next link using its next link.
Basic Operations:
Following are the basic operations supported by a list.
SRSWTI 19
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
Search Searches an element using the given key.
College of
Delete Deletes an element using the given key.
Engineering
1. Static memory allocation may insert in wastage of memory
and shortage of memory. (Like in array implementations)
2. Assign the value of the data field of the new node, temp-
>info
3. Make the link field of the new node to point to the starting
node of the linked list, temp->next=start.
SRSWTI 20
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
starting node) to point to the new node, start=temp.
College of
Algorithm for inserting a node at the end
Engineering
1. If the list is empty then create the new node, temp=malloc
().
2. If the list is not empty, then go to the last node and then
insert the new node after the last node, r=start; go till last
node then r->next=temp.
4.Make the next field of node temp to node S and next field of
node R to point to new node.
4. Free temp.
1. Mark the last node as temp & last but one node as R.
3. Free temp.
SRSWTI 21
College of
Department of SRSWTI Engineering
Computer Engineering
College of
2. Mark the previous node as R & next nodes Engineering
as S.
College of
3. Make the next field of R to point S.
Engineering
4. Make the next field of temp, NULL.
5. Free Temp.
SRSWTI 22
College of
Department of SRSWTI Engineering
Computer Engineering
College of
EXPERIMENT NO. 6 Engineering
College of
AIM : Implementation of Stack using Linked List. Engineering
PROBLEM : WAP to implement stack operations using linked list.
STATEMENT
Example
SRSWTI 23
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
College of
Engineering
SRSWTI 24
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
Step 3: If it is Not Empty, then define a Node pointer 'temp'
and set it to 'top'. College of
Step 4: Then set 'top = top next'. Engineering
Step 5: Finally, delete 'temp' (free(temp)).
CONCLUSION :
EXPERIMENT NO. 7
AIM : Implementations of Binary Search Tree menu driven
SRSWTI 25
College of
Department of SRSWTI Engineering
Computer Engineering
College of
program. Engineering
PROBLEM :
College of
WAP to insert element in tree, delete element from tree,
STATEMENT search an element and traverse binary tree. Engineering
SRSWTI 26
College of
Department of SRSWTI Engineering
Computer Engineering
College of
knows the desired node must be on the left side Engineering
of the
tree; otherwise on right side of the tree. WhenCollege
the value of
is matched it is returned to the calling program.Engineering
SRSWTI 27
College of
Department of SRSWTI Engineering
Computer Engineering
College of
1. Find the proper position to insert a node. Engineering
College
2. If the new node key value is less than the parent node, of
make it its left child.
3. If the new node key value is greater thanEngineering
the parent
node makes it its right child.
CONCLUSION : In Binary tree each node has maximum of two child
nodes. It does not allow duplicate values. Searching in a
binary tree is faster with compare to other trees. It
provides six different traversals. It is used for graph
traversals and to convert an expression to postfix and
prefix forms. Almost for every high-bandwidth routers
binary tree stores router-tables.
EXPERIMENT NO. 08
AIM : Implementation of Quick Sort.
THEORY : Quick Sort, as the name suggests, sorts any list very quickly.
Quick sort is not stable search, but it is very fast and requires
very less additional space. It is based on the rule of Divide and
SRSWTI 28
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
Conquer(also called partition-exchange sort). This algorithm
divides the list into three main parts : College of
1. Elements less than the Pivot element
Engineering
2. Pivot element
Hnece after the first pass, pivot will be set at its position, with all
the elements smaller to it on its left and all the elements larger
than it on the right. Now 6 8 17 14 and 63 37 52 are considered
as two separate lists, and same logic is applied on them, and we
keep doing this until the complete list is sorted.
Algorithm steps:
SRSWTI 29
College of
Department of SRSWTI Engineering
Computer Engineering
College of
p := partition(A, lo, hi) Engineering
quicksort(A, lo, p)
quicksort(A, p + 1, hi)
College of
algorithm partition(A, lo, hi) is
Engineering
pivot := A[lo]
i := lo - 1
j := hi + 1
loop forever
do
i := i + 1
while A[i] < pivot
do
j := j - 1
while A[j] > pivot
if i >= j then
return j
CONCLUSION :
Quick sort is a highly efficient sorting algorithm and is based on
partitioning of array of data into smaller arrays. Using quick sort
method sorting elements in ascending or descending order.
EXPERIMENT NO. 09
AIM : Implementation of Binary Searching method.
SRSWTI 30
College of
Department of SRSWTI Engineering
Computer Engineering
College of
item. Otherwise, the item is searched for in the Engineering
sub-array to the
right of the middle item. This process continues College of
on the sub-array
as well until the size of the subarray reduces toEngineering
zero.
How Binary Search Works?
For a binary search to work, it is mandatory for the target array to
be sorted. We shall learn the process of binary search with a
pictorial example. The following is our sorted array and let us
assume that we need to search the location of value 31 using
binary search.
We change our low to mid + 1 and find the new mid value again.
low = mid + 1
mid = low + (high - low) / 2
Our new mid is 7 now. We compare the value stored at location 7
with our target value 31.
SRSWTI 31
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
College of
Engineering
The value stored at location 7 is not a match, rather it is more
than what we are looking for. So, the value must be in the lower
part from this location.
Algorithm steps:
Procedure binary_search
A sorted array
n size of array
x value to be searched
Set lowerBound = 1
Set upperBound = n
if A[midPoint] < x
SRSWTI 32
College of
Department of SRSWTI Engineering
Computer Engineering
College of
set lowerBound = midPoint + 1 Engineering
if A[midPoint] > x
College of
set upperBound = midPoint - 1 Engineering
if A[midPoint] = x
EXIT: x found at location midPoint
end while
end procedure
EXPERIMENT NO. 10
AIM : Implementation of Graph menu driven program (DFS & BFS)
SRSWTI 33
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
College
set (usually finite) and E is a set consisting of two elementof
subsets of V.
Engineering
Two main data structures for the representation of graphs are
used in practice. The first is called an adjacency list, and is
implemented by representing each node as a data structure
that contains a list of all adjacent nodes. The second is an
adjacency matrix, in which the rows and columns of a two-
dimensional array represent source and destination vertices
and entries in the array indicate whether an edge exists
between the vertices. Adjacency lists are preferred for sparse
graphs; otherwise, an adjacency matrix is a good choice.
Finally, for very large graphs with some regularity in the
placement of edges, a symbolic graph is a possible choice of
representation.
Review:
1. A graph G consists of two sets V and E. Set V is a finite
non empty set of vertices and E is a set of pairs of vertices
called edges.
2. There are two possible orders for visiting the vertices of the
graph, Depth First Search (DFS) and Breadth First Search
(BFS).
3. DFS of an undirected graph is roughly analogous to
preorder traversal of an ordered tree.
4. In DFS we traverse a single path of the graph as far as it
can go i.e. until it lists a node with no successors or a node all
of whose successors have already been visited.
5. In BFS all unvisited vertices adjacent to V are visited after
visiting the starting vertex V and marking it as visited. Next
the unvisited vertices adjacent to these vertices are visited
and so on until the entire graph has been traversed. BFS
uses queue to store the nodes of each level of the graph.
Algorithm for Depth First Search
1. Select any unvisited node in the graph. Mark this node as
SRSWTI 34
College of
Department of SRSWTI Engineering
Computer Engineering
College of
visited, push this on to the stack. Engineering
College
2. Find the adjacent node on TOS (top of stack), and which isof
not yet visited, mark this new node as visited & push on to
stack.
Engineering
3. Repeat step 2 until no new node to TOS node can b found,
when no new adjacent node can be found, pop TOS.
4. Repeat step 2 and 3 till stack becomes empty.
5. Repeat step 1 till any more nodes which are still unvisited-
USE ADJANCY MATRIX for finding adjacent nodes.
CONCLUSION : DFS has less time and space complexity rather than BFS.
And in DFS solution can be found out by without much more
search. The DFS spanning tree is special in that there are
no cross edges. This makes it easy to modify DFS into
finding cut vertices (articulation points), bridges, 2-connected
components, and even strongly connected components in
directed graphs.
SRSWTI 35
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
EXPERIMENT NO. 11
College of
AIM : Mini project Engineering
PROBLEM :
STATEMENT
THEORY :
ALGORITHM: :
CONCLUSION :
EXPERIMENT NO. 12
AIM : Write a recursive function to implement Tower of Hanoi.
SRSWTI 36
College of
Department of SRSWTI Engineering
Computer Engineering
College of
PROBLEM : WAP to implement tower of Hanoi usingEngineering
recursive
STATEMENT function. College of
RESOURCES : Engineering
Equipment/Machines - P IV and Above, Printer, Turbo
REQUIRED C/C++, JDK1.5
Consumables Printer Pages for printouts.
It calls itself.
When it calls itself, it does so to solve a smaller
problem.
There's some version of the problem that is
simple enough that the routine can solve it, and
return, without calling itself. In each successive
call of a recursive method to itself, the argument
becomes smaller reflecting the fact that the
problem has become "smaller" or easier. When
the argument or range reaches a certain minimum
size, a condition is triggered and the method
returns without calling itself.
In general, to solve a problem recursively, we must deal
with two cases:
SRSWTI 37
College of
Department of SRSWTI Engineering
Computer Engineering
College of
Engineering
start out on column A. The object of the puzzle is to
College
transfer all the disks from column A to column C. Only of
one disk can be moved at a time, and no disk Engineering
can be
placed on a disk that's smaller than itself. In the Towers
of Hanoi, we solve the problem of moving n disks in
terms of the easier problem of moving n 1 disk.
ALGORITHM: : 1. Start
2. If n==1, move the single disk from A to C and stop.
3. Move the top n1 disks from S to I.
4. Move the remaining (largest) disk from S to D.
5. Move the top n-1 from I to D.
6. Stop.
SRSWTI 38