Professional Documents
Culture Documents
Ada Lab File Sudit Patel F
Ada Lab File Sudit Patel F
PRACTICAL LAB-FILE
Subject Name:-ANALYSIS AND DESIGN OF
ALGORITHMS.
Subject Code:-BTIT-305.
Class:-B-Tech CSE 2NDYEAR 3RD
ENROLLMENT NO.: 20100BTCSES07307
Section:- f red hat
Index
Practical Program Code No.
Experiment 1
Objective: To implement binary search algorithm and compare its running time in searching
an element in arrays of different sizes.
Description:-
Binary Search: Search a sorted array by repeatedly dividing the search interval in half. Begin
with an interval covering the whole array. If the value of the search key is less than the item
in the middle of the interval, narrow the interval to the lower half. Otherwise, narrow it to
the upper half. Repeatedly check until the value is found or the interval is empty.
Program:-
Output:-
Experiment 2
Objective:- To implement Sum of Array algorithm Recursively and compare its running time.
Description:- Given an array A[], we need to find the sum of its elements using Tail Recursion
Method. We generally want to achieve tail recursion (a recursive function where recursive
call is the last thing that function does) so that compilers can optimize the code. Basically,
if recursive call is the last statement, the compiler does not need to save the state of parent
call.
Program:-
Output:-
Experiment 3
Objective:- To implement Matrix Addition algorithm and compare its running time.
Description:- Matrix addition in C language to add two matrices, i.e., compute their sum and
print it. A user inputs their orders (number of rows and columns) and the matrices.
Program:-
Output:-
PREPAIRED BY: SUDIT PATEL P a g e 6 | 38
ANALYSIS OF DESIGN ALGORITHM BTIT-305
Experiment 4
Objective:- To implement Matrix Multiplication algorithm and compare its running time.
Program:-
Output:-
Experiment 5
Objective:-To implement Linear search algorithm and compare its running time in searching
an element in arrays of different sizes in c.
Output:-
PREPAIRED BY: SUDIT PATEL P a g e 9 | 38
ANALYSIS OF DESIGN ALGORITHM BTIT-305
Experiment 6
Objective:- To implement binary search algorithm in arrays of different sizes.
Description:-
Search a sorted array by repeatedly dividing the search interval in half. Begin with an
interval covering the whole array. If the value of the search key is less than the item in the
middle of the interval, narrow the interval to the lower half. Otherwise, narrow it to the
upper half. Repeatedly check until the value is found or the interval is empty.
Program:-
Output:-
Experiment 7
Objective:- To implement binary search algorithm Recursively in arrays of different sizes.
Description:- Search a sorted array by repeatedly dividing the search interval in half. Begin
with an interval covering the whole array. If the value of the search key is less than the item
in the middle of the interval, narrow the interval to the lower half. Otherwise, narrow it to
the upper half. Repeatedly check until the value is found or the interval is empty.
Program:-
Output:-
Experiment 8
Objective:- To implement Modified binary search algorithm in arrays of different sizes.
Description:- It is basically performing a binary search on a list which first increases then
decreases. Even though it's obvious that we can achieve O (log n) I couldn't figure out what
is wrong the code below that I've written:-
Program:-
Output:-
Experiment 9
Objective:-To implement Merge sort algorithm on the given list of keys.
Description:- Merge sort is similar to the quick sort algorithm as it uses the divide and
conquer approach to sort the elements. It is one of the most popular and efficient sorting
algorithm. It divides the given list into two equal halves, calls itself for the two halves and
then merges the two sorted halves. We have to define the merge() function to perform the
merging.
Program:-
Output:-
Experiment 10
Objective:- To implement Max-Min algorithm on the given list of keys.
Description:- C program to find the maximum and minimum element in an array – In this
article, we will brief in on the many ways to find the maximum and minimum element in an
array in C programming.
Program:-
Output:-
Experiment 11
Objective:-To implement Quick sort algorithm on the given list of Keys (Hoare Partition).
Description:- Hoare uses two indices that start at the ends of the array being partitioned,
then move toward each other until they detect an inversion: a pair of elements, one greater
than the pivot, one smaller, in the wrong order relative to each other. The inverted
elements are then swapped. When the indices meet, the algorithm stops and returns the
final index.
Program:-
Output:-
Experiment 12
Objective:- To implement Quick sort algorithm on the given list of keys (Lomuto Partition).
Description:-
Program:-
Output:-
Experiment 13
Objective:- To implement Heap sort algorithm on the given list of keys.
Description:- Heap Sort is a popular and efficient sorting algorithm in computer
programming. Learning how to write the heap sort algorithm requires knowledge of two
types of data structures - arrays and trees.
Program:-
Output:-
Experiment 14
Objective:- To implement Insertion sort algorithm on the given list of keys.
Description:- Insertion sort works similar to the sorting of playing cards in hands. It is
assumed that the first card is already sorted in the card game, and then we select an
unsorted card. If the selected unsorted card is greater than the first card, it will be placed at
the right side; otherwise, it will be placed at the left side.
Program:-
Output:-
Experiment 15
Objective:- To implement Selection sort algorithm on the given list of keys.
Description:- In selection sort, the smallest value among the unsorted elements of the array
is selected in every pass and inserted to its appropriate position into the array. It is also the
simplest algorithm. It is an in-place comparison sorting algorithm. In this algorithm, the
array is divided into two parts, first is sorted part, and another one is the unsorted part.
Initially, the sorted part of the array is empty, and unsorted part is the given array. Sorted
part is placed at the left, while the unsorted part is placed at the right.
Program:-
Output:-
Experiment 16
Description:-
The knapsack problem is a problem in combinatorial optimization: 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.
Prim’s Algorithm:-
Prim's algorithm is a minimum spanning tree algorithm 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 that can be formed from the graph.
Krushkal’s Algorithm:-
Krushkal's algorithm finds a minimum spanning forest of an undirected edge-weighted
graph. ... It is a greedy algorithm in graph theory as in each step it adds the next lowest-
weight edge that will not form a cycle to the minimum spanning forest.
Program:-
Prim’s Algorithm Program:-
Output:-
Output:-
Experiment 17
Objective:-To implement Floyd’s Warshall’s Algorithm.
Description:-
Floyd–Warshall algorithm is an algorithm for finding shortest paths in a directed weighted
graph with positive or negative edge weights. A single execution of the algorithm will find
the lengths of shortest paths between all pairs of vertices.
Program:-
Output:-
Experiment 18
Objective:-To implement Strassen’s Matrix Multiplication.
Description:-
Strassen's Algorithm is an algorithm for matrix multiplication. Strassen’s Algorithm is a
recursive method for matrix multiplication where we divide the matrix into 4 sub-matrices
of dimensions n/2 x n/2 in each recursive step. For example, consider two 4 x 4 matrices A
and B that we need to multiply.
Program:-
Output:-
Experiment 19
Objective:-To implement N-Queen’s Problem.
Description:-
N – Queen’s Problem is to place n - queens in such a manner on an n x n chessboard that no
queens attack each other by being in the same row, column or diagonal. It can be seen that
for n =1, the problem has a trivial solution, and no solution exists for n =2 and n =3. So first
we will consider the 4 queens problem and then generate it to N – Queen’s problem.
Program:-
Output:-