Expt.
No:1(a)
IMPLEMENT SIMPLE ADTS AS PYTHON CLASSES
a.Stack
AIM:
To write a program to implement simple ADTS of program classes by using stack.
ALGORITHM:
Step 1: Start
Step 2: Initialize Stack
Step 3: Assign stack element with append() function
Step 4: Print it
Step 5: Get the stack element in LIFO order by pop() function
Step 6: Print the function
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)
IMPLEMENT SIMPLE ADTS AS PYTHON CLASSES
b.Queue
AIM:
To write a program to implement simple ADTS using queue.
ALGORITHM:
Step 1: Start
Step 2: Declare queue with some element
Step 3: Enqueue elements with append() function
Step 4: Print it
Step 5: To delete an element or dequeue use pop(0) for FIFO order
Step 6: Print the result
Step 7: Stop
RESULT:
Thus the program to implement simple ADTS using queue was developed by
successfully.
Expt.No:1(c)
IMPLEMENT SIMPLE ADTS AS PYTHON CLASSES
c.Flower Construction
AIM:
To write a program to implement simple ADTS as python classes for flower construction.
ALGORITHM:
Step 1: Start
Step 2: Construct a class flower
Step 3: Construct sub class jasmine, rose, lilly,Tulip
Step 4: Create an object for tulip class
Step 5: By using this object access all its super classes
Step 6: Print the result
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)
IMPLEMENT RECURSION ALGORITHM IN PYTHON
a.Factorial
AIM:
To write a program to implement recursion algorithm for factorial.
ALGORITHM:
Step 1: Start
Step 2: Define recursion function called factorial that takes as input
Step 3: Set as a base condition: if ‘n’ is a ‘0’ or ‘1’,return 1
Step 4: In recursion case call the factorial function with n-1 as the argument and multiply
the result.
Step 5: Print 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:
To write a program to implement recursion algorithm of Fibonacci Series.
ALGORITHM:
Step 1: Start
Step 2: Define recursion function called Fibonacci series which takes ‘n’ as argument
Step 3: if(n==0||n==1) return n
Step 4: Otherwise return or recursively call fib(n-1)+fib(n-2)
Step 5: Print the result
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:
To write a program to implement recursion algorithm of binary search.
ALGORITHM:
Step 1: Start
Step 2: Define a recursion function called binary search which takes low,high,array,key as
Argument
Step 3: Find the mid
Step 4: Compare mid with key value
Step 5: if it is same return index of mid
Step 6: if key<mid call the function which the argument high=mid-1
Step 7: if key>mid call the function which low=mid+1
Step 8: Repeat until the key is found
Step 9: Print the result
Step 10: Stop
RESULT:
Thus the program to implement recursion algorithm of binary search was developed
by successfully.
Expt.No:3
IMPLEMENT LIST ADT USING PYTHON ARRAY
AIM:
To write a program to implement ADT using array.
ALGORITHM:
Step 1: Start
Step 2: Import array to implement its features
Step 3: Assign list values with array() function
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
IMPLEMENTATION OF LINKED LIST USING PYTHON LIST
AIM:
To write a program to implement linked list using python list.
ALGORITHM:
Step 1: Start
Step 2: Create a node to store the data
Step 3: Check if the list of empty
Step 4: If the list is empty,add data to the node
Step 5: Assign the head pointer to it
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)
IMPLEMENTATION OF STACJK AND QUEUE ADTS
A.STACK USING ARRAY
Aim:
To write a program to implement stack using array
Algorithm:
Step 1: Start.
Step 2: Create a class called stack array.
Step 3: Initialize empty stack.
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:
Thus the program has been implement successfully.
EXPT.NO:5(b)
B.QUEUE USING ARRAY
Aim:
To write a program to implement queue using array.
Algorithm:
Step 1: Start.
Step 2: Create a class queue.
Step 3: Declare empty queue.
Step 4: Use append() to enqueue the element, pop(0) to retrieve the first element, isEmpty()
to check whether it is false or empty.
Step 5: Print the result
Step 6: Stop
RESULT:
Thus the program for queue using array was developed by successfully.
Expt.No:5(c)
C.STACK USING LINKEDLIST
AIM:
To write a program for stack using linkedlist.
ALGORITHM:
Step 1: Start
Step 2: Construct class called “node” the constructor __init__() contains two arguments
value and address of next node.
Step 3: Construct a new class to implement stack operations
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 7: Print the result
Step 8: Stop
RESULT:
Thus the program for stack using linkedlist was developed by successfully.
Expt.No:5(d)
D.QUEUE USING LINKEDLIST
AIM:
To write a program for queue using linkedlist.
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 6: Print the result
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:
To write a program to implement postfix evaluation by applying stack.
Algorithm:
Step1: Start
Step2: Read a character (Special key)
Step3: Convert it into integer and push it into the stack
Steep4: If the character is an operator, pop the stack twice to obtain two operands.
Step5: Push the result of the operation
Step6: Remove the final value from stack.
Step7: Print the result
Sterp8: Stop
Result:
Thus, the program has been developed successfully.
Ex. No: 6b
Application of Queue ADT
Aim:
To write a program to implement CPU scheduling process.
Algorithm:
Step1: Start
Step2: Get the number of process from user.
Step3: By using queue data structure (PlPS), determine processing time, time parameter.
Step4: Display if for every process and print it.
Step5: Stop.
Result:
Thus, the program has been implemented successfully.
Ex. No: 7a
Linear Search
Aim:
To write a program to implement Linear Search..
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
Step4; Do the process until the array is exhausted.
Step5: If no match is found, then print no match found.
Step6: Stop.
Result:
Thus, the program has been implemented successfully.
Ex. No: 7b
Binary Search
Aim:
To write a python program for binary search.
Algorithm:
Step1: Start
Step2: Initialize an array set first element as low, and set last element as high.
Step3: Calculate mid compare target value with mid.
Step4; If matches found, return index of mid.
Step5: If matches target value is less than mid, so assign low=mid+1
Step6; Do the process repeatedly until the mid value matches the target value.
Step7: Stop.
Result:
Thus, the program has been implemented successfully.
Ex. No: 7c
Python program to implement bubble sort
Aim:
To write a program to implement to implement bubble sort.
Algorithm:
Step1: Start
Step2: Create a function that takes an array as an argument.
Step3: Get the length of an array
Step4: Create a loop that repeats until swaps are needed.
Step5: Create an inner loop to compare each pair of adjacent.
Step6: It is in wrong order array, swap them.
Step7: Repeat the inner loop and outer loop until array.
Step8: Stop
Result:
Thus, the program has been implemented successfully.
Ex. No: 7d
Insertion Sort
Aim:
To write a program to implement insertion sort.
Algorithm:
Step1: Start
Step2: Create function with array as an argument
Step3: Create two loops and compare the element from index 0 to index loop range.
Step4: If an element is smaller, shift all elements one position to right.
Step5: Repeat the steps until the array is sorted.
Step6: Print the sorted array
Step7: Stop.
Result:
Thus, the program has been implemented successfully.
Ex. No: 7e
Selection Sort
Aim:
To write a program to implement Selection sort.
Algorithm:
Step1: Start
Step2: Create function which takes away as an argument.
Step3: Get the length of array
Step4: Set the first element as minimum and compare with neighboring.
Step5: If the second element is smaller, assign as minimum.
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:
Thus, the program has been implemented successfully.
Ex. No: 7f
Quick Sort
Aim:
To write a program to implement quick sort.
Algorithm:
Step1: Start
Step2: Create a function and give array as argument.
Step2: Assign the first element of array as pivot.
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.
Step8: Repeat the steps to get sorted array.
Step9: Print the sorted array
Step10: Stop.
Result:
Thus, the program has been implemented successfully.
Ex. No: 8
Hash Table
Aim:
To write a python program to implement for hash table.
Algorithm:
Step1: Start
Step2: Create an empty hash table
Step3: Insert a key value pair from hash table.
Step4: Find a value by key in the hash table.
Step5: Update the value associated with an existing key.
Step6: Check if the hash table has a given key
Step7: Stop.
Result:
Thus, the program has been implemented successfully.
Ex. No: 9
Tree traversal and traversal algorithm
Aim:
To write a python program to search the sort data in tree by using tree traversal.
Algorithm:
Step1: Start.
Step2: Declare a class which contains value of root node.
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.
Step6: Repeat the steps and print result.
Step7: Stop.
Result:
Thus, the program has been implemented successfully.
Ex. No: 10
Implementation of binary search tree
Aim:
To write a python program to implement binary search tree recursively.
Algorithm:
Step1: Start
Step2: Define the node structure of class including data value as null, reference of left is right
child.
Step3: Insert a value in root, if the root has value to a 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.
Step6: Repeat the process recursively
Step7: Print the result.
Step8: Stop.
Result:
Thus, the program has been implemented successfully.
EXPT.NO.11
IMPLEMENTATION OF HEAPS
Aim:
To write a program to implement min hoop.
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
Root “percolation up”.
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 6: Repeat the process
Step7: Print the result
Step: Stop
Resullt:
Thus, the program has been implemented successfully.
EXPT.NO:12(a)
PYTHON PROGRAM TO IMPLEMENT BREADTH FIRST SEARCH
Aim:
To write a python program to implement breadth first search.
Algorthim:
Step 1: Start.
Step 2: Select a node from the graph.
Step 3: Add the Starting nodo to queue adjacent nodes to add to queue and work it as
Visited.
Step 5: Then, dequeue the node frok front of the queue.
Step 6: Continue until the queue is empty
Step 7: Print the dequeue elements
Step 8: Stop.
Result:
Thus the program has been implement successfully.
EXPT.NO:12(b)
PYTHON PROGRAM TO IMPLEMENT DEPTH FIRST SEARCH
Aim:
To write a python program to implement depth first search algorithm.
Algorithm:
Step 1: Start.
Step 2: Create a grapth with vertices
Step 3: Start by putting any one of the graph’s vertices on top of the stack.
Step 4: Take the top item and mark it as visited.
Step 5: Create sub-array with adhacent nodes.
Step 6: Array elements on top of stack is marked as visited.
Step 7: Repeat the steps until the stack is empty and print the visited array
Step8: Stop
Result:
Thus the program has been implement successfully.
Ex No:13
IMPLEMENTATION OF SINGLE SOURCE PATH ALGORITHM
Aim:
To write a program to implement dijikira”s algorithm of single source shortest path.
Algorithm:
Step 1: Start
Step 2: Create an empty array to store which has minimum distance from source
Step 3: Assign ‘a’ weight for all vertex of excess source
Step 4: Assign ‘o’ as know for all vertex except source
Step 5: Assign piece of vertex which is not in output such that it has minimum distance
Step 6: Update distance of all vertex adjacent to V
Step 7: Repeat the process
Step 8: Stop
Result:
Thus,the program was developed successfully.
Ex No:14
IMPLEMENTATION OF MINIMUM SPANNINF TREE ALGORITHM
Aim:
To write a program to implement algorithm if minimum spanning tree
Algorithm:
Step 1: Start
Step 2: Determine an orbitary vertex of MST
Step 3: Choose one vertex
Step 4: Then we have to find all edges that connected to it
Step 5: Find the minimum array in it
Step 6:Add the choosen edge to MST if it does not forms cycle
Step 7: Return and print the MST
Step 8: Stop
Result:
Thus, the program was developed successfully.
Ex No:15
IMPLEMENTATION OF AVL TREE ALGORITHM
Algorithm:
Step 1: Start
Step 2: Create a node and check if the tree is empty
Step 3: If empty, new node as root of the tree
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 6: Print the result
Step 7: Stop
Result:
Thus, the program was developed successfully.