Aim & Algorithm
Aim & Algorithm
AIM:
Aim is to write a program in C to implement the stack ADT using array concept that performs
all the operations of stack.
ALGORITHM:
step7.
STEP 4: Create the stack. Initially get the limit of stack and the get the items. If the limit of
stack is exceeds print the message unable to create the stack.
STEP 5: Get the element to be pushed. If top pointer exceeds stack capacity. Print Error
message that the stack overflow. If not, increment the top pointer by one and store the
element in the position which is denoted by top pointer.
STEP 6: If the stack is empty, then print error message that stack is empty. If not fetch the
element from the position which is denoted by top pointer and decrement the top
pointer by one
STEP 7: If the top value is not less than the 0 the stack is display otherwise print the message
“stack is empty”.
RESULT:
Thus a C program for Stack using ADT was implemented successfully
EX. NO: 1B QUEUE ADT USING ARRAY
RESULT:
RESULT:
Thus the C program for array implementation of List ADT was created,
executed and output was verified successfully
EX. NO: 3A STACK ADT USING LINKED LIST
AIM:
To write a C program for stack ADT using linked list implementation.
1. Define a struct for each node in the stack. Each node in the stack contains
data and link to the next node. TOP pointer points to last node inserted in
the stack.
2. The operations on the stack are
a. PUSH data into the stack
b. POP data out of stack
3. PUSH DATA INTO STACK
a. Enter the data to be inserted into stack.
b. If TOP is NULL
i. The input data is the first node in stack.
ii. The link of the node is NULL.
iii. TOP points to that node.
c. If TOP is NOT NULL
i. The link of TOP points to the new node.
ii. TOP points to that node.
4. POP DATA FROM STACK
RESULT:
Thus the C program for array implementation of Stack ADT was created,
executed and output was verified successfully
EX. NO: 3B QUEUE ADT USING LINKED LIST
AIM:
To write a C program for Queue using Linked implementation.
ALGORITHM:
1. Define a struct for each node in the queue. Each node in the queue
Contains data and link to the next node. Front and rear pointer points to
first and last node inserted in the queue.
Thus the C program for array implementation of Queue ADT was created, executed
and output was verified successfully
\
AIM:
2: For addition of two polynomials if exponents of both the polynomials are same then we
add the coefficients. For storing the result we will create the third linked lists say P3.
3: If Exponent of P2 is greater than exponent of P1 then keep the P3 as P2.
6: Continue the above step from 3 to 5 until end of the two polynomials.
RESULT:
AIM:
ALGORITHM:
it.
4: If the incoming symbol in an operator and has more priority then the symbol into the stack.
5: If the incoming operator has less priority than the stack symbol then copy the symbol at
the
Top of the stack and then print until the condition becomes false and push the following
6: If the symbol is ‘)’ then copy operators from top of the stack. Deletion opening
AIM:
To write a C program Implementation Binary Tree and Operations of Binary Trees
ALGORITHM
1. Start from root.
2. Compare the inserting element with root, if less than root, then visit for left, else visit for right.
3. If element to search is found anywhere, return true, else return false
Result:
Thus the program in C is implemented Binary Tree and Operations of Binary Trees.
EX. NO: 6 IMPLEMENTATION OF BINARY SEARCH TREE
AIM:
To write a C program to implementation of binary search tree.
ALGORITHM:
1. Declare function create (), search (), delete (), Display ().
2. Create a structure for a tree contains left pointer and right pointer.
3. Insert an element is by checking the top node and the leaf node and the
operation will be performed.
4. Deleting an element contains searching the tree and deleting the item.
5. Display the Tree elements.
RESULT:
Thus the C program for binary search tree was created, executed and output was
verified successfully.
EX NO: 7 IMPLEMENTATION OF AVL TREE
AIM:-
RESULT
Thus the ‘C’ program to implement an AVL trees. Produce its pre-Sequence, In-Sequence, and Post-
Sequence traversals
EXNO: 8 IMPLEMENTATION OF PRIORITY QUEUE USING HEAPS
AIM:
To write a C program to implement Priority Queue using Binary Heaps.
ALGORITHM:
6. Else if element value is less than the root value, insert element at the left of the root.
RESULT:
Thus the Priority Queue using Binary Heap is implemented and the
result is verified successfully
AIM:
Aim:
To write a C program implement DFS and BFS graph traversal.
ALGORITHM:
DFS
1. Define a Stack of size total number of vertices in the graph.
2. Select any vertex as starting point for traversal. Visit that vertex and push it on to the Stack.
3. Visit any one of the adjacent vertex of the vertex which is at top of the stack which is not
visited and push it on to the stack.
4. Repeat step 3 until there are no new vertex to be visit from the vertex on top of the stack.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES LABORATORY
5. When there is no new vertex to be visit then use back tracking and pop one vertex from the stack.
6. Repeat steps 3, 4 and 5 until stack becomes Empty.
7. When stack becomes Empty, then produce final spanning tree by removing unused edges from
the graph
BFS
1. Define a Queue of size total number of vertices in the graph.
2. Select any vertex as starting point for traversal. Visit that vertex and insert it into the Queue.
3. Visit all the adjacent vertices of the vertex which is at front of the Queue which is not visited
and insert them into the Queue.
4. When there is no new vertex to be visit from the vertex at front of the Queue then delete that
vertex from the Queue.
5. Repeat step 3 and 4 until queue becomes empty.
6. When queue becomes Empty, then produce final spanning tree by removing unused edges from
the graph
RESULT:
AIM:
To write a C Program to implement different searching techniques – Linear and Binary search.
ALGORITHM:
Linear Search:
1. Read the search element from the user
2. Compare, the search element with the first element in the list.
3. If both are matching, then display "Given element found!!!" and terminate the function
4. If both are not matching, then compare search element with the next element in the list.
5. Repeat steps 3 and 4 until the search element is compared with the last element in the list.
6. If the last element in the list is also doesn't match, then display "Element not found!!!" and
terminate the function.
Binary search is implemented using following steps...
RESULT
Thus the C Program to implement different searching techniques – Linear and Binary search
AIM:
1: Start.
2: Repeat Steps 3 and 4 for i=1 to 10
3: Set j=1
4: Repeat while j<=n
[End of if]
5: Stop.
RESULT:
Thus a C program for the concept of bubble sort was implemented successfully.
Ex. No: 11.B MERGE SORT
AIM:
To write a C program to implement the concept of merge sort.
ALGORITHM:
1: Start.
5: Start comparing the starting two pair of elements with each other and place them in ascending order.
6: When you combine them compare them so that you make sure they are sorted.
7: When all the elements are compared the array will be surely sorted in an ascending
order.
8: Stop.
RESULT:
Thus a C program for the concept of merge sort was implemented successfully.
AIM:
1: Start.
2: Choose any element of the array to be the pivot.
3: Divide all other elements (except the pivot) into two partitions.
o All elements less than the pivot must be in the first partition.
o All elements greater than the pivot must be in the second partition.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES LABORATORY
4: Use recursion to sort both partitions.
5: Join the first sorted partition, the pivot, and the second sorted partition.
6: Stop
RESULT:
1. Create a structure, data (hash table item) with key and value as data.
2. Now create an array of structure, data of some certain size (10, in this case). But, the size of array
must be immediately updated to a prime number just greater than initial array capacity (i.e. 10, in
this case).
3. A menu is displayed on the screen.
4. User must choose one option from four choices given in the menu