AID 3rd Semester - Design and Analysis of Algorithms Laboratory - AD3351 - Lab Manual
AID 3rd Semester - Design and Analysis of Algorithms Laboratory - AD3351 - Lab Manual
4th Semester
2nd Semester
Deep Learning -
AD3501
Embedded Systems
Data and Information Human Values and
and IoT - CS3691
5th Semester
7th Semester
8th Semester
Open Elective-1
Distributed Computing Open Elective 2
- CS3551 Project Work /
Elective-3
Open Elective 3 Intership
Big Data Analytics - Elective-4
CCS334 Open Elective 4
Elective-5
Elective 1 Management Elective
Elective-6
Elective 2
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering
www.BrainKart.com
SCIENCE
LAB MANUAL
Prepared By,
AD3351_DAA
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement the implementation of recursive algorithm.
ALGORITHM:
1. START.
2. Input the non-negative integer 'n'
3. If (n==o || n==1) return n; else. return fib(n-1)+fib(n-2);
4. Print, nth Fibonacci number.
5. END.
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
Thus the program implemented Successfully.
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement the implementation of non recursive
algorithm.
ALGORITHM:
Step 1: Take the first two numbers of the series and the number of terms to be printed from the
user.
Step 2. Print the first two numbers.
Step 3. Use a while loop to find the sum of the first two numbers and then proceed the fibonacci
series.
Step 4. Print the fibonacci series till n-2 is greater than 0.
Step 5. Exit.
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
5040
RESULT:
Thus the program implemented Successfully.
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement the Divide and Conquer by strassen’s matrix
multiplication algorithm.
ALGORITHM:
Step 1:Start with two input matrices, A and B, of size n x n that you want to multiply.
Step 2: If the size of the matrices (n) is 1, then multiply the corresponding elements and return the
result as a 1x1 matrix.
Step 3: Divide each of the input matrices A and B into four equal-sized submatrices. Each matrix
can be divided into four quadrants:
Step 4: Calculate seven products recursively using the following formulas:
Step 5: Compute the four submatrices of the result matrix C using the calculated products
Step 6: Combine the four submatrices C11, C12, C21, and C22 to form the final result matrix C.
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
Thus the program implemented Successfully.
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement the Decrease and Conquer by topological
sorting algorithm.
ALGORITHM:
1. Step 1: Find a vertex with in-degree 0 (a vertex with no incoming edges).
2. Step 2: Remove the selected vertex and its outgoing edges from the graph.
3. Step 3: Repeat Steps 1 and 2 until all vertices are processed.
4. Step 4: If there are still vertices left in the graph after Step 3, the graph contains a cycle
(it's not a DAG).
5. Step 5: The order in which vertices are removed in Steps 2 forms a topological ordering.
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
Thus the program implemented Successfully
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement the Divide and Conquer by strassen’s matrix
multiplication algorithm.
ALGORITHM:
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
Thus the program implemented Successfully
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement the dynamic programming by coin change
problem.
ALGORITHM:
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
Thus the program implemented Successfully
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement the dynamic programming by warshall and
Floyd’s algorithm.
ALGORITHM:
1. Initialization:
Start with the given adjacency matrix, let's call it graph.
Create another matrix, let's call it transitive_closure, initialized as a copy of the
graph.
2. Main Loop:
For each intermediate vertex k from 1 to the number of vertices:
For each pair of vertices i and j:
Update transitive_closure[i][j] to 1 if either
transitive_closure[i][j] is 1 or both transitive_closure[i][k] and
transitive_closure[k][j] are 1.
3. Final Result:
The transitive_closure matrix now represents the transitive closure of the original
graph
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
RESULT:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement the dynamic programming by knapsack
problem.
ALGORITHM:
1. Initialize the table: Create a 2D table (array) dp of size (n+1) x (W+1), where n is the
number of items and W is the maximum capacity of the knapsack. Each cell dp[i][j] in the
table represents the maximum value that can be obtained with the first i items and a
knapsack capacity of j.
2. Fill in the table: For each item i and each capacity j, calculate the maximum value that
can be obtained considering whether or not to include the current item in the knapsack.
wt[i-1] is the weight of the i-th item.
val[i-1] is the value of the i-th item.
3. Final result: The maximum value that can be obtained is stored in dp[n][W], where n is
the total number of items and W is the maximum capacity of the knapsack.
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
Thus the program implemented successfully.
\
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement the greedy technique by Huffman trees and
codes
ALGORITHM:
1. Frequency Count:
Count the frequency of each character in the input text or dataset.
2. Create Nodes:
Create a leaf node for each unique character, and associate the frequency of that
character with the node.
3. Priority Queue:
Place all the leaf nodes into a priority queue (min-heap), where the priority is based
on the frequency of the characters. The node with the lowest frequency has the
highest priority.
4. Build Huffman Tree:
While there is more than one node in the priority queue:
Remove the two nodes with the lowest frequency from the priority queue.
These nodes will become the left and right children of a new internal node.
Create a new internal node with a frequency equal to the sum of the
frequencies of the two nodes removed in the previous step.
Insert the new internal node back into the priority queue.
5. Result:
The final node remaining in the priority queue is the root of the Huffman tree.
6. Assign Codes:
Traverse the Huffman tree from the root. Assign a binary '0' to each left branch and
a '1' to each right branch.
The Huffman codes for the characters are the binary sequences obtained by
traversing from the root to the leaves.
7. Generate Huffman Codes:
For each character, the Huffman code is the binary sequence obtained by
concatenating the binary values associated with each branch from the root to the
leaf corresponding to that character.
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
Thus the program implemented Successfully.
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement iterative improvement by simplex method.
ALGORITHM:
1. Formulate the Linear Programming Problem:
Identify the decision variables.
Formulate the objective function to be maximized or minimized.
Write down the linear equality and inequality constraints.
2. Convert the Problem to Standard Form:
Express any inequalities as equalities by introducing slack or surplus variables.
Make sure all variables are non-negative.
3. Initialize the Simplex Tableau:
Set up an initial simplex tableau with the coefficients of the objective function and
the constraints.
4. Select the Pivot Column:
Identify the column with the most negative coefficient in the bottom row
(excluding the rightmost column).
5. Select the Pivot Row:
For the chosen pivot column, calculate the ratios of the right-hand side values to
the corresponding coefficients in the pivot column. Select the row with the smallest
non-negative ratio as the pivot row.
6. Pivot Operation:
Use elementary row operations to make the pivot element (intersection of the pivot
row and pivot column) equal to 1 and all other elements in the pivot column equal
to 0. This operation updates the tableau.
7. Update the Tableau:
Update the tableau by applying the pivot operation to the rest of the rows to make
the pivot column a unit vector.
8. Repeat Steps 4-7:
Continue the iterations until there are no more negative coefficients in the bottom
row of the tableau.
9. Read the Solution:
The values in the rightmost column represent the solution to the linear
programming problem.
10. Check Optimality:
If all coefficients in the bottom row are non-negative, the solution is optimal.
Otherwise, go back to steps 4-9.
11. Post-Optimal Analysis (if needed):
If there are multiple optimal solutions or if sensitivity analysis is required, perform
additional analysis based on the specific problem requirements.
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
1. Initialize the Chessboard: Create an N×N chessboard and initialize it. This can be done
using a 2D array or any suitable data structure. Initially, all cells may be empty.
2. Define the Backtracking Function: Create a recursive backtracking function that will
attempt to place queens on the chessboard. The function should explore different
possibilities while respecting the constraints of the problem.
3. Base Case: Define a base case for the recursion. In the context of N-Queens, the base case
is often when all queens are placed successfully on the board.
4. Recursive Step: In the recursive function, try placing a queen in each row, one by one.
Check if placing the queen in the current position violates any constraints. If not, proceed
to the next row and continue the process.
5. Constraint Checking: At each step, check whether the placement of the queen violates
any constraints (i.e., check if it attacks any other queen in the same row, column, or
diagonal). If the placement is valid, proceed; otherwise, backtrack and try a different
position.
6. Backtrack: If you reach a point where it's impossible to place a queen without violating
constraints, backtrack to the previous step and explore other possibilities.
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement backtracking technique Subset sum Problem..
ALGORITHM:
1. In the recursive function, consider two cases:
Include the current element in the subset and reduce the target sum by the
value of the current element.
Exclude the current element from the subset and move on to the next
element.
2. Backtracking:
If the current combination does not lead to a solution, undo the choice (backtrack)
and explore other possibilities.
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
RESULT:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AIM:
Aim is to write a program in C to implement branch and Bound by assignment Problem..
ALGORITHM:
1. Initialize:
Create an initial solution or assignment.
Initialize the lower bound to a very large value (for minimization problems) or a
very small value (for maximization problems).
2. Create a Priority Queue:
Use a priority queue (min-heap for minimization, max-heap for maximization) to
store partial solutions or subproblems.
The priority is determined by the lower bound of each subproblem.
3. While the Priority Queue is not Empty:
Dequeue the subproblem with the lowest bound from the priority queue.
If the subproblem is feasible:
Update the lower bound if the solution is better than the current best
solution.
Enqueue the subproblems obtained by branching (creating new
assignments).
4. Branching:
Choose a variable to branch on. This involves creating two new subproblems: one
where the selected variable is assigned to one value and another where it is
assigned to another value.
Update the partial solution and calculate the lower bounds for both subproblems.
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
1. Initialization:
Create an initial node in the search tree, representing the initial state of the problem
(e.g., the starting city). Initialize the lower bound with an initial estimate.
2. Branching:
Divide the problem into subproblems (branches) by making decisions. For TSP,
this involves selecting the next city to visit. Create child nodes for each possible
decision and add them to the search tree.
3. Bounding:
Compute a lower bound for each node in the search tree. This is an estimate of the
minimum possible cost of any solution that can be obtained by expanding that
node. Prune (discard) branches that are guaranteed to lead to a solution that is
worse than the current best solution.
PROGRAM:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
OUTPUT:
RESULT:
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering
AD3351_DAA LAB
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
Click on Subject/Paper under Semester to enter.
Professional English Discrete Mathematics Environmental Sciences
Professional English - - II - HS3252 - MA3354 and Sustainability -
I - HS3152 GE3451
Digital Principles and
Statistics and Probability and
Computer Organization
Matrices and Calculus Numerical Methods - Statistics - MA3391
- CS3351
- MA3151 MA3251
3rd Semester
1st Semester
4th Semester
2nd Semester
Deep Learning -
AD3501
Embedded Systems
Data and Information Human Values and
and IoT - CS3691
5th Semester
7th Semester
8th Semester
Open Elective-1
Distributed Computing Open Elective 2
- CS3551 Project Work /
Elective-3
Open Elective 3 Intership
Big Data Analytics - Elective-4
CCS334 Open Elective 4
Elective-5
Elective 1 Management Elective
Elective-6
Elective 2
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering