DSA L Aim Algorithm
DSA L Aim Algorithm
No:1(a)
a.Stack
AIM:
ALGORITHM:
Step 1: Start
Step 4: Print it
Step 7: Stop
RESULT:
Thus the program to implement simple ADTS of python classes by using stack was developed
by successfully.
Expt.No:1(b)
b.Queue
AIM:
ALGORITHM:
Step 1: Start
Step 4: Print it
Step 7: Stop
RESULT:
Thus the program to implement simple ADTS using queue was developed by
successfully.
Expt.No:1(c)
c.Flower Construction
AIM:
To write a program to implement simple ADTS as python classes for flower construction.
ALGORITHM:
Step 1: Start
Step 7: Stop
RESULT:
Thus the program to implement simple ADTS as python classes for flower construction
was developed by successfully.
Expt.No:2(a)
a.Factorial
AIM:
ALGORITHM:
Step 1: Start
Step 4: In recursion case call the factorial function with n-1 as the argument and multiply
the result.
Step 6: Stop
RESULT:
Thus the program to implement recursion algorithm for factorial was developed by
successfully.
Expt.No:2(b)
b. Fibonacci Series
AIM:
ALGORITHM:
Step 1: Start
Step 2: Define recursion function called Fibonacci series which takes ‘n’ as argument
Step 6: Stop
RESULT:
Thus the program to implement recursion algorithm of Fibonacci series was developed by
successfully.
Expt.No:2(c)
c. Binary Search
AIM:
ALGORITHM:
Step 1: Start
Step 2: Define a recursion function called binary search which takes low,high,array,key as
Argument
Thus the program to implement recursion algorithm of binary search was developed
by successfully.
Expt.No:3
AIM:
ALGORITHM:
Step 1: Start
Step 4: Use insert() to add element at desired position, append() to add element at end of
the list
Step 5: Use remove() to delete the desired element, index() is used to find the index of
Element
Step 6: Print the result
Step 7: Stop
RESULT:
Thus the program to implement ADT using python array was developed by
successfully.
Expt.No:4
AIM:
ALGORITHM:
Step 1: Start
Step 6: If the list is not empty, add the data to the node and link the address to current
head.
Step 7: Assign the head to newly added node
Step 8: Stop
RESULT:
Thus the program to implement linked list using python list was developed by
successfully.
EXPT.NO:5(a)
Aim:
To write a program to implement stack using array
Algorithm:
Step 1: Start.
Step 4: Use append() to push element, pop() to retrieve element,empty() to check whether
It is full or empty
Step 5: Print the result
Step 6: Stop
RESULT:
Aim:
Algorithm:
Step 1: Start.
Step 4: Use append() to enqueue the element, pop(0) to retrieve the first element, isEmpty()
Step 6: Stop
RESULT:
Thus the program for queue using array was developed by successfully.
Expt.No:5(c)
AIM:
ALGORITHM:
Step 1: Start
Step 2: Construct class called “node” the constructor __init__() contains two arguments
value and address of next node.
Step 4: Get values from user and check head is none or not
Step 5: If node assign 1st values as head. Else assign the addresses to next of the node
value.
Step 6: If value is retrieved assign the address of next node to previous head
Step 8: Stop
RESULT:
Thus the program for stack using linkedlist was developed by successfully.
Expt.No:5(d)
AIM:
ALGORITHM:
Step 1: Start
Step 2: Create class called “node” which contains two arguments data and address of
next node
Step 3: Construct another class called “Queue” which is used to access all features of
Queue
Step 4: The constructor __init__ has value of head node and linkage of address of its
sub nodes
Step 5: The append() is used to enqueue queue elements and pop(0) is used to
dequeue queue elements
Step 7: Stop
RESULT:
Thus the program for queue using linkedlist was developed by successfully.
Ex. No: 6a
Application of Stack
a. Postfix evaluation
Aim:
Algorithm:
Step1: Start
Steep4: If the character is an operator, pop the stack twice to obtain two operands.
Sterp8: Stop
Result:
Aim:
Algorithm:
Step1: Start
Step3: By using queue data structure (PlPS), determine processing time, time parameter.
Step5: Stop.
Result:
Linear Search
Aim:
Algorithm:
Step1: Start
Step2: Initialize array start with first element, assign target value
Step3: Compare and check if the current index value otherwise move to next value
Step6: Stop.
Result:
Binary Search
Aim:
Algorithm:
Step1: Start
Step2: Initialize an array set first element as low, and set last element as high.
Step6; Do the process repeatedly until the mid value matches the target value.
Step7: Stop.
Result:
Aim:
Algorithm:
Step1: Start
Step7: Repeat the inner loop and outer loop until array.
Step8: Stop
Result:
Insertion Sort
Aim:
Algorithm:
Step1: Start
Step3: Create two loops and compare the element from index 0 to index loop range.
Step7: Stop.
Result:
Selection Sort
Aim:
Algorithm:
Step1: Start
Step4: Set the first element as minimum and compare with neighboring.
Step6: After each iteration, minimum element is supported in front of unsorted array.
Step7: Repeat the steps to get the sorted array and print it.
Step8: Stop.
Result:
Quick Sort
Aim:
Algorithm:
Step1: Start
Step4: Take two variable to point left and right of array excluding pivot.
Step5: The left will point lower index and right will point higher index.
Step6: Move all elements which are greater than pivot in right and lower than pivot in left.
Step7: For each complete iteration, the pivot comes middle of its lesser and greater elements.
Step10: Stop.
Result:
Hash Table
Aim:
Algorithm:
Step1: Start
Step7: Stop.
Result:
Aim:
To write a python program to search the sort data in tree by using tree traversal.
Algorithm:
Step1: Start.
Step3: In preorder traversal PLR, start with parent, go left subtree until its end, then move to
right subtree.
Step4: In an order traversal LPR, start with left subtree, print parent node only, then move to
right subtree.
Step5: In postorder traversal LPR, start with left subtree then right subtree and print the parent
node.
Step7: Stop.
Result:
Aim:
Algorithm:
Step1: Start
Step2: Define the node structure of class including data value as null, reference of left is right
child.
Step4: If the value to be inserted is smaller than root, insert in left subtree.
Step5: If the value to be inserted is greater than root, insert in right subree.
Step8: Stop.
Result:
IMPLEMENTATION OF HEAPS
Aim:
Algorithm:
Step 1: Start
Step 2: Create hole in available location, check binary heap tree properly.
Step 3: If no violation occurs, move to insert next element. Else, bubble up the value towards
Step 4: To remove the element, create hole at root, insert last element without disturbing the
Heap property.
Step 5: If heap property is disturbed interchange it with its childes “percolation down”.
Step: Stop
Resullt:
Thus, the program has been implemented successfully.
EXPT.NO:12(a)
Aim:
Algorthim:
Step 1: Start.
Step 3: Add the Starting nodo to queue adjacent nodes to add to queue and work it as
Visited.
Step 8: Stop.
Result:
Aim:
Algorithm:
Step 1: Start.
Step 3: Start by putting any one of the graph’s vertices on top of the stack.
Step 7: Repeat the steps until the stack is empty and print the visited array
Step8: Stop
Result:
Aim:
Algorithm:
Step 1: Start
Step 2: Create an empty array to store which has minimum distance from source
Step 5: Assign piece of vertex which is not in output such that it has minimum distance
Step 8: Stop
Result:
Aim:
Algorithm:
Step 1: Start
Step 6:Add the choosen edge to MST if it does not forms cycle
Step 8: Stop
Result:
Algorithm:
Step 1: Start
Step 4: If the tree is not empty, perform binary search tree of insertion operation, check balance
factor
Step 5: Suppose balancing factor exceeds {-1,+1,0} , apply suitable rotations and do step 4.
Step 7: Stop
Result: