DAALab Manual DSE Feb 2023
DAALab Manual DSE Feb 2023
Course Name & code : Design and Analysis of Algorithms Lab & DSE-2264
No of contact hours/week: L T P C
0 0 3 1
No. of
At the end of this course, the student should be able to: Contact Marks
Hours
CO1: Ability to design one or more algorithms for a problem using appropriate 12
data structures
CO2: Convert the algorithm into a program which is efficient 12
Total
(Page 1 of 5) MIT/GEN/F-01/R1
ASSESSMENT PLAN
Course
L. No. Topics Outcomes
Addressed
LAB- 1
L1.1) Write an algorithm and program to implement a doubly linked list which
supports
the following operations
i. Create the list by adding each node at the front
ii. Insert a new node to the left of the node whose key value is read as an
input.
iii. Delete all occurrences of a given key, if it is found. Otherwise, display
appropriate message
iv. Search a node based on its key value
v. Display the contents of the list
L1.2). Write a program to construct a binary tree to support the following
operations.
Assume no duplicate elements while constructing the tree. CO1, CO2,
i. Given a key, perform a search in the binary tree. If the key is found then CO3
display “key found” else inserts the key in the BST.
ii. Display the tree using inorder, preorder and post order traversal methods
L1.3). Write a program to implement the following graph representations.
i. Adjacency list
ii. Adjacency matrix
Additional Questions: -
L1. a) Repeat problem given in solved exercise using singly linked list.
L1. b) Write a program to implement Stack and Queue using circular doubly
linked list.
(Page 2 of 5) MIT/GEN/F-01/R1
LAB- 2
L2. 1) Write an algorithm for finding the Greatest Common Divisor (GCD) of two
numbers using Euclid’s algorithm. Write a program to implement the Euclid’s
algorithm.
L2. 2) Write a program to find GCD using consecutive integer checking method
and analyze its time efficiency.
L2. 3) Write a program to find GCD using middle school method and analyze its
time efficiency.
Additional Questions:
L2. a) Write a program for computing ⌊√n ⌋ for any positive integer and analyze its
time efficiency. Besides assignment and comparison, your program may only use
the four basic arithmetic operations.
L2. c) Write a program to compute the nth Fibonacci number recursively and
analyze its time efficiency.
(Page 3 of 5) MIT/GEN/F-01/R1
LAB-3
L3. 1) Write a program to sort a set of integers using selection sort algorithm and
analyze its time efficiency.
L3. 2)Write a program to sort set of integers using bubble sort. Analyze its time
efficiency.
L3. 3)Write a program to implement brute-force string matching. Analyze its time
efficiency.
L3. 4) Write a program to implement matrix multiplication using brute-force
technique and analyze its time efficiency.
Additional Questions:
L4. 3) Write a program for depth-first search of a graph. Identify the push and pop
order of vertices.
Additional Questions:
(Page 4 of 5) MIT/GEN/F-01/R1
ii) BFS to check for bipartite
Note: A graph is said to be bipartite if all its vertices can be partitioned into two
disjoint subsets X and Y so that every edge connects a vertex in X with a vertex in
Y.
L4. c) Write a program to construct a graph for the following maze. One can
model a maze by having a vertex for a starting point, a finishing point, dead ends,
and all the points in the maze where more than one path can be taken, and then
connecting the vertices according to the paths in the maze. Also find the solution to
the maze using Depth-First-Search.
(Page 5 of 5) MIT/GEN/F-01/R1
LAB-5
CO1, CO2,
CO3
L5. 1) Write a program to sort a set of numbers using insertion sort and analyze its
time efficiency.
L5. 2) Write a program to determine the Topological sort of a given graph using:
i) Depth-First technique
ii) Source removal technique
L5. 3) Write a program to find diameter of a binary tree. Diameter of a binary tree
is the longest path between any two nodes.
For e.g. consider the following two binary trees.
The diameter in each tree is 9. In the first one, longest path passes through root
whereas in the second it does not.
Additional Questions:
L5. b) Modify the algorithm such that it checks whether there is any task
dependency between the teams.
L5. c) Write a program in C to generate Fibonacci numbers upto n where n is a
positive integer.
L5. d) Write a program in C to reverse a queue.
(Page 6 of 5) MIT/GEN/F-01/R1
LAB-6
L6. 1) Write a program to sort given set of integers using Quick sort and analyze
its efficiency.
L6. 2) Write a program to sort given set of integers using Merge sort and analyze
its efficiency.
L6. 3) Write a program to determine the height of a binary search tree and analyze
its time efficiency.
L6. 4) Find total number of nodes in a binary tree and analyze its efficiency.
CO1, CO2,
CO3
Additional Questions:
L6. a) Write a program to find an where n > 0 using divide and conquer strategy.
L6. c) Write a program to find the total number of nodes in a binary tree and
analyze its efficiency. Obtain the experimental result of order of growth and plot
the result.
LAB-7
L7. 1) Write a program to create a binary search tree and display its elements using
all the traversal methods and analyse its time efficiency.
L7. 2) Write a program to create a AVL tree for a set of integers and analyze its CO1, CO2,
time efficiency. For the AVL tree created, insert an element 6. CO3
Additional Questions:
L7. a) For the AVL tree created in exercise 1 above, insert an element 6
(Page 7 of 5) MIT/GEN/F-01/R1
LAB-8
L8. 1) Write a program to sort the list of integers using heap sort with bottom-up max
heap construction and analyze its time efficiency. Prove experimentally that
the worst-case time complexity is O (n log n)
L8. 2) Write a program to create a heap for the list of integers using top-down heap
construction algorithm and analyse its time efficiency.
L8. 3) Write a program to sort the list of integers using heap sort technique and
analyse its time efficiency.
L8. 4) Write a program for finding and deleting an element of the smallest value in a
heap.
Additional Questions:
L8. a) Write a program to check whether an array H[1..n] is a heap or not
L8. b) Write a program for finding and deleting an element of a given value in a
heap.
LAB-9
L9. 1) Write a program to sort set of integers using comparison counting algorithm. CO1, CO2
L9. 2) Write a program to implement Horspool’s algorithm for String Matching and
find the number of key comparisons in successful search and unsuccessful search.
L9. 3) Write a program to construct the Open hash table. Find the number of key
comparisons in successful search and unsuccessful search.
Additional Questions:
L9. a) Write a program to construct the closed hash table. Find the number of key
comparisons in successful search and unsuccessful search.
L9. c) Write a program to sort the elements using distribution counting method.
(Page 8 of 5) MIT/GEN/F-01/R1
LAB-10
L10. 2) Write a program to compute the transitive closure of a given directed graph
using Warshall's algorithm and analyse its time efficiency.
CO1, CO2,
L10. 4) Write a program to implement 0/1Knapsack problem using bottom-up CO3
dynamic programming.
Additional Questions:
L10. b) Write a program that finds the composition of an optimal subset from the
table generated by the bottom-up dynamic programming algorithm for the
knapsack problem.
(Page 9 of 5) MIT/GEN/F-01/R1
LAB-11
L11. 1) Write a program to find Minimum Cost Spanning Tree of a given undirected
graph using Prim’s algorithm.
L11. 2) Write a program to find Minimum Cost Spanning Tree of a given undirected
graph using Kruskal's algorithm and analyse its time efficiency.
L11. 3) Write a program to find shortest path from a given vertex to other vertices
in a given weighted connected graph, Using Dijkstra’s algorithm and analyse its
time efficiency. CO1, CO2,
CO3
Additional Questions:
L11. b) Write a program to find a maximum spanning tree – a spanning tree with
the largest possible edge weight of a weighted connected graph.
L11. c) Write a program to implement the greedy algorithm for the change-making
problem, with an amount n and coin denominations d1 > d2 > ... > dm as its input.
LAB-12
L12. 2) Write a program to find the solution to the subset-sum problem for
S= {1, 2, 5, 6, 8} and d=9, using backtracking.
CO1, CO2
Additional Questions:
L12. a) Write a program for finding Hamiltonian circuit for the graph, using
backtracking.
(Page 10 of 5) MIT/GEN/F-01/R1
L12. b) Write a program to implement assignment problem using Branch and
Bound.
References:
1. Anany Levitin, Introduction to The Design and Analysis of Algorithms, 3rd Edition, Pearson
Education, India, 2012.
2. Ellis Horowitz, SartajSahni, Dinesh Mehta, Fundamentals of Data Structures in C++, 2nd Edition,
GalgotiaPublications, Reprint 2013
3. Thomas H. Cormen, Charles E. Leiserson, Ronal L, Rivest, Clifford Stein, Introduction to
Algorithms, Phi, 2nd Edition, 2006.
Date:
Approved by:
(Signature of HOD)
Date: 30-02-2023
(Page 11 of 5) MIT/GEN/F-01/R1
*********
(Page 12 of 5) MIT/GEN/F-01/R1