0% found this document useful (0 votes)
13 views

Wa0018

Uploaded by

Saniya Kulsum
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)
13 views

Wa0018

Uploaded by

Saniya Kulsum
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/ 61

TABLE of Contents

PAGE
S. No Date PROGRAM
NUMBER
1. 15/07/2024 Recursive Technique 2
2. 16/07/2024 Iterative and Recursive Technique 3
3. 23/07/2024 Implementation of Doubly Linked List Data Structure 5
4 25/07/2024 Implementation of Stack Data Structure using append and pop 7
functions
5. 29/08/2024 Implementation of Stack Data Structure 9
6. 30/08/2024 Creation of Heap using Algorithm Heapify 10
7. 30/08/2024 Insertion into a Heap Data Structure 11
8. 30/08/2024 Creating a Heap using Algorithm Insert 12
9. 30/08/2024 Iterative and Recursive Technique 13
10. 06/09/2024 Divide and Conquer Paradigm: Search Algorithm 14
11. 06/09/2024 Divide and Conquer Paradigm: Search Algorithm 16
12. 12/09/2024 Partitioning the elements of the array 18
13. 12/09/2024 Merging of Two Sorted Arrays 20
14. 12/09/2024 Divide and Conquer Paradigm: Sorting the array by Partitioning 21
15. 12/09/2024 Divide and Conquer Paradigm: Selecting the kth smallest number 22
16. 12/09/2024 Divide and Conquer Paradigm: Sorting Problem 24
17. 12/09/2024 Divide and Conquer Paradigm: Finding Maximum and Minimum 25
18 12/09/2024 Application of Array data structure using modules 26
19 12/09/2024 Application of Array data structure 27
20 12/09/2024 Application of Stack Data Structure 28
21 12/09/2024 Applications of Deque Data Structure 29
22 12/09/2024 Sorting using heap data structure 30
23 12/09/2024 Implementation of Circular Queue Data Structure 31
24 19/09/2024 Operations on Binary Search Tree Data Structure 33
25 19/09/2024 Operations on Heap Data Structure: Deletion 36
26 19/09/2024 Implementation of Binary Search Tree Data Structure 38
27 25/09/2024 Implementation of Dynamic Array Data Structure 40
28 25/09/2024 Techniques for Algorithm Design: Greedy Algorithm – Knapsack 43
Problem
29 04/10/2024 Techniques for Algorithm Design: Dynamic Programming-Longest 44
Common Subsequence Problem
30 04/10/2024 Techniques for Algorithm Design: Backtracking: Sum of Subset 45
Problem
31 04/10/2024 Huffman Coding 46
32 04/10/2024 Techniques for Algorithm Design: Greedy Algorithm – Optimal 48
Storage on Tapes Problem
33 04/10/2024 Graph Traversal Technique: Depth First Search 50
34 04/10/2024 52
35 04/10/2024 Techniques for Algorithm Design: Greedy Algorithm – Minimum 55
Spanning Tree Problem
36 04/10/2024 Techniques for Algorithm Design: Greedy Algorithm – Minimum 57
Spanning Tree Problem
37 04/10/2024 Tree Traversal Technique 60
24-PMT-032 Page |2

Recursive Technique
DATE: 15/07/2024

PROGRAM NO.: 01 Create a script to print all possible permutations of the set {𝑙, 𝑚, 𝑛}.

Python Code:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 Page |3

Iterative and Recursive Technique


DATE: 16/07/2024

Formulate a code that implements iterative and recursive function to generate a


PROGRAM NO.: 02
Fibonacci sequence with n numbers. Execute your code for n = 12.

Python Code:
RECURSIVE METHOD

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 Page |4

ITERATIVE METHOD

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 Page |5

Implementation of Doubly Linked List Data Structure


DATE: 23/07/2024
Design a script for doubly linked list with class to represent a node and to initialize
PROGRAM NO.: 03 the head node, method to insert at begin, deletion at begin, to print the elements
in the doubly linked list.
Suppose an initially empty doubly linked list has executed a total of 8 insertion
operations, 5 deletion operations. What is the output after these operations?

Python Code:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 Page |6

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 Page |7

Implementation of Stack Data Structure using append


DATE: 25/07/2024 and pop functions
Devise a script to implement stack data structure. Display the values when the
PROGRAM NO.: 04 following series of operations are performed upon an initially empty stack:
Insert the data 2, 12, size of the stack, delete a data, display the stack, insert 42,
62, 32, 92, delete three data from the stack, find the size of the stack, display the
stack, insert 52, 72 delete the first three from the stack, find the size of the stack,
display the stack.

Python code:

INPUT:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 Page |8

OUTPUT:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 Page |9

Implementation of Stack Data Structure


DATE: 29/08/2024
Create a class to represent stack data structure. Include class methods to for
insertion and deletion of elements in a stack data structure.
PROGRAM NO.: Insert the data 67, 97, 17, 7, find the size of the stack, insert the data 27, 57, 47,
05 87, display the stack, delete the first four data from the stack, find the size of the
stack, insert the data 57, 37, find the size of the stack, display the stack.

Python code:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 10

Creation of Heap using Algorithm Heapify


DATE: 30/08/2024

Formulate a script to create a heap represented by an array a [0 : n] and execute


PROGRAM NO:6 the code on a[0 : 9] = (63, 3, 93, 103, 13, 23, 83, 53, 43, 73).

Python code:

INPUT:

OUTPUT:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 11

Insertion into a Heap Data Structure


DATE: 30/08/2024

Design a code to insert an element into a heap. Use the code to insert the data 25,
PROGRAM NO:7 13 into the heap represented by a[0 : 7] = (30, 17, 20, 15, 10, 12, 5, 1).

Python code:

Input:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 12

DATE: 30/08/2024
Creating a Heap using Algorithm Insert
Design a code to form a heap using Algorithm Insert. Run the code on the data 45,
PROGRAM NO.: 8
5, 65, 25, 85, 55, 95, 15, 75.

Python code:

INPUT:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 13

Iterative and Recursive Technique


DATE: 30/08/2024

Give the code for finding the binomial coefficient in iterative and recursive form.
PROGRAM NO:9 What is the output when m = 15 and n = 5.

Python code (Recursive):

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 14

Divide and Conquer Paradigm: Search Algorithm


DATE:6/09/2024
Formulate a script for the Algorithm BinSearch(a, n, x) with functions to read the
elements of n elements of an array.
PROGRAM NO:10 Use the code to search the elements 4, 13, 120, 203 in the array a[0 : 15] = (3, 13,
23, 43, 53, 73, 83, 93, 103, 113, 123, 143, 153, 193, 203, 243).

Python code (Iterative):

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 15

python code:

Input:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 16

Divide and Conquer Paradigm: Search Algorithm


DATE:6/09/2024
Design a Python code for the following search algorithm:
PROGRAM NO:11

Suppose a [0 : 15] = (– 5, – 2, – 1, 0, 3, 5, 5, 8, 10, 13, 16, 18, 21, 29, 32, 39).
Applying Bin Srch (a, l, h, x) what would be the output when x = – 3, 3, 33.
Python code:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 17

Input:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 18

Partitioning the elements of the array


DATE:12/09/2024
Write a script for the following Algorithm Partition(a, m, p) with functions to
read the elements of n elements of an array.
PROGRAM NO:12

The output of the script must have the following details:


(i) Elements of the array a[0 : 12] = (71, 91, 101, 81, 61, 31, 41, 1, 11, 51,
21, 70).
(ii) Partitioning element
(iii)Position of the partitioning element
(iv) Array after partition.

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 19

Python code:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 20

Merging of Two Sorted Arrays


DATE:12/09/2024
Design a script in Python for Algorithm Merge( 𝑎1, 𝑎2, 𝑎). What is the outoput
when 𝑎1 = (25, 63, 89, 97, 115), 𝑎2 = (6, 17, 37, 90).
PROGRAM NO:13

Python code:

Input:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 21

Divide and Conquer Paradigm: Sorting the array by


DATE:12/09/2024 Partitioning
Design a code for the Algorithm Quicksort If a[1 : 10] = (96, 46, 16, 36, 106, 136,
PROGRAM NO:14 56, 26, 6, 86), then what would be the output? Your code must have a module
named Partition to divide the array.

Python code:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 22

Divide and Conquer Paradigm: Selecting the kth smallest


DATE:12/09/2024 number
Devise a Python code to select the 4th, 7th smallest element in the array a[1 : 13] =
PROGRAM NO:15 (90, 120, 10, 110, 20, 80, 150, 30, 70, 50, 90, 40, 60) using the following algorithm.
Import the module named Partition to find the partitioning element.

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 23

PYTHON CODE:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 24

Divide and Conquer Paradigm: Sorting Problem


DATE:12/09/2024
Design a code with import statement for the following algorithm:
PROGRAM
NO:16

Execute the code on the array a[1 : 11] = (111, 85, 16, 67, 34, 56, 44, 91, 125,
7, 11).

PYTHON CODE:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 25

Divide and Conquer Paradigm: Finding Maximum and


DATE:12/09/2024 Minimum
Give a code for Algorithm MaxMin. Use the code to find the maximum and
minimum value in the sequence 56, 12, 77, 99, 23, 10, 2, 97, 88, 34, 65.
PROGRAM NO:17

PYTHON CODE:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 26

Implementation of Array Data Structure Using Modules


DATE:12/09/2024
Created an array by importing an array module with elements 82, 32, 2, 52, 12,
PROGRAM NO:18 22. Use built-in methods to print the elements of the array, sort the elements,
inserts the elements {66, 86, 26} at the end of the array, length of the array.

Python CODE:

output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 27

Application of Array data structure


DATE:12/09/2024

Formulate a Python program to find the frequency of each element in an array


PROGRAM NO:19 A[0 : 11] = {5, 5, 15, 45, 65, 65, 75, 5, 15, 65, 45, 5} using array data structure.

PYTHON CODE:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 28

Application of Stack Data Structure


DATE:12/09/2024

Design a recursive method to reverse a string using stack data structure. Execute
PROGRAM NO:20 the code on the string ‘ssDeQwJIOffB’ then display the output.

PYTHON CODE:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 29

Applications of Deque Data Structure


DATE:12/09/2024
Formulate a code to check whether a string is palindrome or not using deque data
structure. Execute a code and display the outputs: ‘The given string is
PROGRAM NO:21 palindrome ‘ and ‘The given string is not a palindrome ‘ by taking relevant
inputs of size at-least 10 characters.

PYTHON CODE:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 30

DATE: 12/10/2024 Sorting using Heap Data Structure


Create a code for the following algorithm:

PROGRAM NO.: 22

Use the code to sort the array a[0 : 10] = (44, 14, 84, 104, 94, 54, 84, 24, 34, 124,
4) and produce the output.

PYTHON CODE:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 31

Implementation of Circular Queue Data Structure


DATE:12/09/2024
Formulate a program to implement circular queue data structure. Perform the
PROGRAM NO:23 following series operations on a circular queue which is initially empty:
enqueue(45), enqueue(105), dequeue(), dequeue(), dequeue( ), enqueue(25),
enqueue(5), display elements of the circular queue, enqueue(35), dequeue(),
enqueue(55), dequeue(), dequeue(),enqueue(75), enqueue(15), display elements
of the circular queue.
PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 32

Input:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 33

DATE: 19/09/2024 Operations on Binary Search Tree Data Structure


Design a code with import statement:
1. To search a data in a binary search tree.
2. To find the maximum and minimum value.
PROGRAM NO.: 24 3. To compute the height of the binary search tree.
Insert the following data 75, 95, 5, 135, 105, 15, 85, 25, 65, 45, 125. Perform the
operation search on the data 80, 35, 95, 135. Also, find the minimum and
maximum value, height of the binary search tree etc.

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 34

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 35

Output

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 36

DATE: 19/09/2024 Operations on Heap Data Structure: Deletion


For the following algorithm, design the Python code:

PROGRAM NO.: 25

Execute the code on the heap represented by a[0: 10] = (97, 87, 90, 77, 67, 80, 60,
57, 37, 7, 47) to delete the maximum element. Use import statement to load
definitions from a module.

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 37

Output

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 38

DATE: 19/09/2024 Implementation of Binary Search Tree Data Structure


Implement a binary search tree using class and objects concepts. Use the code to
PROGRAM NO.: 26 insert and display the following sequence of numbers: 150, 10, 25, 68, 181, 190,
83, 167, 41, 51, 169, 181, 5.

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 39

Input:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 40

DATE: 25/09/2024 Implementation of Dynamic Array Data Structure


Design a code with class named Dynamic array with constructor function with
attributes n (size of the array), capacity and to define the array with capacity,
methods to insert an element at a specific index, find size of the array, display the
elements, print the element stored at a specified index and to delete the elements
at the end of the array.
PROGRAM NO.: 27 Execute the code as follows:
(i) to insert the elements 75, 95, 105, 35, 5, 15, 25 into an empty array.
(ii) Print the element stored at 3rd position.
(iii) Find the size of the array.
(iv) Delete the last two elements of the array.
(v) Print the array.

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 41

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 42

Output

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 43

DATE: Techniques for Algorithm Design:


25/09/2024 Greedy Algorithm – Knapsack Problem
Develop a Python script implementing the Algorithm GreedyKnapsack. Determine the
optimal solution to the given knapsack instance using the script:
PROGRAM
For a collection {𝑎, 𝑏, 𝑐, 𝑑, 𝑒, 𝑓, 𝑔} of seven items with profit-weight values as
NO:28
𝑎: (20, 2), 𝑏: (16, 3), 𝑐: (10, 2), 𝑑: (11, 5), 𝑒: (18, 6), 𝑓: (22, 3), 𝑔: (48, 4) and the total
weight of the knapsack is 20.

PYTHON CODE:

Output

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 44

Techniques for Algorithm Design:


DATE:
04/10/2024 Dynamic Programming-Longest Common Subsequence
Problem
Create a program for longest common subsequence problem. Utilize the program to
PROGRAM determine the length and longest common subsequence of the strings:
NO:29
X = aaaabbbbbbbbaaabbba, Y = aabbbbaaabbaabbbaababa.

PYTHON CODE:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 45

DATE: Techniques for Algorithm Design:


04/10/2024 Backtracking: Sum of Subset Problem
Propose a code for the following algorithm.

PROGRAM NO:
30

Use the code to identify all feasible subsets of w that sums to m if w = {5, 10, 15, 17,
18, 20, 35, 40} and m = 80.

PYTHON CODE:

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 46

DATE: 04/10/2024 Huffman Coding


Propose a Python function that will produce a set of optimal Huffman codes for the
messages (M1, M2 ... M9) with relative frequencies (q1, q2 ... q9). Make the Huffman
PROGRAM NO:31
code for the messages if the relative frequencies (q1, q2 ... q9) = (3, 6, 9, 11, 23, 44,
50, 52, 60).

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 47

Output

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 48

DATE: 04/10/2024
Techniques for Algorithm Design:
Greedy Algorithm – Optimal Storage on Tapes Problem
Devise a Python program to determine the optimal storage on m tapes with the
minimum mean retrieval time if there are n programs, each of which is of length li,
1  i  n. Also, give a function for input and output statemnents.
PROGRAM NO:32
With the programs having lengths of 34, 55, 65, 12, 90, 47, 23, 11, 81, 72, 3, 16,
95, 6, 12, 61, 75, 62, 57, 39 employ the code to determine the optimal arrangement
for the 20 programs on the four tapes T0, T1, T2, T3 and T4.

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 49

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 50

DATE:
04/10/2024 Graph Traversal Technique: Depth First Search
Construct the depth-first search traversal algorithm's Python code.
Stretch a graph with 14 vertices and 20 edges and determine the spanning tree of the
PROGRAM
NO:33 graph

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 51

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 52

DATE: 04/10/2024
Techniques for Algorithm Design:
Greedy Algorithm – Single-Source Shortest Path Problem
Create a Python program to implement the specified algorithm:

PROGRAM NO.: 34

Compute the shortest path between the vertex d and every other vertex in the graph
by using the code.
c

a d
h

b g j
To any seven edges, assign the weights 4, 5, 5, 6, 7, 7, 8 and the additional 3 to each.

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 53

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 54

OUTPUT:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 55

Techniques for Algorithm Design:


DATE: 04/10/2024 Greedy Algorithm – Minimum Spanning Tree Problem
(Construction of minimum spanning tree using Algorithm Prim)
Build a script for Algorithm Prim. Construct a simple connected graph, weighted
graph with 11 vertices and 18 edges and assign weights 1, 1, 2, 4, 4, 6, 6, 7, 8, 8,
PROGRAM NO.:35 rest of the edges with 5. Identify one vertex as a start vertex and illustrate the
running of the code.

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 56

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 57

Techniques for Algorithm Design:


DATE: 04/10/2024 Greedy Algorithm – Minimum Spanning Tree Problem
(Construction of minimum spanning tree using Algorithm Kruskal)
Create a script in Python to implement the following algorithm.

PROGRAM NO.: 36

Employ the script to obtain a minimum cost spanning tree for the given connected
graph starting from the vertex h.

a
6 2
5 1
b o
3 6
2
7 3
1
c g 2 l
5
4 2
2 3 h 5
k
d 4 i 3 j

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 58

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 59

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 60

DATE:
04/10/2024 Tree Traversal Technique
Produce a Python program for inorder, postorder tripleorder traversal technique.
Employ import statement to insert modules from the object-oriented representation
PROGRAM binary search tree program which you created. If the input is 60, 40, 30, 90, 70, 80, 10,
NO.:37
4, 30, 29, 111, 95, 85, what would be the output.

PYTHON CODE:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI
24-PMT-032 P a g e | 61

Output:

PMT1MC05  DATA STRUCTURES AND ALGORITHMS USING PYTHON – LAB 


DEPARTMENT OF MATHEMATICS  LOYOLA COLLEGE, CHENNAI

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy