Design & Analysis of Algorithm Lab - BVICAM

20
Laboratory Manual (Version 9.0) for Design & Analysis of Algorithm Lab (MCA-252) MCA-IV Semester Compiled by: Dr. Anupam Baliyan (Associate Professor, BVICAM, New Delhi) Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM) A-4, Paschim Vihar, Rohtak Road, New Delhi-63 Visit us at: www.bvicam.in

Transcript of Design & Analysis of Algorithm Lab - BVICAM

Page 1: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual (Version 9.0)

for

Design & Analysis of Algorithm Lab (MCA-252)

MCA-IV Semester

Compiled by:

Dr. Anupam Baliyan (Associate Professor, BVICAM, New Delhi)

Bharati Vidyapeeth’s

Institute of Computer Applications

and Management (BVICAM)

A-4, Paschim Vihar, Rohtak Road, New Delhi-63 Visit us at: www.bvicam.in

Page 2: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 2 of 20

Index

List of Abbreviations

Declaration

1. Vision of the Department 5

2. Mission of the Department 5

3. Programme Educational Objectives (PEOs) 5

4. Programme Outcomes (POs) 6

5. Institutional Policy for Students’ Conduct 7

6. Learning Outcomes of Laboratory Work 9

7. Course/Lab Outcomes (COs) 10

8. Mapping of COs with POs 10

9. Course/Lab Description 10

10. Grading Policy 11

11. Lesson Plan 11

12. Assignments 12

Page 3: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design & Analysis of Algorithm Lab. | Version (9.0)

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi |Page 3 of 20

List of Abbreviations

BTL Bloom’s Taxonomy Level

CE Communication Efficacy

CICP Conduct Investigations of Complex Computing Problems

CK Computational Knowledge

CO Course Outcome

DAC Departmental Advisory Committee

DDS Design and Development of Solutions

I&E Innovation and Entrepreneurship

I&T Individual & Team Work

IQAC Internal Quality Assurance Cell

LLL Life-Long Learning

MTU Modern Tool Usage

PA Problem Analysis

PE Professional Ethics

PEO Programme Educational Objective

PMF Project Management and Finance

PO Programme Outcome

SEC Societal and Envoirnmental Concern

Page 4: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 4 of 20

Declaration

Department : Department of Computer Science and Applications

Course, Year and the

Semester to which Lab is

offered

: MCA - II Year, IV Semester

Name of the Lab Course : Design & Analysis of Algorithm lab

Course Code : MCA-252

Version No. : 9.0

Name of Course/Lab

Teacher

: Dr. Anupam Baliyan

Laboratory Manual

Committee

: 1. Mrs. Vaishali Joshi, Chairperson

2. Dr. Anupam Baliyan, Member

3. Dr. Ritika Wason, Member

4. Mrs. Tanya Pathak Garg, Member

5. Mr. Uttam Singh Bist, Member

6. Prof. P. S. Grover, Margdarshak

7. Mr. Amit Sharma, Alumni &Industry Expert

8. Dr. Anupam Baliyan, Concerned Subject Teacher,

Convener

Approved by : DAC Date: 02/12/2019

Approved by : IQAC Date: 03/12/2019

Signature

(Course Teacher)

Signature

(Head of Department)

Signature

(IQAC Coordinator)

Page 5: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design & Analysis of Algorithm Lab. | Version (9.0)

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi |Page 5 of 20

1. Vision of the Department

To become a Centre of excellence in the field of Computer Science and Applications,

to contribute effectively in the rapidly changing global economy directed towards

national development ensuring prosperity for the mankind.

2. Mission of the Department

M1 To become a centre of excellence in the field of Computer Science and

Applications and produce professionals as per global industry standards.

M2 To foster innovation, entrepreneurial skills, research capabilities and bring

all-round development amongst budding professionals.

M3 To promote analytical and collaborative life-long learning skills, among

students and faculty members involving all stakeholders.

M4 To inculcate strong ethical values and professional behaviour while giving

equal emphasis to social commitment and nation building.

3. Programme Educational Objectives (PEOs)

The PEO’s for the MCA programme are as follows:

PEO1 Exhibit professional competencies and knowledge for being a successful

technocrat.

PEO2 Adopt creative and innovative practices to solve real-life complex problems.

PEO3 Be a lifelong learner and contribute effectively to the betterment of the

society.

PEO4 Be effective and inspiring leader for fellow professionals and face the

challenges of the rapidly changing multi-dimensional, contemporary world.

Page 6: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 6 of 20

4. Programme Outcome (POs)

PO1:

Computational Knowledge (CK)

Demonstrate competencies in fundamentals of computing, computing

specialisation, mathematics, and domain knowledge suitable for the

computing specialisation to the abstraction and conceptualisation of

computing models from defined problems and requirements.

PO2:

Problem Analysis (PA)

Identify, formulate, and analyze complex real-life problems in order to arrive

at computationally viable conclusions using fundamentals of mathematics,

computer sciences, management and relevant domain disciplines.

PO3: Design and Development of Solutions (DDS)

Design efficient solutions for complex, real-world problems to design

systems, components or processes that meet the specifications with suitable

consideration to public health, and safety, cultural, societal, and

environmental considerations.

PO4: Conduct Investigations of Complex Computing Problems (CICP)

Ability to research, analyze and investigate complex computing problems

through design of experiments, analysis and interpretation of data, and

synthesis of the information to arrive at valid conclusions.

PO5: Modern Tool Usage (MTU)

Create, select, adapt and apply appropriate technologies and tools to a wide

range of computational activities while understanding their limitations.

PO6: Professional Ethics (PE)

Ability to perform professional practices in an ethical way, keeping in mind

cyber regulations & laws, responsibilities, and norms of professional

computing practices.

PO7: Life-Long Learning (LLL)

Ability to engage in independent learning for continuous self-development

Page 7: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design & Analysis of Algorithm Lab. | Version (9.0)

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi |Page 7 of 20

as a computing professional.

PO8: Project Management and Finance (PMF)

Ability to apply knowledge and understanding of the computing and

management principles and apply these to one’s own work, as a member

and leader in a team, to manage projects in multidisciplinary environments.

PO9: Communication Efficacy (CE)

Ability to effectively communicate with the technical community, and with

society at large, about complex computing activities by being able to

understand and write effective reports, design documentation, make

effective presentations, with the capability of giving and taking clear

instructions.

PO10: Societal and Envoirnmental Concern (SEC)

Ability to recognize and assess societal, environmental, health, safety, legal,

and cultural issues within local and global contexts, and the consequential

responsibilities applicable to professional computing practices.

PO11: Individual & Team Work (I&T)

Ability to work in multi-disciplinary team collaboration both as a member

and leader as per need.

PO12: Innovation and Entrepreneurship (I&E)

Ability to apply innovation to track a suitable opportunity to create value

and wealth for the betterment of the individual and society at large.

5. Institutional Policy for Students’ Conduct The following guidelines shall be followed: -

5.1 All the students in their introductory Lab. shall be assigned a system, which

shall be their workplace for the complete semester. Students can store records

of all their Lab. assignments on their individual workstations.

Page 8: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 8 of 20

5.2 Introductory Lab. shall include an introduction to the appropriate

software/tool, followed by a basic Introductory Assignment having Practice

Questions. All the students areexpected to complete this assignment within a

week time, as the same shall be assessed through a lab. test.

5.3 Each week the instructor, in parallel to respective topics covered in the

theory lecture, shall assign a set of practical problems to the students in form

of Assignments (A, B, C, .....). The problems in these assignments shall be

divided into two parts. The first set of Problems shall be compulsory for all

the students and its record need to be maintained in the Prcatical File, having

prescribed format, as given in Appendix-A. All the students should get the

weekly assigntment checked and signed in the Practical File by the respective

teacher in the immediate succeeding week. The second set of problems

areAdvanced Problems and shall be optional. Student may solve these

advanced problems for their further practice.

5.4 Cellular phones, pagers, CD players, radios and similar devices are

prohibited in the classrooms, laboratories and examination halls.

5.5 Laptop-size computers / Tablets may be used in lectures for the purpose of

taking notes or working on team-projects.

5.6 The internal practical exam shall be conducted towards the end of the

semester and shall include the complete set of Lab exercises conducted as

syllabus. However, students shall be assessed on continuos basis through

overall performances in regular lab. tests, both announced and surprise and

viva-voce.

5.7 The respective faculty shall prepare and submit sufficient number of practical

sets of computing problems to the Dean (Examinations),atleast two weeks

prior to the actual exam.It is the responsibility of the faculty to ensure that a

set should not be repeated for more than 5 students in a given batch.

5.8 The exam shall be of 3 hours duration where the student shall be expected to

implement solutions to his/her assigned set of problems on appropriate

Page 9: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design & Analysis of Algorithm Lab. | Version (9.0)

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi |Page 9 of 20

software tools in the lab.

5.9 Once implemented, student shall also appropriately document code

implemented in the assigned answer sheets, which shall be submitted at the

end of the examination.All the students shall also appear for viva-voce

examination during the exam.

5.10 Co-operate, Collaborate and Explore for the best individual learning

outcomes but copying or entering into the act of plagiarism is strictly

prohibited.

6. Learning Outcomes of Laboratory Work

The student shall demonstrate the ability to:

Verify and Implement the concepts and theory learnt in class.

Code and use Software Tools to solve problems and present their optimal

solutions.

Apply numerical/statistical formulas for solving problems/questions.

Develop and apply critical thinking skills.

Design and present Lab as well as project reports.

Apply appropriate methods for the analysis of raw data.

Perform logical troubleshooting as and when required.

Work effectively as a member of a team in varying roles as need be.

Communicate effectively, both oral and written.

Cultivate ethics, social empathy, creativity and entrepreneurial mindset.

Page 10: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 10 of 20

7. Course/Lab Outcomes (COs) CO1 Evaluate correctness & efficiency of algorithms using inductive proofs and

invariants. (BTL5)

CO2 Discuss and perfom parameter-based analysis of the searching & sorting and tree-

based Algorithms. (BTL6)

CO3 Create and test optimal solutions using various algorithms for real-life problem.

(BTL6)

CO4 Apply logical thinking to build innovative solutions for real-life problems. (BTL3)

8. Mapping of COs with POs

Table 1: Mapping of COs with POs

PO/CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

CO1 3 3 - 2 2 3 - - - 3 - -

CO2 3 3 - 2 - 3 2 - - 3 - -

CO3 3 3 3 2 - 3 2 - - 3 - -

CO4 3 3 3 2 - 3 2 - - 3 - 2

9. Course/Lab Description

Course (Lab) Title : Design & Analysis of Algorithm Lab.

Course (Lab) Code : MCA-252

Credits : 01

Pre-requisites : Data Structure

Academic Session : January to June

Contact Hours/Week : 02(01 Lab of 02 hours /Week)

Internal Assessment : 40 Marks

Page 11: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design & Analysis of Algorithm Lab. | Version (9.0)

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi |Page 11 of 20

External Assessment : 60 Marks

10. Grading Policy

Item Points Marks Remarks

Weekly Lab Assignments

including Practical Files

10 10 Closed Book/Open Book

Internal End-Term Practical

Examination

20 10 Closed Book

Viva-Voce 20 20 Closed Book

External End-Term Examinations 60 60 Closed Book (conducted and

evaluated by the University)

Total 100

11. Lesson Plan

Week No.

Lab No.

Topics / Concepts to be Covered

Reference of Lab Manual

1. 1. Divide & Conquer Assignment A (Problem AP1 to AP5)

2. 2. Sorting and Searching Assignment B (Problem BP1 to BP6)

3. 3. Buffer reserved for revision Assignment A-B

4. 4. Greedy algorithms Assignment C (Problem CP1 to CP4)

5. 5. Greedy algorithms Assignment C (Problem CP5 to CP7)

6. 6. Buffer reserved for revision Assignment C

7. 7. Dynamic Programming Assignment D (Problem DP1 to DP3)

8. 8. Dynamic Programming Assignment D (Problem DP4 to DP5)

9. 9. Buffer reserved for revision Assignment D

10. 10. Pattern matching Assignment E (Problem EP1 to EP2)

11. 11. Pattern matching Assignment E (Problem EP3 to EP4)

Page 12: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 12 of 20

Week No.

Lab No.

Topics / Concepts to be Covered

Reference of Lab Manual

12. 12. Buffer reserved for revision Assignment E

13. 13. Backtracking & Branch and

Bound

Assignment F (Problem FP1 to FP3)

12. Assignments

AssignmentSet: A (Divide&Conquer)

Objectives of the Assignment:

Familiarize with the concept of Divide & Conquer.

Familiarize with problem solving using Divide & Conquer approach.

Test and execute the programs using C with correct syntax and logical errors.

Familiarize with the analysis of problems,solved by using Divide & Conquer

CO/BTLCovered: CO1 & CO2/BTL5 & BTL6

Problems:

AP1 Given a sorted array of integers, find index of first and last occurance of a given

number.If the element is not found in an array, report that as well.

AP2 Given a sorted array, find a given element in O (Log n) time.

AP3 Given an Array, find peack element in it.APeack elements is the element that is

greater than its neighbours.

AP4 Given an Array, find the number of inversions of it. If (i and A (i) >A (j)) then

the pair (i, j) is called the inversion of the array. We need to count all such pairs

of inversions of Array.

AP5 Given an array of integers, find the minimum and maximum elements persents

in it by doing minimum comparisions by using divide and conauer approach.

Advanced Problems:

AA1 Given many stacks of coins which are arranged adjacently. We need to collect all

these coins in the minimum number of steps where in one step we can collect

one horizontal line of coins or vertical line of coins and collected coins should be

Page 13: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design & Analysis of Algorithm Lab. | Version (9.0)

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi |Page 13 of 20

continuous.

AA2 Given an array arr[] of length N, the task is to find the sum of the maximum

elements of every possible sub-array of the array.

AA3 Given an array of strings arr[ ], the task is to find the largest string in the array

which is made up of the other strings from the array after concatenating one

after another. If no such string exists, then print -1.

AA4 Given an Array [ ] of N elements and a number K. ( 1 <= K <= N ) . Split the

given array into K sub – arrays (they must cover all the elements). The

maximum subarray sum achievable out of K sub-arrays formed, must be

minimum possible. Find that possible subarray sum.

AA5 Given an array of integers. The task is to rearrange elements of the array such

that no two adjacent elements in the array are same.

Assignment Set: B (Sorting&Searching)

Objectives of the Assignment:

Familiarize with the concept of Sorting and Searching.

Implement various type of sorting algorithm by Using C.

Study and understand some case study based on sorting and searching and

finally write the algorithms for the same with analysis.

CO/BTLCovered: CO1 & CO2/BTL5 & BTL6

Problems:

BP1 Given an array of integrs, sort it by using merger sort technique.

BP2 Sort an array iteratively and recursively by using bubble sort technique.

BP3 Given an array, use in place sorting that is much faster then merge sort and

heapsort.

BP4 Given an array of integers use stable in-place sorting that build the final sorted

array one at a time.

BP5 Given a collection of n items, each of which has a non-negative key whose

maximum value is at most k, efficitevly sort it by using counting sort.

BP6 Given an array of integers, sort it by building max or min heap.

Page 14: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 14 of 20

Advanced Problems:

BA1 Given an array A [ ] consisting 0s, 1s and 2s. The task is to write a function that

sorts the given array. The functions should put all 0s first, then all 1s and all 2s in

last.

BA2 Given two arrays: arr1 [0...m-1] and arr2 [0...n-1]. Find whether arr2 [ ] is a subset

of arr1[ ] or not. Both the arrays are not in sorted order. It may be assumed that

elements in both arrays are distinct.

BA3 Given an unsorted array, sort the given array. You are allowed to do only

following operation on array.

flip(arr, i): Reverse array from 0 to i

Unlike a traditional sorting algorithm, which attempts to sort with the fewest

comparisons possible, the goal is to sort the sequence in as few reversals as

possible.

BA4 Given two arrays A1 [ ] and A2 [ ], sort A1 in such a way that the relative order

among the elements will be same as those are in A2. For the elements do not

present in A2, append them at last in sorted order.

BA5 Given a sorted array and a number x, find a pair in array whose sum is closest to

x.

BA6 Given an array of strings arr[ ]. Sort given strings using Bubble Sort and display

the sorted array.

BA7 Given an array of “n”distinct elements, find the minimum number of swaps

required to sort the array.

BA8 We are given an array of n distinct numbers. The task is to sort all even-placed

numbers in increasing and odd-placed numbers in decreasing order. The

modified array should contain all sorted even-placed numbers followed by

reverse sorted odd-placed numbers.

BA9 Given three integers, print them in sorted order with¬out using if condition.

BA10 Given an array of positive integers. Sort the given array in decreasing order of

number of factors of each element, i.e., element having the highest number of

Page 15: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design & Analysis of Algorithm Lab. | Version (9.0)

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi |Page 15 of 20

factors should be the first to be displayed and the number having least number of

factors should be the last one. Two elements with equal number of factors should

be in the same order as in the original array.

Assignment Set: C (Greedy Algorithm)

Objectives of the Assignment:

Understand and apply the concept of Greedy-choice property (A global

optimum can be arrived at by selecting a local optimum) on problems.

Familarize the concept of Optimal substructure (An optimal solution to the

problem contains an optimal solution to subproblems) and apply it on

problem.

Identify the suitability of greedy approach for problems and design and test

algorithm for some problems those can be solved by using Greedy approach.

CO/BTLCovered: CO1 & CO3/BTL5 & BTL6

Problems:

CP1 Given a set of items, each with a weight and a value, determine the number of

each item to include in a collection so that the total weight is less than or equal to

a given limit and the total value is as large as possible.

CP2 Given a connected and undirected graph, find a minimum spanning tree that has

minimum cost.

CP3 Given a weighted undirected graph. Finds a subset of the edges that forms a tree

that includes every vertex, where the total weight of all the edges in the tree is

minimized by using prims approach.

CP4 Given a Graph, find a minimum spanning tree that takes a graph as input and

finds the subset of the edges of that graph which form a tree that includes every

vertex has the minimum sum of weights among all the trees.

CP5 Given a graph and a source vertex in the graph, find shortest paths from source

to all vertices in the given graph.

CP6 Given a schedule containing arrival and departure time of trains in a station, find

minimum number of platforms needed in the station so to avoid any delay in

Page 16: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 16 of 20

arrival of any train.

CP7 Given weights and values of n items, we need to put these items in a knapsack of

capacity W to get the maximum total value in the knapsack by using Greedy

approach.

Advanced Questions:

CA1 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.

CA2 Given an Array [ ] of N elements and a number K. (1 <= K <= N). Split the given

array into K sub – arrays (they must cover all the elements). The maximum

subarray sums achievable out of K sub-arrays formed, must be minimum

possible. Find that possible subarray sum.

CA3 Given a sorted array of positive integers where arr[i] > 2*arr[i-1], check whether a

sub sequence exists whose sum is equal to k.

CA4 A new variety of rice has been brought in supermarket and being available for

the first time, the quantity of this rice is limited. Each customer demands the rice

in two different packaging of size a and size b. The sizes a and b are decided by

staff as per the demand.

CA5 Given the size of the packets a and b, the total quantity of rice available d and the

number of customers n, find out maximum number of customers that can be

satisfied with the given quantity of rice

CA6 Display the total number of customers that can be satisfied and the index of

customers that can be satisfied.

Assignment Set: D (Dynamic Programming)

Objectives of the Assignment:

Identify the suitability of Dynamic Programming approach for a given

problem.

Understand and test Optimal Substructure and Overlapping subproblems.

Create and test Algorithms for some problems by using Dynamic

Programming.

Page 17: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design & Analysis of Algorithm Lab. | Version (9.0)

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi |Page 17 of 20

CO/BTLCovered: CO1 & CO3/BTL5 & BTL6

Problems:

DP1 Given a set of items, each with a weight and a value, determine the number of

each item to include in a collection so that the total weight is less than or equal to

a given limit and the total value is as large as possible.

DP2 Given a graph and a source vertex srcin graph, find shortest paths from srcto all

vertices in the given graph. The graph may contain negative weight edges.

DP3 For a weighted directed Graph, find shortest distances between every pair of

verticesi.

DP4 Given a sequence of matrices, find the most efficient way to multiply these

matrices together. The problem is not actually to perform the multiplications, but

merely to decide in which order to perform the multiplications.

DP5 Given weights and values of n items, we need to put these items in a knapsack of

capacity W to get the maximum total value in the knapsack by using Dynamic

approachGreedy approach.

Advanced Problems

DP1 The Fibonacci numbers are the numbers in the following integer sequence.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 ...

Construct an Algorithm by using Dynamic Programming.

DP2 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 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.

DP3 Given a set of non-negative integers, and a value sum, determine if there is a

subset of the given set with sum equal to given sum.

DP4 Given an array of n distinct elements, find length of the largest subset such that

Page 18: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 18 of 20

every pair in the subset is such that the larger element of the pair is divisible by

smaller element.

DP5 Given two sequences, find the length of longest subsequence present in both of

them. A subsequence is a sequence that appears in the same relative order, but

not necessarily contiguous. For example, “abc”, “abg”, “bdf”, “aeg”, “acefg”, ..

etc are subsequences of “abcdefg”.

DP6 Given two integer arrays val [0...n-1] and wt [0...n-1] which represent values and

weights associated with n items respectively. Also given an integer W which

represents knapsack capacity, find out the maximum value subset of val[ ] such

that sum of the weights of this subset is smaller than or equal to W. You cannot

break an item, either pick the complete item, or don’t pick it (0-1 property).

DP7 Given a weighted Graph, find shortest distances between every pair of vertices in

a given edge weighted directed Graph.

Assignment Set: E (Pattern Matching)

Objectives of the Assignment:

Design and Implement different Pattern Matching Algorithms.

CO/BTLCovered: CO1 & CO3/BTL5 & BTL6

Problems:

EP1 Given a text txt [0...n-1] and a pattern pat [0...m-1], write a function search (char

pat [ ], char txt [ ]) that prints all occurrences of pat [ ] in txt [ ]. You may assume

that n > m.

EP2 Given a text txt [0...n-1] and a pattern pat [0...m-1], prints all occurrences of pat [

]in txt [ ] by using KMP approach. You may assume that n > m.

EP3 Given a text txt [0...n-1] and a pattern pat [0...m-1], prints all occurrences of pat [ ]

in txt [ ] by using Rabin Krap approach. You may assume that n > m.

EP4 Given a text txt [0...n-1] and a pattern pat [0...m-1], prints all occurrences of pat [

]in txt [ ] by using Finite Automata. You may assume that n > m.

Page 19: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design & Analysis of Algorithm Lab. | Version (9.0)

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi |Page 19 of 20

Advanced Problems

EA1 Given two strings s1 and s2, the task is to find whether the two strings contain

the same characters that occur in the same order. For example: string “Rama”

and string “Ram” contain the same characters in same order.

EA 2 Given two strings s and t. The task is to find maximum length of some prefix of

the string S which occurs in string t as subsequence

EA 3 Given a string, count how many maximum-length palindromes are present. (It

need not be a substring).

Assignment Set: F (Backtracking & Branch and Bound)

Objectives of the Assignment:

To unserstand about back tracking approach to sole the problems and explrore

the technique of branch and bound to understand Non-Polynomial Problem

CO/BTLCovered: CO1, CO3 & CO4/BTL3,BTL5 & BTL6

Problems:

FA1 Given a Set, find subset of elements that are selected from the set whose sum

adds up to a given number K. We are considering the set contains non-

negative values. It is assumed that the input set is unique (no duplicates are

presented).

FA2 Given a Graph, determine whether a given graph contains Hamiltonian Cycle

or not.

FA3 The N-Queen’s puzzle is the problem of placing N chess queens on an N×N

chessboard so that no two queens threaten each other. Thus, a solution

requires that no two queens share the same row, column, or diagonal. Provide

a solution by using Branch and Bound

Page 20: Design & Analysis of Algorithm Lab - BVICAM

Laboratory Manual for MCA-252; Design &Analysis of Algorithm Lab | Version 9.0

© Bharati Vidyapeeth’s Institute of Computer Applications and Management (BVICAM), New Delhi|Page 20 of 20

APPENDIX-A

Template for the Index of Lab File

WEEK

NO.

PROBLEMS WITH DESCRPTION PAGE

NO.

SIGNATURE

OF THE

TEACHER

WITH DATE

1 AP1

AP2

AP3

2 AA1

AA2

AA3

3 BP1

BP2

BP3

BP4

Note: The students should use Header and Footer mentioning their roll no. & name in

Header and page no. in footer.