Lab Manual. Algorithms Design (Pr) COT-311

Similar documents
2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Exam study sheet for CS2711. List of topics

PES Institute of Technology-BSC QUESTION BANK

Data Structures and Algorithms Written Examination

International Journal of Software and Web Sciences (IJSWS)

IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*

Solutions to Homework 6

Warshall s Algorithm: Transitive Closure

Sample Questions Csci 1112 A. Bellaachia

10CS35: Data Structures Using C

Mathematics for Algorithm and System Analysis

Lab Manual. Data Structures (Pr): COT-213 Data Structures (P): IT-215

V. Adamchik 1. Graph Theory. Victor Adamchik. Fall of 2005

Any two nodes which are connected by an edge in a graph are called adjacent node.

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

DATA STRUCTURES USING C

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

Binary Search Trees CMPSC 122

Data Structure [Question Bank]

Social Media Mining. Graph Essentials

Lab Manual. Advanced Pr I IT 314

International Journal of Advanced Research in Computer Science and Software Engineering

Data Structures Fibonacci Heaps, Amortized Analysis

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Why? A central concept in Computer Science. Algorithms are ubiquitous.

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Approximation Algorithms

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Converting a Number from Decimal to Binary

Linear Programming. March 14, 2014

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Ordered Lists and Binary Trees

Dynamic Programming. Lecture Overview Introduction

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

Java Software Structures

Scheduling Shop Scheduling. Tim Nieberg

CS711008Z Algorithm Design and Analysis

Algorithm Homework and Test Problems

Introduction to Algorithms. Part 3: P, NP Hard Problems

Discrete Mathematics Problems

Analysis of Algorithms, I

CMPSCI611: Approximating MAX-CUT Lecture 20

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. Course Curriculum. DATA STRUCTURES (Code: )

Chapter 6: Graph Theory

MATHEMATICS Unit Decision 1

An Introduction to APGL

ML for the Working Programmer

Part 2: Community Detection

CS 2302 Data Structures Spring 2015

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

5.1 Bipartite Matching

Diversity Coloring for Distributed Data Storage in Networks 1

One last point: we started off this book by introducing another famously hard search problem:

CS311H. Prof: Peter Stone. Department of Computer Science The University of Texas at Austin

Binary Heaps. CSE 373 Data Structures

Complexity Theory. IE 661: Scheduling Theory Fall 2003 Satyaki Ghosh Dastidar

Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs

Discrete Mathematics & Mathematical Reasoning Chapter 10: Graphs

OPTIMAL DESIGN OF DISTRIBUTED SENSOR NETWORKS FOR FIELD RECONSTRUCTION

Algorithms and data structures

Problem Set 7 Solutions

Lecture 18: Applications of Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

I PUC - Computer Science. Practical s Syllabus. Contents

Midterm Practice Problems

Lecture 7: NP-Complete Problems

Data Structures. Level 6 C Module Descriptor

GRAPH THEORY LECTURE 4: TREES

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

Binary Search Trees (BST)

5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1

Class Notes CS Creating and Using a Huffman Code. Ref: Weiss, page 433

Handout #Ch7 San Skulrattanakulchai Gustavus Adolphus College Dec 6, Chapter 7: Digraphs

Data Structures. Chapter 8

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

Exercises Software Development I. 11 Recursion, Binary (Search) Trees. Towers of Hanoi // Tree Traversal. January 16, 2013

Network (Tree) Topology Inference Based on Prüfer Sequence

Max Flow, Min Cut, and Matchings (Solution)

ONLINE DEGREE-BOUNDED STEINER NETWORK DESIGN. Sina Dehghani Saeed Seddighin Ali Shafahi Fall 2015

To My Parents -Laxmi and Modaiah. To My Family Members. To My Friends. To IIT Bombay. To All Hard Workers

Dynamic programming. Doctoral course Optimization on graphs - Lecture 4.1. Giovanni Righini. January 17 th, 2013

Data Structures and Algorithms

Answer: (a) Since we cannot repeat men on the committee, and the order we select them in does not matter, ( )

Analysis of Algorithms I: Binary Search Trees

Euler Paths and Euler Circuits

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

The number of marks is given in brackets [ ] at the end of each question or part question. The total number of marks for this paper is 72.

Big O and Limits Abstract Data Types Data Structure Grand Tour.

1/18/ year Ph.D. student internships in. Done job hunting recently. Will join Yahoo! Labs soon. Interviewed with

CSE 4351/5351 Notes 7: Task Scheduling & Load Balancing

Symbol Tables. Introduction

Decision Mathematics D1 Advanced/Advanced Subsidiary. Tuesday 5 June 2007 Afternoon Time: 1 hour 30 minutes

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Bicolored Shortest Paths in Graphs with Applications to Network Overlay Design

Guessing Game: NP-Complete?

1 Introduction. Dr. T. Srinivas Department of Mathematics Kakatiya University Warangal , AP, INDIA

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

Binary Trees and Huffman Encoding Binary Search Trees

Transcription:

Lab Manual Algorithms Design (Pr) COT-311

Lab Instructions Several practicals / programs? Whether an experiment contains one or several practicals /programs One practical / program Lab Teacher forms groups of the students based on All Students need to perform the practical/program Assign all practicals /programs among all groups 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 Whether practical has been verified and signed by the lab teacher?? If a student has not completed a practical, he/she is expected to complete it at his/her own with the help of his/her fellow students in his/her hostel The student completes the practical file and submits it to the concerned teacher in his/her office or mail box on next working day 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.

L T P - - 3 Lab Manual Algorithm Design (Pr) COT- 311 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) Implement the ascending and desending order using Quick Sort. Finding k th 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. I Implement Quick Sort with duplicate numbers in the given array/elements. Delete k th indexed element in Min heap and Max heap. Experiment 2 (Dynamic Programming) I. (a) Implement the matrix chain multiplication problem. Find the Longest palindromic subsequence (Hint: Subsequence is obtained by deleting some of the characters from a string without reordering the remaining characters, which is also a palindrome). 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 wise or column wise). Experiment 3 (Greedy Algorithms) I. (a) 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 g i dollars (g i > 0) if started at or before time t i where t i is an arbitrary real number. (Note: If an event is not started by t i then there is no benefit in scheduling it at all. All events can start as early as time 0). 1

(c) (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} ). Implement the file or code compression using Huffman s algorithm. Consider the following scheduling problem. You are given n jobs. Job i is specified by an earliest start time s i, and a processing time p i. 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 s 1 = 2, p 1 = 5 and s 2 = 0, p 2 = 3, then a legal preemptive 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 C j = 1, where C j is the time when job j is completed and j runs from 1 to n. In the example schedule given above, C 1 =7 and C 2 =8. 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} ). Experiment 4 (Binary Search Tree) I. (a) II. III. IV. Finding the maximum and minimum element in BST. Finding K th smallest/largest element in BST. Write a program for converting the array to BST (Input: Unsorted/Sorted array). Write a program for printing all the elements of BST in the range K1 and K2 (Input: BST and two numbers K1 and K2). 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. 2

II. III. Write a program to transform given a tree into a binary tree. Write a program to represent an arithmetic expression in binary tree format. Experiment 6 (Graph Algorithms) I. (a) I 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 same set of numbers/characters (Input: given two arrays of unordered numbers/characters). Find Minimum Cost Spanning Tree of a given undirected graph using Prim s algorithm. Implement the algorithm for Hash Tables to removing the duplicate characters/ numbers (Input as an array of characters/numbers). Find Minimum Cost Spanning Tree of a given undirected graph using Kruskal s algorithm. 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. 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, 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. I Find the k th shortest path between two given nodes of a graph. Give an algorithm to determine whether a directed graph with positive and negative cost edges has negative cost cycle. 3

Experiment 8 (All Pair s Shortest Paths) I. (a) Implement all pair s Shortest Paths Problem using Floyd s-warshall algorithm. Implement all pair s Shortest Paths Problem using Johnson s algorithm. 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. 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) (c) Implement the Ford-Fulkerson method for maximum flow network. Implement the Maximum bipartite matching problem in the graph. Implement the Bitonic sorting algorithm. 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 = {a 1, a 2, a 3,..., a n }, and a i > a j and i < j II. III. 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. 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 4

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. Implement the algorithm to compute roots of optimal sub-trees. Implement the optimal binary search tree problem. I 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. (c) Find a subset of a given set S = {S 1, S 2,..., S m } 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. Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = {S 1, S 2,..., S m } 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. III. Implement the conversion of the BST to B-tree. Perform the following operations on Binomial heaps: a) Creation b) Insertion. c) Deletion. d) Searching. 5

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 (Graph Algorithms) I. 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 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. IV. 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. 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. I. Implement N Queen's problem. Additional Problem 5 (Other Techniques) II. Implement Sudoku problem. 6

III. IV. V VI. VII VIII. Design an efficient solution for tower of Hanoi problem. Implement 0/1 Knapsack problem. Implement the travelling salesman problem (TSP). 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 Implement the Coin change problem. Design the Graph coloring problem 7