Professional Documents
Culture Documents
Lab Instructions
Whether an experiment contains one or
several practicals /programs
Several
practicals / programs
One
practical / program
All Students need to perform the
practical/program
Teacher decides whether the completed practicals / programs can be appropriately described
using flow chart, algorithm, query statement, etc.
Teacher issues necessary instructions to the students for writing practicals / programs
accordingly
Students write experiments in practical files and get them signed by the lab teacher
Students make entries in the list of contents of the practical files and get them signed by
the lab teacher
In case of an experiment containing several practicals, a lab teacher needs to think whether a
practical performed by the students in one group needs to be repeated by the other groups in lab on
the same day?
OR
A practical performed by the students in one group needs to be repeated as assignments to be
completed by the students of other groups in their hostels? Here, an assignment includes both
executing a program on computer and also writing the same in practical file.
OR
A practical performed by the students in one group needs to be repeated as assignments, only
writing practicals in their practical files, for the students of other groups in their hostels?
Teacher issues necessary instructions to the students accordingly.
Lab Manual
Algorithm Design (Pr)
COT- 311
L T P
- - 3
Practical exam: 40
Sessional: 60
Note: Implement the following using C/C++ programming language on LINUX or Windows like
platform.
Experiment 1 (Quick and Heap sort)
I. (a)
(b)
II. (a)
(b)
III. (a) Implement Quick Sort with duplicate numbers in the given array/elements.
(b) Delete kth indexed element in Min heap and Max heap.
Experiment 2 (Dynamic Programming)
I. (a)
(b)
II. (a)
(b)
(c)
Implement the activity-selection problem ( You are given n activities with their start and
finish times. Select the maximum number of activities that can be performed by a single
person, assuming that a person can only work on a single activity at a time.
Example: Consider the following 6 activities.
start[] = {1, 3, 0, 5, 8, 5}; finish[] = {2, 4, 6, 7, 9, 9};
The maximum set of activities that can be executed by a single person is {0, 1, 3, 4} ).
II. (a)
(b)
(c)
II.
Write a program for converting the array to BST (Input: Unsorted/Sorted array).
III.
Write a program for printing all the elements of BST in the range K1 and K2 (Input:
BST and two numbers K1 and K2).
IV.
Write a program to build a binary tree for the given elements (i.e., integers) and give
traversal functions: inorder, preorder, postorder.
II.
III.
I. (a)
(b)
Find Minimum Cost Spanning Tree of a given undirected graph using Kruskals
algorithm.
Implement the algorithm for Hash Tables to check both arrays have same set of
numbers/characters (Input: given two arrays of unordered numbers/characters).
II. (a)
Find Minimum Cost Spanning Tree of a given undirected graph using Prims algorithm.
(b)
Implement the algorithm for Hash Tables to removing the duplicate characters/ numbers
(Input as an array of characters/numbers).
III. (a) Find Minimum Cost Spanning Tree of a given undirected graph using Kruskals
algorithm.
(b) Give an algorithm for finding non repeated character in a string/number using Hash
Tables. Example: the first non repeated character in the string abbcc is a.
II. (a)
(b)
From a given vertex in a weighted connected graph, find shortest paths to other vertices
using Dijkstra's algorithm.
Draw simple, connected weighted graph with 10 vertices and 18 edges, such that graph
contains minimum weight cycle with at least 4 edges. Show that the Bellman-Ford
algorithm find this cycle.
Draw simple, connected weighted graph with 8 vertices and 16 edges, each with unique
edge weight. Identify one vertex as a start vertex and obtain shortest path using
Dijkstra's algorithm.
From a given vertex in a weighted connected graph, find shortest paths to other vertices
using Bellman-Ford algorithm.
III. (a) Find the kth shortest path between two given nodes of a graph.
(b)
Give an algorithm to determine whether a directed graph with positive and negative
cost edges has negative cost cycle.
I. (a)
(b)
II. (a)
(b)
Write an algorithm to print all the nodes reachable from a given starting node in a
digraph using BFS method.
Obtain the Topological ordering of vertices in a given digraph.
Check whether a given graph is connected or not using DFS method.
Find the strongly connected components in a digraph.
Experiment 10 (Flow and Sorting Networks)
I. (a)
(b)
(c)
Note: Additional Programs are for those students who wish to do advance problems
Additional Problem 1 (Data Structures)
I.
Write an algorithm for finding counting inversions in an array. Inversion is a pair such
that for an array A = {a1, a2, a3,...., an}, and ai > aj and i < j
II.
Given an array. Let us assume that there can be duplicates in the list. Write an algorithm
to search for an element in the list in such a way that we get the highest index if there
are duplicates.
III.
Write an algorithm for finding i and j in an array A for any key such that
A[j]2 + A[i]2 == key
IV.
V.
Given key in a sorted array A with distinct values. Find i, j, k such that
A[i] + A[j] + A[k] == key
Suppose an array A has n distinct integers. Increasing sequence is given as
A[1].........A[k] and decreasing sequence is given as A[k+1]........A[n]. Write an
algorithm for finding k.
VI.
You have 1 to N-1 array and 1 to N numbers and one number is missing. Write an
4
Implement the job sequencing with deadlines problem using the fixed tuple size
formulation.
II. (a)
(b)
III. (a) Write an algorithm for partitioning problem. Partition problem is to determine whether a
given set can be partitioned into two subsets such that the sum of elements in both
subsets is same.
(b)
Find a subset of a given set S = {S1, S2,..., Sm} of n positive integers whose sum is
equal to a given positive integer d. For example, if S = {1, 2, 5, 6, 8} and d = 9 there are
two solutions {1, 2, 6} and {1, 8}. A suitable message is to be displayed if the given
problem instance doesn't have a solution.
(c)
Given a value N, if we want to make change for N cents, and we have infinite supply of
each of S = {S1, S2,..., Sm} valued coins, how many ways can we make the change?
The order of coins doesnt matter. For example, for N = 4 and S = {1, 2, 3}, there are
four solutions: {1, 1, 1, 1}, {1, 1, 2}, {2, 2}, {1, 3}. So output should be 4. For N = 10
and S = {2, 5, 3, 6}, there are five solutions: {2, 2, 2, 2, 2}, {2, 2, 3, 3}, {2, 2, 6}, {2, 3,
5} and {5, 5}. So the output should be 5.
Additional Problem 3 (Advanced Data Structures)
I.
II.
III.
I.
II.
III.
Let G be a connected graph of order n. Write an algorithm for finding maximum number
of Cut-vertices that G can contain. Cut-vertex is a vertex which when removed from the
graph splits it into two disconnected components.
IV.
An Euler circuit for an undirected graph is a path that starts and ends at the same vertex
and uses each edge exactly once. A connected undirected graph G has an Euler circuit.
If and only If energy vertex is of even degree. Give an algorithm and implement to find
the Euler Circuit in a graph with e edges provided one exists.
Additional Problem 5 (Other Techniques)
I.
II.
III.
IV.
VI.
Given a rod of length n inches and an array of prices that contains prices of all pieces of
size smaller than n. Determine the maximum value obtainable by cutting up the rod and
selling the pieces. For example, if length of the rod is 8 and the values of different
pieces are given as following, then the maximum obtainable value is 22 (by cutting in
two pieces of lengths 2 and 6)
Length | 1 2 3 4 5 6 7 8
----------------------------------------------------Price | 1 5 8 9 10 17 17 20
VII
VIII.