0% found this document useful (0 votes)
140 views22 pages

DAA-Lab Manual-NBA 2023 - Geeta Rani

The document provides guidelines for a lab manual on the design and analysis of algorithms course. It includes: 1) An introduction describing the course aims, prerequisites, and how students will learn algorithm design strategies and analysis. 2) Assessment criteria splitting internal and external evaluations and details on assessments. 3) Expected lab outcomes related to algorithm design and analysis. 4) Guidelines for students on lab conduct, requirements for lab records, and formatting for programs in the record. 5) Illustrations of experiments to be performed in the lab related to algorithms and their analysis.

Uploaded by

Harshit Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views22 pages

DAA-Lab Manual-NBA 2023 - Geeta Rani

The document provides guidelines for a lab manual on the design and analysis of algorithms course. It includes: 1) An introduction describing the course aims, prerequisites, and how students will learn algorithm design strategies and analysis. 2) Assessment criteria splitting internal and external evaluations and details on assessments. 3) Expected lab outcomes related to algorithm design and analysis. 4) Guidelines for students on lab conduct, requirements for lab records, and formatting for programs in the record. 5) Illustrations of experiments to be performed in the lab related to algorithms and their analysis.

Uploaded by

Harshit Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Department of Computer and Communication Engineering

LAB MANUAL

Dr. Geeta Rani HOD-CCE

Course Coordinator
1. AIM:
Design and analysis of algorithms is the core course of computer and communication
engineering. This course is introduced in fifth semester to teach the designing and
analysis of algorithms based on different algorithm design strategies such as divide and
conquer, greedy approach, dynamic programming, branch and bound etc. This course is
introduced here after completing the pre-requisites “programming in C” and “data
structures and algorithms. In this course, the students can understand how an efficient
algorithm can be designed for a given problem. They can also learn analysis of algorithms
in space and time.

2. ASSESSMENT CRITERIA:

a) Ratio of Internal and External: 60: 40

b) Internal assessment: - Continuous Evaluation comprises of lab records, viva,

performance in lab, and problem solving on coding platform

(HackerRank/Leetcode)

c) External assessment through written examination, implementation, and Viva.

3. LAB OUTCOMES:

[CC3131.1] Recognize the appropriate algorithm design strategy based on the type
of problem.
[CC3131.2] Implement the divide, conquer based algorithms, and compute their
time complexity.
[CC3131.3] Implement the algorithms based on greedy approach, dynamic
programming, backtracking, and branch and bound. Also, analyses their time
complexity.
[CC3131.4] Strengthen the industry readiness, and entrepreneurship ability by
problem solving on an open-source platform.

4. GUIDELINES TO STUDENTS:

a) Students need to maintain a proper decorum in the computer lab. Students


must use the computers (hardware and software) with care. Any damage
caused is punishable.
b) Students must carry their lab record with completed exercises in each lab.
c) Students can use lab in free time or lunch hours with prior permission of the
lab in-charge.
d) Students must submit their lab records on or before the date of submission.
e) Students should not use pen drives/CD.

5. FORMAT OF INDEX

Aim of the Date of Date of Page Remarks and


S.No. Program
Performance Submission No. Signature

write
complete aim of the
program that
student has
written in the
DD/MM/YYY DD/MM/YYY Here faculty will Signature
aim section in every
Y Y write some of the
program
remark/grade/co faculty
mment/etc.

6. HOW TO WRITE PROGRAM IN THE LAB RECORD


Note: Sample question is shown in Figures 2, 3, and 4

Students must follow the following format to write programs in lab record.
a) Aim: write the complete aim of the program to be developed.
b) Source Code: write complete source code with name of the file in the middle
of the sheet and program should be written in proper indentation.
c) Output: write the compete output with set of input entered by user during
execution.
d) Dry run: The written code should be illustrated with an example dry run.
Other instructions related to lab record

a. Black file with tag as shown in Figure 1.

b. The students need to write all programs discussed and implemented in

lab.

c. Every question in lab record must start with new page. (Look at image)

d. Every question will have as shown in image.

i. Aim

ii. Source Code in C

iii. Output

iv. Dry run (should include line number in corresponding code, logic,

values of counters, and change in input after each iteration).

v. Dry run should be handwritten.

vi. Students can write dry run on A4 size sheet and keep it in lab

record file, or they can submit a separate notebook for dry run.

Figure 1: Lab record file


Figure 2: Sample code

Figure 3: Sample output

Figure 4: Sample dry run


Design and Analysis of Algorithms Lab
Course Code: CC3131

Illustration of Experiments
Course Code: CC3131
Semester-V
1. Binary Search in both recursive and non-recursive manner.
Non-recursive (Iterative Binary Search)

Step 1: Start
Step 2: Initialize
low = 1
high = n
Step 3: Perform Search
While(low <= high)
Step 4: Obtain index of midpoint of interval
Middle = (low + high) / 2
Step 5: Compare
if(X < K[middle])
high = middle - 1
else
print “Element found at position”
Return(middle)
goto: step 2
Step 6: Unsuccessful Search
print “Element found at position”
Return (middle)
Step 7: Stop

Recursive Binary Search


2. Selection Sort operation with suitable input.
i The selection sort algorithm is as follows:
ii Step 1: Set Min to location 0 in Step 1.
iii Step 2: Look for the smallest element on the list.
iv Step 3: Replace the value at location Min with a different value.
v Step 4: Increase Min to point to the next element
vi Step 5: Continue until the list is sorted.

3. Implement Quick Sort operation with suitable input.


Steps for quick sort

i. Make any index value in the array as a pivot.

ii. Partition the array according to the pivot.

iii. Recursively quicksort the left partition

iv. Recursively quicksort the correct partition.

Steps for partition

i Pick any pivot, let's say the highest index value.

ii Take two variables to point left and right of the list, excluding pivot.

iii The left will point to the lower index, and the right will point to the higher index.

iv Now you move all elements which are greater than pivot to the right.

v Move all elements smaller than the pivot to the left partition.
4. Insertion Sort operation with suitable input.

5. Merge Sort operation with suitable input.


6. HeapSort – MAX Heap and MIN Heap.

Create a heap.
Delete the elements.
Sorted array.
7. Priority Queue operation with suitable input.
• Elements are inserted according to their priority.
• The elements of highest priority are deleted earlier than elements of lower priority.
• The value of element can be considered its priority.
• Maintaining priority queue using array takes O(n) time.
• Maintaining priority queue using heap takes O (log n) time.

8. knapsack problem using dynamic programming.

// Find maximum of two integers


int max(int a, int b) { return (a > b) ? a : b; }

// Returns the maximum value that can be put in a knapsack of capacity W


int knapSack(int W, int wt[], int val[], int n)
{
// Base Case
if (n == 0 || W == 0)
return 0;

// If weight of the nth item is more than Knapsack capacity W, then this
item cannot be included in the optimal solution
if (wt[n - 1] > W)
return knapSack(W, wt, val, n - 1);

// Return the maximum of two cases:


// (1) nth item included
// (2) not included
else
return max(
val[n - 1]
+ knapSack(W - wt[n - 1], wt, val, n - 1),
knapSack(W, wt, val, n - 1));
}

9. Single source shortest path problem using greedy method. (Dijkstra’s).


10. Prim’s and Kruskal’s with suitable input.
Step 1: Determine an arbitrary vertex as the starting vertex of the MST.
Step 2: Follow steps 3 to 5 till there are vertices that are not included in the
MST (known as fringe vertex).
Step 3: Find edges connecting any tree vertex with the fringe vertices.
Step 4: Find the minimum among these edges.
Step 5: Add the chosen edge to the MST if it does not form any cycle.
Step 6: Return the MST and exit
11. Breadth first search and Depth first search with suitable input.
Terminology:
• Visiting: To hit a particular vertax.
• Exploring: To hit all its adjacent vertices.
• Data structures used: BFS→ Queue
• DFS-→ Stack

Steps:
BFS:
• visit a vertex, explore it completely, repeat till all vertices are explored.
DFS:
• Visit a vertex, explore one of its adjacent vertices. Explore one of the adjacent vertices of
the previously explored vertex. Repeat till no vertex to explore. Return back and explore.
Repeat.

12. Fibonacci series dynamic programming using top-down approach.


13. Fibonacci series dynamic programming using bottom-up approach.
14. Longest integer sequence LIS with suitable input.

1. Create a table of dimension n+1*m+1 where n and m are the lengths


of X and Y respectively. The first row and the first column are filled with
zeros.

2. Fill each cell of the table using the following logic.


3. If the character corresponding to the current row and current column are
matching, then fill the current cell by adding one to the diagonal ele-
ment. Point an arrow to the diagonal cell.

4. Else take the maximum value from the previous column and previous
row element for filling the current cell. Point an arrow to the cell with
maximum value. If they are equal, point to any of them.
5. Fill the values

6. Step 2 is repeated until the table is filled.

7. Fill all the values


8. The value in the last row and the last column is the length of the longest
common subsequence

9. The bottom right corner is the length of the LCS. In order to find the
longest common subsequence, start from the last element and follow
the direction of the arrow. The elements corresponding to () symbol
form the longest common subsequence.
Create a path according to the arrows

Thus, the longest common subsequence is CA

15. Implement Binomial Coefficient using Dynamic Programming with suitable input.
16. Implement travelling sales person problem using dynamic programming with suitable input.
Algorithm: Traveling-Salesman-Problem
C ({1}, 1) = 0
for s = 2 to n do
for all subsets S є {1, 2, 3, … , n} of size s and containing 1
C (S, 1) = ∞
for all j є S and j ≠ 1
C (S, j) = min {C (S – {j}, i) + d(i, j) for i є S and i ≠ j}
Return minj C ({1, 2, 3, …, n}, j) + d(j, i)

17. Consider the problem of N-queens on a chess board. Two queens are said to attack each
other if they are on the same row, column or diagonal. Write a program that implements
back tracking algorithm to solve the problem i.e., place eight non-attacking queens on the
board.
Continue the same way untill two adjacent queens are placed at non-conflicting positions,
i.e these are not in same row, not in same column, and not in same diagonal.

18. Implement Graph Coloring Problem with suitable input.


Pairs of adjacent vertices are assigned different colours, and
The number of different colours used across the graph is minimal.
Algorithm
▪ List down all the vertices and colors in two lists
▪ Assign color 1 to vertex 1
▪ If vertex 2 is not adjacent to vertex 1 then assign the same color, oth-
erwise assign color 2.
▪ Repeat the process until all vertices are colored.
▪ Algorithm backtracks whenever color i is not possible to assign to any vertex k and
it selects next color i + 1 and test is repeated.

You might also like