0% found this document useful (0 votes)
28 views14 pages

Python & Data Structures Laboratory Manual

DSA Lab for job

Uploaded by

Pranav
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)
28 views14 pages

Python & Data Structures Laboratory Manual

DSA Lab for job

Uploaded by

Pranav
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/ 14

Python & Data Structures Laboratory

B. Tech. 3rd Semester

Name :
Roll Number :
Department : Computer Science and Engineering

Faculty of Engineering & Technology


Ramaiah University of Applied Sciences
Ramaiah University of Applied Sciences
Private University Established in Karnataka State by Act No. 15 of 2013

Faculty Engineering & Technology


Programme B. Tech. in CSE, AIML, ISE and MC
Year/Semester 2023 / 3rd
Name of the Laboratory Python & Data Structures Laboratory
Laboratory Code 21CSL206A
List of Lab Experiments
No Lab Experiment Marks (10) Faculty Signature

1 Array

2 Linked List

3 Stack

4 Queue

5 Binary Tree

6 Binary Search Tree

7 Heap

8 AVL Tree

9 Quick Sort

10 Merge Sort

Total Marks (100)

Signature of the Faculty In-charge


Experiment 1
Title of the laboratory experiment: Array
1. Aim:
To understand and implement the basic operations in arrays using python.

2. Objective:
To execute the below operations:

1. Traverse − print all the array elements one by one.


2. Insertion − Adds an element at the given index.
3. Deletion − Deletes an element at the given index.
4. Search − Searches an element using the given index or by the value.
5. Update − Updates an element at the given index.

3. Exercise:
To develop a python to perform the below tasks:

1. Create your own list of your favourite five sportsperson. Using this find out,
a) Length of the list.
b) Add a sixth sportsperson at the end of this list.
c) You realize that you need to add the sixth sportsperson after the second sportsperson,
so remove it from the list first and then add it after the second sportsperson.
d) Now you don't like two sportspersons. Now remove those two and replace them with
any other two sportspersons.
e) Sort the sportspersons list in alphabetical order (hint: use the dir() functions to list
down all functions available in the list).
2. Create a list of all even numbers between number x and number y.
a) Sort the sportspersons list in alphabetical order (hint: use the dir() functions to list
down all functions available in the list). The number x should be your age, and the
number y should be your father's or mother's age.

4. Experimental Procedure
1. Algorithm design
“Write the pseudocode of the main operations of the given data structure”
2. Program
“Paste the screenshot of the executed python code”
3. Presentation of the results
“Paste the output of the program”
4. Analysis and discussions
“Discuss the time complexities of all the operations of the given data structure”
Experiment 2
Title of the Laboratory Exercise: Linked List
1. Aim:
To understand and implement the basic operations in Circular Doubly Linked List using python.
2. Objective:
To execute the below operations in Circular Doubly Linked List:
1. Insert: Inserts an element after a specific value.
2. Delete: Deletes an element having a specific value.
3. Display: Prints the elements in the forward direction as well as in the reverse direction.
3. Exercise:
In a Circular Doubly Linked List class, implement the below four operations:
def insert_after_value(self, data_after, data_to_insert):
# Search for first occurance of data_after value in linked list
# Now insert data_to_insert after data_after node
def remove_by_value(self, data):
# Remove first node that contains data
def print_forward(self):
# This method prints list in forward direction. Use node.next. Use a print statement to print the
nodes in forward direction starting from the first node to the last node.
def print_backward(self):
# Print linked list in reverse direction. Use node.prev for this. Use a print statement to print the
nodes in backward direction starting from the last node to the first node.
Now make following calls,
LL = LinkedList()
LL.insert_values(["Red","Yellow","Purple","Orange"])
LL.print()
LL.insert_after_value("Yellow","Blue") # insert Blue after Yellow
LL.print()
LL.remove_by_value("orange") # remove Orange from linked list
LL.print()
LL.remove_by_value("Green")
LL.print()
LL.remove_by_value("Red")
LL.remove_by_value("Yellow")
LL.remove_by_value("Blue")
LL.remove_by_value("Purple")
LL.print()
LL.print_forward()
LL.print_backward()

4. Experimental Procedure
1. Algorithm design
“Write the pseudocode of the main operations of the given data structure”
2. Program
“Paste the screenshot of the executed python code”
3. Presentation of the results
“Paste the output of the program”
4. Analysis and discussions
“Discuss the time complexities of all the operations of the given data structure”
Experiment 3
Title of the Laboratory Exercise: Stack
1. Aim:
To understand and implement the basic operations in stack using python.
2. Objective:
To execute the below operations in stack:
1. Push: Pushing (storing) an element on the stack.
2. Pop: Removing (accessing) an element from the stack.
3. Peek: get the top data element of the stack, without removing it.
4. Check if stack is full.
5. Check if stack is empty.
3. Exercise:
1. Write a function in python that can reverse a string (your full name) using stack data structure.
Create a function called “reverse_myname” which does this operation.
Follow the steps given below to reverse a string using stack:
a) Create an empty stack.
b) One by one push all characters of string to stack by calling a push().
c) One by one pop all characters from stack and put them back to string by calling a
pop().
2. Create a Python function named "is_it_balanced" that determines if the string's parenthesis
are balanced or not. "{}',"()" or "[]" are examples of parentheses.

4. Experimental Procedure
1. Algorithm design
“Write the pseudocode of the main operations of the given data structure”
2. Program
“Paste the screenshot of the executed python code”
3. Presentation of the results
“Paste the output of the program”
4. Analysis and discussions
“Discuss the time complexities of all the operations of the given data structure”
Experiment 4
Title of the Laboratory Exercise: Queue
1. Aim:
To understand and implement the basic operations in deque using python.
2. Objective:
To execute the below operations in a full binary tree:
1. Insert an element at the front end of the deque.
2. Delete an element at the rear end of the deque.
3. Exercise:
Using the deque data structure, insert some elements at the front and delete an element at the rear end
of the deque. The maximum size of the array is 6. Check the conditions of overflow and underflow
before carrying out insertion and deletion, respectively.

4. Experimental Procedure
1. Algorithm design
“Write the pseudocode of the main operations of the given data structure”
2. Program
“Paste the screenshot of the executed python code”
3. Presentation of the results
“Paste the output of the program”
4. Analysis and discussions
“Discuss the time complexities of all the operations of the given data structure”
Experiment 5

Title of the Laboratory Exercise: Binary Tree


1. Aim:
To understand and implement the basic operations in full binary tree using python.
2. Objective:
To execute the below operations in a full binary tree:
1. Search − Searches an element in a tree.
2. Insert − Inserts an element in a tree.
3. Pre-order Traversal − Traverses a tree in a pre-order manner.
4. In-order Traversal − Traverses a tree in an in-order manner.
5. Post-order Traversal − Traverses a tree in a post-order manner.
3. Exercise:
Construct a full binary tree with 10 nodes, where the data item inserted at every node should be a
random value between 1 and 100. Add the following methods to the class named "FullBinaryTree"
and perform the operation on the constructed full binary tree.
1. find_min(): finds the minimum element stored in the constructed Full binary tree.
2. find_max(): finds the maximum element stored in the constructed Full binary tree.
3. calculate_sum(): calculates the sum of all elements stored in the constructed Full binary tree.
4. pre_order_traversal(): performs pre-order traversal of the constructed Full binary tree.
5. post_order_traversal(): performs post-order traversal of the constructed Full binary tree.
6. in_order_traversal(): performs in-order traversal of the constructed Full binary tree.

4. Experimental Procedure
5. Algorithm design
“Write the pseudocode of the main operations of the given data structure”
6. Program
“Paste the screenshot of the executed python code”
7. Presentation of the results
“Paste the output of the program”
8. Analysis and discussions
“Discuss the time complexities of all the operations of the given data structure”
Experiment 6
Title of the Laboratory Exercise: Binary Search Tree
1. Aim:
To understand and implement the basic operations in Binary Search Tree using python.
2. Objective:
To execute the below operations in a Binary Search Tree (BST):
1. Search − Searches an element in a BST.
2. Insert − Inserts an element in a BST.
3. Delete − Deletes an element in a BST.
4. Check the balance of the BST.
5. Determine the height of the BST.
3. Exercise:
Construct a binary search tree with the below values: {12, 35, 14, 97, 36, 65, 89}. Write a python
program to perform the following operations:
1. Insert a new element which is having a value equivalent to the “last two digits of your roll
number”.
2. To determine the height of the constructed BST.
3. Delete any element from the constructed BST.
4. To check if the constructed BST is Balanced or not.

4. Experimental Procedure
a. Algorithm design
“Write the pseudocode of the main operations of the given data structure”
b. Program
“Paste the screenshot of the executed python code”
c. Presentation of the results
“Paste the output of the program”
d. Analysis and discussions
“Discuss the time complexities of all the operations of the given data structure”
Experiment 7
Title of the Laboratory Exercise: Heap
1. Aim:
To understand and implement the basic operations in Heap using python.
2. Objective:
To execute the below operations in a Heap:
a. Heapify the binary tree
b. Insert a new node into the heap binary tree
c. Delete an existing node from the heap binary tree
3. Exercise:
Implement a Python program that constructs a binary tree with the following: 3, 9, 2, 1, 4, 5, 7, 11,
9. Write a python program to perform the following operations.
a. Construct a Max Heap Binary Tree
b. Construct a Min Heap Binary tree
c. Insert a new node which is the last two digits of your roll no. into the Heap tree
d. Delete the node with element 4 from the Heap Tree

4. Experimental Procedure
1. Algorithm design
“Write the pseudocode of the main operations of the given data structure”
2. Program
“Paste the screenshot of the executed python code”
3. Presentation of the results
“Paste the output of the program”
4. Analysis and discussions
“Discuss the time complexities of all the operations of the given data structure”
Experiment 8
Title of the Laboratory Exercise: AVL Tree
1. Aim:
To understand and implement the basic operations in AVL using python.
2. Objective:
To execute the below operations in an AVL Tree:
1. Left rotation
2. Right rotation
3. Left-Right rotation
4. Right-Left rotation
3. Exercise:
Implement a Python program that constructs an AVL tree having the following elements: Z, I, J, F,
A, E, C, P, B, D, H, N. Consider the order of the elements in ascending order. Explain the rotations
diagrammatically.

4. Experimental Procedure
1. Algorithm design
“Write the pseudocode of the main operations of the given data structure”
2. Program
“Paste the screenshot of the executed python code”
3. Presentation of the results
“Paste the output of the program”
4. Analysis and discussions
“Discuss the time complexities of all the operations of the given data structure”
Experiment 9
Title of the Laboratory Exercise: Quick Sort
1. Aim:
To implement Quick Sort Algorithm using Python
2. Objective:
1. To understand the concept of Quick Sort Algorithm
2. To learn how to implement Quick Sort Algorithm using Python
3. To analyze the time complexity of Quick Sort Algorithm
3. Exercise:
In this exercise, you will implement Quick Sort Algorithm using Python. Follow the steps below:

Step 1: Write a function called quick_sort that takes an array of integers as input and returns a sorted array.
Step 2: Implement the Quick Sort Algorithm. The steps of the Quick Sort Algorithm are as follows:
i. Choose a pivot element from the array (can be the first or last element).
ii. Partition the array into two subarrays: one with elements less than or equal to the pivot, and one with
elements greater than the pivot.
iii. Recursively sort the two subarrays.
Step 3: Test your implementation using a test case that includes a list of 10 unsorted integers.
Step 4: Analyse the time complexity of Quick Sort Algorithm.
Step 5: Submit your code along with a brief explanation of the Quick Sort Algorithm and its time complexity
analysis.

Note: You can use the time module in Python to measure the time taken by your quick_sort function to sort
an array.

4. Experimental Procedure
5. Algorithm design
“Write the pseudocode of the main operations of the given sorting technique”
6. Program
“Paste the screenshot of the executed python code”
7. Presentation of the results
“Paste the output of the program”
8. Analysis and discussions
“Discuss the time complexities of all the operations of the given sorting technique”
Experiment 10
Title of the Laboratory Exercise: Merge Sort
1. Aim:
To implement Merge Sort Algorithm using Python
2. Objective:
1. To understand the concept of Merge Sort Algorithm
2. To learn how to implement Merge Sort Algorithm using Python
3. To analyze the time complexity of Merge Sort Algorithm
3. Exercise:
In this exercise, you are required to implement the merge sort algorithm using Python. Follow the
instructions below:

Step 1: Define a function called "merge_sort" that takes in a list of numbers as input and returns a
sorted list using the merge sort algorithm.
Step 2: Implement the "merge" function, which will be used in the merge sort algorithm. This
function takes two sorted sub-lists and merges them into a single sorted list. The merge function
should return the merged list.
Step 3: Implement the "merge_sort" function using recursion. The function should divide the input
list into two halves, sort each half recursively, and then merge the two sorted halves using the "merge"
function.
Step 4: Test your implementation using a test case that includes a list of 10 unsorted integers.
Step 5: Analyse the time complexity of your implementation.

4. Experimental Procedure
1. Algorithm design
“Write the pseudocode of the main operations of the given sorting technique”
2. Program
“Paste the screenshot of the executed python code”
3. Presentation of the results
“Paste the output of the program”
4. Analysis and discussions
“Discuss the time complexities of all the operations of the given sorting technique”

You might also like