Você está na página 1de 30

ANALYSIS AND DESIGN OF ALGORITHMS LABORATORY USING C or C++(CSE)

Sub Code : CSE48 Hrs / Week : 03 Total Hrs. : 42

IA Marks: 25 Exam Hours : 03 Exam Marks : 50

Implement the following using C/C++ Language.

1. Perform recursive Binary search and Linear search. Hence find the time required to search an element. 2. Sort a given set of elements using the Heapsort method. 3. a. Sort a given set of elements using Merge sort method b. Check whether a given graph Is connected or not using DFS method. 4.Sort a given set of elements using selection sort and hence find the time required to sort elements. 5. a. Obtain the Topological ordering of vertices in a given digraph. b. Sort a given set of elements using Insertion sort method. 6. Implement 0/1 Knapsack problem using dynamic programming. 7. From a given vertex In a weighted connected graph, find shortest paths to other vertices using Dljkstra's algorithm. 8. Sort a given set of elements using Quick sort method. 9. Find Minimum Cost Spanning Tree of a given undirected graph using Kruskal's algorithm. 10. a. Print a!! the nodes reachable from a given starting node In a digraph using Breadth First Search method. b. Implement All Pair Shortest paths problem using Floyd's algorithm. 11. Find a subset of a given set S = {S1,~, .......... ,Sn) of n positive Integers whose sum Is equal to a given positive Int eger d. For example s={1,2,5,6,8}and d = 9 there are two solutions [ 1,2,6] and J 1,8}. A suitable message Is to be displayed if the given problem Instance doesn't have a solution. 12. a. Implement Horspool algorithm for String Matching. b. Find the Binomial Co-efficient using Dynamic Programming.

13. Find Minimum Cost Spanning Tree of a given undirected graph using Prism's algorithm. 14. a. Print all the nodes reachable from a alven startlna node In a alven
digraph uelng De h Flret rch method.

b. Compute the transitive closure of a given directed graph using Warshall's algorithm. 15. Implement N Queen's problem using Back Tracing. Note: In the examination questions must be given on lots. Each student must be given one question.

1a > Write a program to conduct binary search using recursive function & to calculate time taken for executing program
#include<stdio.h> #include<conio.h> #include<time.h>

void selectionsort(int a[] , int n ) { int i,j,temp,min; for(i=O;i<n-l;i+ +) { min=i; for(j=i+l;j<n;j+ +) if(a[j]<a[min]) min=j; temp = a[i]; a[i]=a[min]; a[min]=temp; } }

int bin(int a[] ,int low, int high ,int key) { int mid; mid = (low+high)/2; if(key == a[mid]) return mid; if(key < a[mid]) bin(a,low,mid-l,key); else if(key > a[mid]) bin(a,mid+l,high,key); }

void main() { int a[100],n,i,key,flag; float start,end; c1rscr(); printf(" enter the number of elements \n"); scanf("
% d",&n);

printf(" enter the elements \n"); for(i=O;i<n;i+ +) scanf(" % d",&a[i]); printf(" enter the key element to be searched\n"); scanf("
% d"

,&key);

printf(" the elements in ascending order is \n"); for(i=O;i<n;i+ +) printf(" 0 / o d \n

II

,a[il);

start = c1ock(); flag = bin(a,O,n-1,key); end = c1ock(); if(flag == -1) printf(" the element not present \n"); else printf(" the element present at %d \n" , flag+1); printf(" the time taken a/of cpu cycles\n" , ( end-start; getch(); }

lb > Write a program to conduct linear search using recursive function & to calculate time taken for executing program
#include<stdio.h> #include<conio.h> #include<time.h> int Iin(int a[] , int p ,int key,int n) { if( P > n) return -1; if( a[p] == key) return p; Iin(a,p+1,key,n);

}
void mainO { int a[100],n,i,key,flag; c1ock_t start,end; c1rscrO; printf(" enter the number of elements \n"); scanf("%d",&n); printf(" enter the elements in ascending order\n"); for(i=O;i<n;i+ +) scanf("%d" ,&a[i]); printf(" enter the key element to be searched\n"); scanf("%d" ,&key); start = c1ock(); flag = Iin(a,(),key,n-1); end = c1ock(); if(flag == -1) printf(" the element not present \n"); else printf(" the element present at %d \n" , flag+1); printf(" the time taken %ld cpu cycles\n" , end-start); getch(); }

2a> Program to sort given set of elements using heap sort


#include<stdio.h> #include<conio.h>

main() { int a[100],heaparray[100],i,n,par=(); c1rscr() };

printf("Enter the number of elements \n"); scanf("


%

d" ,&n);

printf("Enter the elements \n"); for(i=O;i<n;i+ +) scanf(" % d",&a[i]); heapi nsert( a,n,heaparray);

printf("The elements in ascending order are \n"); for(i=O;i<n-l;i+ +) remoove(heaparray,n); par= maximum(heaparray,n); printf(" getch(}; }
% d\n",par);

heapinsert(int a[100] , int n, int heaparray[100]) { int i,k,parent,temp,numele=O;

for(i=O;i<n;i+ +) { numele++; heaparray[numele] =a[i]; k=numele; while( k > 1) { parent = k/2; if(heaparray[k] > heaparray[parent] ) break;

temp = heaparray[k]; heaparray[k] = heaparray[parent]; heaparray[parent] = temp; k=parent; }}}

1* to find max in heap* 1


int maximum(int heaparray[100],int n) {

int i , max = 0 , index; for(i=1;i<=n+1;i+ +) if( max < heaparray[i]) max = heaparray[i],index=i; heaparray[index] =0; return(max); } remoove(int heaparray[100],int n) { int k=l,newk,temp; printf("%d\n" ,heaparray[l]); heaparray[l] = maximum(heaparray,n); while( (2*k) <= n) { if( heaparray[2*k] == 0 II heaparray[ 2*k+1] == 0) { if( heaparray[2*k] == 0) newk = 2 * k + 1; else newk = 2 * k; } else if( heaparray[2*k] < heaparray[2*k+1] ) newk= 2*k; else newk = 2 * k + 1; temp = heaparray[k]; heaparray[k] = heaparray[newk]; heaparray[newk] = temp; k=newk;

} }

3a > Program to sort numbers in ascending order using merge sort #include<stdio.h>
#include<conio.h> #include<time.h>

void mainO { int a[100],n,i; clrscrO; printf(" enter the number of elements \n"); scanf("%d" ,&n); printf(" enter the elements \n"); for(i=l;i<=n;i++ ) scanf("%d",&a[i]); mergesort( a, 1,n); printf(" the elements are\n" ); for(i=l;i<=n;i++ ) printf("%d\n" ,a[i]); getchO;
}

1* function for partition * 1 mergesort(int a[] ,int low, int high) {


int mid; if(low < high) { mid = (low+high)/2; mergesort(a,low ,mid ); mergesort(a,mid+l,high ); merge(a,low ,mid, high ); }
}

1* function to merge partitions * 1 merge(int a[],int low,int mid ,int high) {


int i,j,k,b[100]; i = low; k = low; j = mid+l; while( i <= mid &&j<=high) if(a[i] < a[j]) b[k++] = a[i++]; else b[k++] = a[j++]; while( i <= mid) b[k++] = a[i++]; while(j <= high) b[k++] = a[j++]; for(i=low;i<=high;i++ ) a[i] = b[i];
}

3b > Program to check the graph is connected or not using DFS Method #include <stdio.h> void main( ) { int i,j; c1rscr(); printf (n\n enter number of nodes in the graph \n "); scanf ("%d", an); printf(" enter the adjacency matrix \n"); for(i=l;i<=n;i+ +) for(j= l;j< =n;j+ +) scanf(" % d" ,&a[i] [i]); for(i=l;i<=n;i++ ) { visited[i] =0; s[i]=O; } Componentlabel(); }

Componentlabel() { int i,k; for(i=l;i<=n;i+ +) if(s[i] == 0) { label++; dfs(i); } if( label > 1) printf(" disconnected graph \n"); else printf(" connected components \n"); for(i=l;i<=n;i+ +) printf(" vertex %d belongs to component %d \n" , i, s[i] ); } dfs(int v) { visited[v] = 1; s[v] = label; for(i=l;i<=n;i+ +) if(a[v][i] == 1 && visited[i] == 0) dfs(i); }

4 > Progrm to sort given set of elements using selection sort and hence find the time required to sort elements
#include<stdio.h> #include<conio.h> #include<time.h> void main()
{

int a[100],n,i; float start,end; printf(" enter the number of elements \n"); scanf("%d" ,&n); printf(" enter the elements in ascending order\n"); for(i=l;i<=n;i++) scanf("%d" ,&a[i]); start = c1ock(); selectionsort( a,n); end = c1ock(); printf(" the elements are\n" ); for(i=l;i<=n;i++) printf("()/%d\n",a[i]); printf(" the time taken % start;getchO; }
f cpu cycles\n" , ( end-

1* function selection * 1 selectionsort(int a[] , int n) {


int i,j,temp,min; for(i=l;i< =n-l;i++)
{

min=i; for(j=i+l;j<=n;j++) if(a[j]<a[min]) min=j; temp = a[i]; a[i]=a[min]; a[min]=temp;


}}

5 > Program to obtain topological ordering of vertices in the given digraph #include <stdio.h> int topolo gy(int cost[10][10], int n , int f1ag[10]) { int i, j ,u,v,sum,min,d[10],s[10],pri[10],count=0; for (i=l; i<=n; i+ +) { if(f1ag[i] = = 0) { printf(tl%d\ttl,i); f1ag[i]= -1; count++; foro = l;j< =n;j+ +) { if(cost[i]U] == 1 ) f1agU]--; } i=(); } } return count; }

L* main program* L void main()


{ int n,cost[ 10] [10],i,j,f1ag[ 10],count; c1rscr(); printf ("\nHow many nodes in the graph have \n tI); scanf ("%d
tl,

&n);

fo r(i=l;i<=n;i++) f1ag[i]=(); printf (tlEnter the adjacency matrix. \n); fo r (i=l; i<=n; i+ +) fo r (j=1; j<=n; j+ +) { scanf (tl%d f1agU]++; } printf(tI \n the topological order is \n tI); count = topo logy(cost, n, flag); if(count == n) printf(" \n the topological order exist tI); else printf(tI \n the topological order does not exist tI);
tl,

&cost[i]U]); if(cost[i]U] == 1)

#include<stdio.h> #include<conio.h> #include<time.h> void main() { int a[100],n,i; c1rscrO; printf(n enter the number of elements \nn); scanf("%d",&n); printf(" enter the elements in ascending order\n"); for(i=l;i<=n;i+ +) scanf("%d" ,&a[i]); printf(" the elements are\n" ); for(i=l;i<=n;i+ +) printf("%d\n" ,a[i]); getch(); } inssort(int a[] , int n ) { int i,j,temp; for(i=2;i< +) { =n;i+

j=il; while(j > 0 && a[j+l] < a[j { temp = a[j]; a[j]=a[j+l]; a[j+l]=temp; j--; } } }

#include <stdio.h> #include<stdlib.h> int w[20],p[20],temp1,profit; int n,i,c; float knapsack ( int i , int c) { float profit=O; if ( i == n) return (c < w[i] ? 0: p[n]); if( c < w[i]) return napsack( i + 1 , c); return ( max(knapsack(i+1,c) , knapsack(i+1,c-w[i])+p[i]; } void main() { c1rscrO; printf ("\ nEnter the capacity o f the knapsack: "); scanf (()/%d", &c); printf ("Enter the number of o bjects: "); scanf ("()/%d", &n); printf ("E nter the weight and profit of each object:\ n"); for (i=1; i<=n; i++) scanf ("()/%d%/d", &w[i],&p[i]); profit = knapsack (1, c); printf ("Maximum profit earnable: %d\n", profit); }

7 > Program to find single source shortest path using dijkstra's algorithm #include <stdio.h>
I * function to find path * I void dijkstra(int cost[10][10], int n, int source) {

for (i=l; i<=n; i+ +) { d[i] = cost[source][i]; s[i] =0; } s[source] = 1; for (i=l; i<=n-l; i+ +) { min = 999; for (j=I; j<=n; j+ +) if(s[j] == 0) if(d[j] < min) { min = d[j]; u = j; } s[u] = 1; for (v=l; v<=n; v+ +)

if(s[v] == 0)

if(d[u] + cost[u][v] < dry]) dry] = d[u]+cost[u](v]; for(i=l;i<=n;i+ +) printf(" the distance from %d to %d is %d\n", source,i , d[i]); } void main() { int n,cost[10][10],i,j,sum,source; clrscr(); printf ("\nHow many nodes in the graph have \n "); scanf ("%d", &n); printf ("Enter the cost adj matrix for the graph 999 indicates no connection. \n"); for (i=l; i<=n; i+ +) for (j=I; j<=n; j+ +) scanf (nO/od", &cost[i][j]); printf ("\n enter the reference or source node "); scanf ("%d", &source); dijkstra (cost, n, source); }

#include<stdio.h> #include<conio.h> #include<time.h> void main{) { int a[100],n,i; clrscr{); printf(" enter the number of elements \n"); scanf("%d" ,&.n); printf(" enter the elements \n"); for(i=O;i<n;i+ +) scanf("%d" ,&.a[iD]); printf(" sorted the elements are\n" ); for(i=O;i<n;i+ +) printf("%d\n" ,a[iD]); getch{); } quicksort(int a[] ,int low, int high) { int j; if(low < high) {
j = partition(a,low,high); quicksort( a,low ,j-l); quicksort( a,j+ 1,high); } }

partition(int a[],int low,int high) { int i,j,key,temp; key = a[low]; i = low + 1; j = high;

fore;; )

{ while( key> a[i] aa i<=high) i++; while( key < aU]) j--;

if(i < j)
{ temp = a[i]; a[i] = aU]; aU] = temp; } { temp = aU]; aU] = a[low]; a[low] = temp; retumj;

} }
struct graph { int begvi int endvi int costi }i int kruskals(int cost[10][10], int n ) { struct graph edge[2 0] ,temp[i]; int i, j ,p rent[2 0], parenti, parentj , count, sum, spanedgei for (i=li i<=ni i++) for (j=li j<=ni j+ +) if (cost[i][j] != 999 && i!=j) { edge[count].begv = ii edge[count].endv = ji edge[count].cost = cost[i][j]i count++; } for (i=li i<=count-li i++) for (j=i+li j<=counti j+ +) if (edge[i].cost > edge[j].cost) { temp.begv =edge[i].begvi temp.endv = edge[i].endvi temp.cost = edge[i].costi edge[i].begv=edge[j].be9vi edge[i].endv=edge[j].endvi edge[i].cost = edge[j].costi edge[j].begv = temp.begvi

edge[j].endv = temp.endvi

edge[j].cost = temp.cQ.sti } sum = 0i spanedge = Oi for(i=lii<=nii+ +) parent[i] = -li for (i=l; i<=count; i+ +) { parenti = getparent (parent, edge[i].begv); parentj = getparent (parent, edge[i].endv); if{parenti != parentj) { printf{1f %d ======= %d \n" , edge[i].begv , edge[i].endv); sum = sum + edge[i].cost; parent[parentj] = parenti; spanedge+ +;

} }
if{spanedge != n-1) { printf{" spanning tree not po ssible \n"); exit{O); } return sum; } getparent{int parent[] , int v) { while{parent[v] != -1) v = parent[v]; return v; } void main{) { int n,cost[ 10][ 10],i,j,sum; c1rscr{); printf ("\ nHow many nodes in the graph have \n If); scanf ("%d", an); printf ("Enter the cost adj matrix fo r the graph 999 indicates no connection. \n (i=l; i<=n; i+ +) for (j=1; j<=n; j+ +) lf , acost[i][j; scanf (lf%d
lf

); for

void bfs(int n ,int a[10][10], int source, int 5[10]) { for(i=l;i<=n;i+ +) q[i]=(); for(i=l;i<=n;i+ +) if(a[source][i] && s[i]==O) q[ + +r]=i; if( f<= r) { s[q[f]] = 1; bfs(n , a, q[f++] , 5); } }

L* main program * L
void main() { int n,a[10][10],i, j ,source,s[10]; c1rscr(); printf ("\n enter number of nodes in the graph \n "); scanf ("%d", &n); printf ("Enter the adjacency matrix for the graph:\n"); for (i=l; i<=n; i+ +) for (j=I; j<=n; j+ +) scanf ("%d", &a[i][j]); printf ("\n enter the source node in the graph \n "); scanf ("%d", &source); for(i=l;i<=n;i++) s[i]=O; printf(" the bfs travesal of graph is \n"); bfs(n,a,source,s); printf(" the nodes reachable are \n"); for(i=l;i< =n;i+ +) if(s[i]) printf("%d\n",i); } void floyd (int a[][20], int n) { for (k=()i k<ni k++) for (i=()i i<ni i+ +) for (j=()ij<ni j+ +) if(a[i][j] > (a[i][k] + a[k][j] a[i][j] = (a[i][k ] + a[k] [j])i printf(" the dist matrix is \n") for (i=Oi i<ni i+ +) { for (j = 0; j<ni j+ +)

printf("%d\t" , a[i][j]); printf("\n"); } }

1* main program * 1
void main() { int n,a[20][20],i, j ; c1rscr(); scanf ("%d", &n); printf ("Enter the cost adjacency matrix for the graph: \n"); for (i=Oi i<ni i+ +) for (j=Oi j<ni j+ +) scanf ("%d", &a[i][j]); } main() { int n,a[100],total,i,s,r=O,k,x[100]; printf(" enter the number of elements \n"); scanf("%d",&n); printf(" enter the elements \n"); for(i=O;i<n;i+ +) scanf("%d" ,&a[i]); printf(" enter the sum to be computed \n"); scanf("%d" ,&total); for(i=O;i<n;i+ +) x[i]=O; for(i=O;i<n;i+ +) r +=a[i]; sumofsubset(n,a,() ,() , r,total,x); } sumofsubset(int n,int a[100],int t, int k, int r,int total,int x[100]) { int i; I f( s + a[k] = = total) { printf(" subset === { " ); for(i=O;i< =k;i+ +) if(x[i] ) printf("%d ,", a[i]); printf("} \n"); }

else if( s + a[k] + a[k+l] <= total) sumofsubset( n,a,s+a[k],k + 1,r-a[k],total,x); if( (s + r - a[k] >= total) && ( s + a[k+l] <= total) ) { x[k]=(); sumofsubset( n,a,s,k + 1,r-a[k],total,x); }

#include<stdio.h> #include<string.h> char text[200],pat[200],table[200]; int i,j,m,n,f1ag,k; mainO {


c1rscr()

;
lt

printf(It enter the text string\n scanf(lt%slt,text); printf(It enter the pattren string \n scanf(lt%slt ,pat); m = strlen(pat); n = strlen(text); flag = horspool(text,pat,m,n); if( flag != -1)

);

lt

);

printf(It the pattren string is present from %d th charcter \n printf(It the pattren string is not present } Horspool() { for(i=O;i<n;i+ +) table[text[i]]=m; for(j=O;j< =m-2;j+ +) table[pat[j]]=m-1-j; i = m-1; while( i <= n-1 ) {
lt

lt

, f1ag+1); else

);

k = 0;
while( k <= m-1 && pat[m-1-k] == text[i-k] ) k = k + 1; if (k = = m ) return i - m + 1; else i = i table[text[i]]; } return -1; } +

#include<stdio.h> #include<conio.h> void main() { int n,k,c[100][100],i,j,min; c1rscrO; printfC' enter the values of n & k ( n must be> k ) \n"); scanf("%d%d" ,&n,&k); for(i=l;i<=n;i++) foru = l;j< = k;j+ + ) c[i] [j]=O; for(i = 1; i<=n; i++} { foru = 1; j<=i;j++) if( U==I) II (i==j c[i][j] = 1; else c[i][j] = c[i-l][j-l] + c[i-l] [j]; } printf(" binomial coefficient is \n\n"); for(i=l;i<=n;i+ +) { forU=I;j< =k;j++) if(i>=j) printf("%d\t" , c[i][j]); printf("\n")L _ getchO; } }

int prims(int cost[10][10], int n , int source) { int i, j ,u,v,sum,min,d[10],s[10],pri[10]i for (i=li i<=ni i++) { d[i] = cost[source][i]i sri] = pri[i] = sourcei } sum = Oi s[source] = Ii for (i=li i<=n-1i i++) { min = 999i for U=li j<=ni j++) if(s[j] == 0) if(d[j] < min) { min = d[j]i u = ji } sum = sum + d[U]i s[u] = Ii printf(" edge lod ========== lod \n" , pri[u] , U)i for (v=li v<=ni v+ +) if(s[v] == 0) if(cost[u][v] < dry]) { dry] = cost[U][V]i pri[v] = u i

Oi

} return sumi } void mainO { int n,cost[10][10],i,j,source,sumi c1rscrOi printf ("\nHow many nodes in the graph have \n "); scant ("%d", an); printf ("Enter the cost adjacency matrix tor the graph 999 indicates no connection. \n");

for (i=l; i<=n; i+ +) for (j=1; j<=n; j+ +) scanf ("%d", acost[i] [j]);
scant ("%d", &source); it(sum >= 999)

printf ("\n enter the so urce no de \n ");

printf (liThe Spanning tree does not exists: \n" ); else printf (liThe Spanning tree exists min cost is %d:\n" ,sum);

14a > Implementation of DFS #include <stdio.h> void dfs(int n ,int a[10][10], int source, int 5[10]) { s[source] = 1; printf("
%

d=====" , source);

for(i=1;i<=n;i+ +) if(a[source][i] == 1 && sri] == 0) dfs(n,a,i,s); void main() { int n,a[10][10],i, i ,source,s[10]; c1rscrO; printf ("\n enter number of nodes in the graph \n "); scanf ("
% d",

an);

printf ("Enter the adjacency matrix for the graph:\n"); for (i=1; i<=n; i+ +) for (j=1; i< =n; i+ +) scanf ("%d", &a[i][j]); printf ("\n enter the source node in the graph \n "); scanf ("
%

d", &source);

for(i=1;i<=n;i++ ) s[i]=O; printf(" the dfs travesal of graph is \n"); dfs(n,a,source,s);

#include <stdio.h> #include<stdlib.h> int warshall (int a[][20], int n) { for (k=O; k<n; k++) for (i=O; i<n; i++) for (j=0; j<n; j++) a[i][j] =( a[i][j] I I a[i][k] && a[k][j; void main()
{

int n,a[20][20],i, j ; c1rscr(); printf ("\n enter number of nodes in the graph \n "); scanf ("
%

d", an);

printf ("Enter the adjacency matrix for the graph:\n"); for (i=O; i<n; i++) for (j=0; j<n; j++) scanf ("
%

d", &a[i][j;

printf{" the path matrix is \n"); for (i=O; i<n; i++) { for (j = 0; j<n; j++) printf{"
%

d\t" , a[i][j;

printf{" \n");
}
,

. #include<stdio.h> #include<math.h> mainO { int n; c1rscrO; printf(" enter the number of queens \n"); scanf("%d",&n); if( n== 1 II n == 2 II n == 3) printf(" solution cannot be found \n"); nqueen(n); } nqueen(int n) { int k=1,x[100],i,count=0; x[k]=O; while( k !=O) { while( (x[k] <=n) ( place(x,k) == 0 x[k] = x[k] + 1; if( x[k] <= n) { if( k == n) { count++; printf(" \n THE SOLUTION %d === \n",count); for(i=l;i<=n;i+ +) printf("%d\t", x[i]); getchO; } else

{
k++; x[k] =0; } } else k--; } }

place(int x[] , int k) { int i; for(i=l;i<=k-l;i++ ) { if(x[i] = = x[k]) return 0; if(abs(x[i]-x[k]) == abs(i-k return 0; } return 1; }

DAYANANDA SAGAR COLLEGE OF ENGINEERING. DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING. ADA LAB VIVA QUESTIONS

1. 2. 3. 4. 5. 6. 7.

What is an Algorithm? What is the need to study Algorithms? Explain Euclids Algorithm to find the GCD of two integers with an eg. Explain Consecutive Integer Checking algorithm to find the GCD of two numbers with an eg. Middle School Algorithm with an eg. Explain the Seive of Eratosthenis with an eg. Explain the Algorithm desig n and analysis process with a neat diagram. Define: a) Time Efficiency b) Space Efficiency

8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27.

What are the important types of problems that encounter in t he area of computing. What is a Data Struct ure? How are data structures classified? Briefly explain linear and non-linear data structures. What is a Set? How does it differ from a list? What are the different operations that can be performed on a Set? What are the different ways of defining a Set? How can sets be implemented in computer application? What is a Dictionary? Give an example. Briefly discuss the Algorithm Analysis Framework. Write a note on measuring the input size of an algorithm. What are different ways of measuring the running time of an algorithm? What is Order of Growth? Define Worst case, Average case and Best case efficiencies. Explain the Linear Search algorithm. Define O, T, O notations. Give the general plan for analyzing the efficiency of non-recursive algorithms with an eg. Give an algorit hm to find the smallest element in a list of n numbers and analyze the efficiency. Give an algorit hm to check whether all the elements in a list are unique or not and analyze the efficiency. Give an algorit hm to multiply two matrices of order N * N and analyze the efficiency. Give the general plan for analyzing the efficiency of Recursive algorithms wit h an eg.

28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38.

Give an algorit hm to compute the Factorial of a posit ive integer n and analyze the efficiency. Give an algorit hm to solve the Tower of Hanoi puzzle and analyze the efficiency. Define an explicit formula for the nth Fibonacci number. Define a recursive algorithm to compute the nth Fibonacci number and analyze its efficiency. What is Exhaustive Search? What is Traveling Salesman Problem (TSP)? Explain with an eg. Give a Brute Force solution to the TSP. What is the efficiency of the algorithm? What is an Assignment Problem? Explain with an eg. Give a Brute Force solution to the Assignment Problem. What is the efficiency of the algorithm? Explain Divide and Conquer technique and give the general divide and conquer recurrence. Define: a) Eventually non-decreasing function b) Smooth function c) Smoothness rule d) Masters Theorem

39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57.

Explain the Merge Sort algorithm with an eg. And also draw the tree structure of the recursive calls made. Analyze the efficiency of Merge sort algorithm. Explain the Quick Sort algorithm with an example and also draw the tree struct ure of the recursive calls made. Analyze the efficiency of Quick sort algorithm. Give the Binary search algorithm and analyze the efficiency. Give the alg orithm to find the height of a Binary tree and analyze the efficiency. Give an algorit hm each to traverse the binary tree in Inorder, Preorder and Postorder. Explain how do you multiply two large integers and analyze the efficiency of the algorithm. Give an eg. Explain Strassens Matrix multiplication with an eg. And analyze the efficiency. Explain the concept of Decrease and Conquer technique and explain its three major variations. Give the Insertion Sort algorithm and analyze the efficiency. Explain DFS and BFS with an eg. And analyze the efficiency. Give two solutions to sort the vertices of a directed graph Topologically. Discuss the different methods of generating Permutations. Discuss the different methods of generating Subsets. What is Heap? What are the different types of heaps? Explain how do you construct heap? Explain the Heap Sort algorithm with an eg. Explain the Horspools algorithm with an eg.

58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82.

Explain the concept of input enhancement in String Matching What is Hashing? Explain with an eg. Explain the concept of Dynamic programming with an eg. What is Binomial Co-Efficient? Give an algorithm to find the binomial co-efficient and analyze the efficiency. What is Transitive closure? Explain how do you find out the Transitive closure with an eg. Give the Warshalls algorithm and analyze the efficiency. Explain how do you solve the All-Pairs-Shortest-Paths problem with an eg. Give the Flloyds algorithm and analyze the efficiency. What is Knapsack problem? Give the solution to solve it using dynamic programming technique. What are Memory functions? What are the advantages of using memory functions? Give an algorit hm to solve the knapsack problem. Explain the concept of Greedy technique. Explain Prims algorithm with an eg. Prove that Prims algorithm always yields a minimum spanning tree. Explain Kruskals algorithm with an eg. Explain Quick find and Quick union implementations of disjoint subsets Explain Dijkstras algorithm with an eg . What are Huffman trees? Explain how to construct Huffman trees with an eg. Explain the concept of Backtracking with an eg. What is a state space tree? Explain how to construct a state space tree? What is n-Queens problem? Generate the state space tree for n = 4. Explain the subset sum problem with an eg. What are Decision Trees? Explain. Define P, NP and NP-Complete problems. Explain the Branch and Bound technique with an eg.

Você também pode gostar