Download Lab Manual Algorithm Design (Pr) COT

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Factorization of polynomials over finite fields wikipedia , lookup

Halting problem wikipedia , lookup

Transcript
Lab Manual
Algorithm Design (Pr)
COT- 311
L
T P
-
Practical exam:
- 3
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)
Implement the ascending and desending order using Quick Sort.
Finding kth minimum and maximum element in Heap.
Implement Quick Sort using first/last/any random element as pivot.
Build Min heap, Max heap and sort the given elements.
(b)
III.
Implement
Quick
(a)
array/elements.
Sort
with
duplicate
numbers
in
the
given
Delete kth indexed element in Min heap and Max heap.
(b)
Experiment 2(Dynamic Programming)
I. (a)
(b)
Implement the matrix chain multiplication problem.
Find
the
Longest
palindromic
subsequence
(Hint:
Subsequence
is
1
obtained by deletingsome of the characters from a string without
reordering the remaining characters, which
is also a palindrome).
II. (a)
Find optimal ordering of matrix multiplication.
Find the longest common substring (Input: Character string as in book
or binary matrix of 0 and 1. Output: longest sequence of 1's either row
(b)
wise or column wise).
Experiment 3(Greedy Algorithms)
I. (a)
(b)
Implement the file or code compression using Huffman’s algorithm.
You are given n events where each takes one unit of time. Event i will
provide a profit of gi dollars (gi> 0) if started at or before time ti where
ti is an arbitrary real number. (Note: If an event is not started by ti then
there is no benefit in scheduling it at all. All events can start as early
as time 0).
(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)
Implement the file or code compression using Huffman’s algorithm.
Consider the following scheduling problem. You are given n jobs. Job i
2
(b)
is specified by an earliest start time si, and a processing time pi. We
consider a preemptive version of the problem where a job's execution
can be suspended at any time and then completed later. For example if
n = 2 and the input is s1 = 2, p1 = 5 and s2 = 0, p2 = 3, then a
legalpreemptive schedule is one in which job 2 runs from time 0 to 2
and is then suspended.Then job 1 runs from time 2 to 7 and secondly,
job 2 is completed from time 7 to 8. The
goal is to output a schedule that minimizes ∑Cj = 1, where Cj is the
time when job j iscompleted and j runs from 1 to n. In the example
schedule given above, C1 =7 and C2 =8.
Implement the activity-selection problem ( You are given n activities with
(c)
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} ).
Experiment 4(Binary Search Tree)
I. (a)
Finding the maximum and minimum element in BST.
Finding
Kth smallest/largest element in BST.
(b)
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
3
and K2 (Input: BST and two numbers K1 and K2).
IV.
Write a program for removing the duplicates in array using BST.
Experiment 5(Binary Tree)
I.
Write a program to build a binary tree for the given elements (i.e.,
integers) and give traversal functions: inorder, preorder, postorder.
II.
Write a program to transform given a tree into a binary tree.
III.
Write a program to represent an arithmetic expression in binary tree
format.
Experiment 6 (Graph Algorithms)
I. (a)
Find Minimum Cost Spanning Tree of a given undirected graph using
Kruskal’s algorithm.
Implement the algorithm for Hash Tables to check both arrays have
(b)
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
Prim’s algorithm.
Implement the algorithm for Hash Tables to removing the duplicate
(b)
characters/numbers (Input as an array of characters/numbers).
III.
Find Minimum Cost Spanning Tree of a given undirected graph using
4
Kruskal’s algorithm.
(a)
Give an algorithm for finding non repeated character in a string/number
using Hash Tables. Example: the first non repeated character in the
(b)
string “abbcc” is ‘a’.
Experiment 7 (Shortest Path Finding in Graph)
I.
(a) 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,
(b)
such that graph contains minimum weight cycle with at least 4 edges.
II. (a)
Draw simple, connected weighted graph with 8 vertices and 16 edges,
Show that the Bellman-Ford algorithm find this cycle.
each withunique edge weight. Identify one vertex as a start vertex and
obtain shortest path usingDijkstra's algorithm.
From a given vertex in a weighted connected graph, find shortest paths
(b)
to othervertices using Bellman-Ford algorithm.
III.
Find the kth shortest path between two given nodes of a graph.
(a)
Give an algorithm to determine whether a directed graph with positive
(b)
and negative
cost edges has negative cost cycle.
Experiment 8 (All Pair’s Shortest Paths)
I.
(a) Implement all pair’s Shortest Paths Problem using Floyd’s-Warshall
5
algorithm.
Implement all pair’s Shortest Paths Problem using Johnson’s algorithm.
(b)
Experiment 9 (BFS and DFS problems)
I. (a)
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.
(b)
II. (a)
Check whether a given graph is connected or not using DFS method.
Find the strongly connected components in a digraph.
(b)
Experiment 10 (Flow and Sorting Networks)
I. (a)
Implement the Ford-Fulkerson method for maximum flow network.
Implement the Maximum bipartite matching problem in the graph.
(b)
Implement the Bitonic sorting algorithm.
(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 <
6
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.
Given key in a sorted array A with distinct values. Find i, j, k such that
A[i] + A[j] + A[k] == key
V.
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 algorithm for finding that missing number.
Additional Problem 2 (Dynamic Programming & Greedy Algorithms)
I.
Implement the job sequencing with deadlines problem using the fixed
tuple size formulation.
II. (a)
Implement the algorithm to compute roots of optimal sub-trees.
Implement the optimal binary search tree problem.
(b)
III.
Write an algorithm for partitioning problem. Partition problem is to
(a)
determine whether a given set can be partitioned into two subsets such
7
that the sum of elements in both subsets is same.
Find a subset of a given set S = {S1, S2,..…., Sm} of n positive integers
(b)
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.
Given a value N, if we want to make change for N cents, and we have
(c)
infinite supply of each of S = {S1, S2,..…., Sm} valued coins, how many
ways can we make the change? The order of coins doesn’t 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.
Perform the following operations on B-Tree:
a) Creation
b) Insertion.
c) Deletion.
d) Searching.
II.
Implement the conversion of the BST to B-tree.
III.
Perform the following operations on Binomial heaps:
a) Creation
8
b) Insertion.
c) Deletion.
d) Searching.
e) Uniting two Heaps
f) Extracting the minimum node
IV.
Perform the following operations on Fibonacci heaps:
a) Creation
b) Insertion.
c) Deletion.
d) Searching.
e) Uniting two Heaps
f) Extracting the minimum node
Additional Problem 4
I.
(Graph Algorithms)
Perform the following operations on Disjoint set:
a) MAKE-SET
b) UNION
c) FIND-SET
d) INSERT
e) DELETE
f) SPLIT
g) Returns the minimum object in SET
II.
Perform the following Union-by-Weight operations on a universe of 10
elements (0-9, each initially in their own set). Draw the forest of trees
9
that result. U(1,5); U(3,7); U(1,4);U(5,7); U(0,8); U(6,9); U(3,9). If the
sets have equal weight, use the root with the smaller value as the root
of the new set.
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.
Implement N Queen's problem.
II.
Implement Sudoku problem.
III.
Design an efficient solution for tower of Hanoi problem.
IV.
Implement 0/1 Knapsack problem.
V
Implement the travelling salesman problem (TSP).
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
10
in two pieces of lengths 2 and 6)
Length
| 1
2
3
4
5
6
7
8
17
17
20
----------------------------------------------------Price
| 1
5
8
9
VII
Implement the Coin change problem.
VIII.
Design the Graph coloring problem
10
11