ADA _Lab Manual_BCSL404
ADA _Lab Manual_BCSL404
Reviewed By
Prof. MITHUNA H R
Assistant Professor
Approved By:
Dr. Kala Venugopal
Head of Department Information Science and Engineering
MISSION OF INSTITUTE
“To be center of Academic and Research excellence in the field of Information Technology
inculcating value based education for the development of quality Human Resource”
“Equip students with fundamental concepts, practical knowledge and professional ethics through
dedicated faculty for higher studies and professional career in various Scientific, Engineering and
Technological streams leading to proficiency in the field of Information Technology”
PROGRAM SPECIFIC OUTCOMES (PSOs)
PSO1: Able to apply knowledge of information management and communication systems to provide secured
solutions for real time engineering applications.
PSO2: Apply best software engineering practices, modern tools and technologies to deliver quality products.
COURSE OUTCOMES
Course Outcomes-Program Outcomes mapping
CO1 Develop programs to solve computational problems using suitable algorithm design strategy.
Compare algorithm design strategies by developing equivalent programs and observing running times for
CO2
analysis (Empirical).
CO3 Make use of suitable IDE tools to develop programs
Choose appropriate algorithm design techniques to develop solution to the computational and complex
CO4
problems.
CO5 Demonstrate and present the development of program, its execution and running time(s) and record the
results/inferences
CO2 3 3 3 1 3 2 1 3 2 2
CO3 2 2 2 3 2 2 3 2 2
CO4 3 3 2 1 1 2 2 3 2 2
CO5 3 3 2 1 3 2 2 3 2 2
The internals marks of lab for 2022 scheme is 30 Marks for Continuous Evaluation and 20 Marks for Lab
Internals.
Continuous Evaluation for 2022 scheme:
Sl Parameters Mark 10 6 2 0
No
1. Writing 10 The student is The student is The student has The student is
Program/Logic able to write able to write the written not attempted
(present the program program with incomplete to write
week’s/previous without any minor logical program with program.
week’s) logical and error major logical
syntactical and syntactical
error and error
proper
indentation is
followed.
2. Implementation in the 10 Student is able Student is able Student is The student
target language with to execute, to execute the executed the has not
different inputs debug, and test program, but program executed the
the program fails to debug, partially(fails to program.
for all possible and test the meet desired
inputs/test program for all output)
cases. possible
inputs/test
cases.
Parameters 6 4 2 0
2 Design and implement C/C++ Program to find Minimum Cost Spanning Tree of a given
connected undirected graph using Prim's algorithm. 11-14
3 a. Design and implement C/C++ Program to solve All-Pairs Shortest Paths problem 15-18
using Floyd's algorithm.
b.Design and implement C/C++ Program to find the transitive closure using Warshal's
algorithm.
4 Design and implement C/C++ Program to find shortest paths from a given vertex in a 19-21
weighted connected graph to other vertices using Dijkstra's algorithm.
5 Design and implement C/C++ Program to obtain the Topological ordering of vertices in 22-23
a given digraph
6 Design and implement C/C++ Program to solve 0/1 Knapsack problem using Dynamic 24-26
Programming method.
7 Design and implement C/C++ Program to solve discrete Knapsack and continuous 27-28
Knapsack problems using greedy approximation method.
8 Design and implement C/C++ Program to find a subset of a given set S = {sl , 29-30
s2,.....,sn} of n positive integers whose sum is equal to a given positive integer d.
9 Design and implement C/C++ Program to sort a given set of n integer elements using 31-31
Selection Sort method and compute its time complexity. Run the program for varied
values of n> 5000 and record the time taken to sort. Plot a graph of the time taken
versus n. The elements can be read from a file or can be generated using the random
number generator.
10 Design and implement C/C++ Program to sort a given set of n integer elements using 32-33
Quick Sort method and compute its time complexity. Run the program for varied values
of n> 5000 and record the time taken to sort. Plot a graph of the time taken versus n.
The elements can be read from a file or can be generated using the random number
generator.
11 Design and implement C/C++ Program to sort a given set of n integer elements using 34-35
Merge Sort method and compute its time complexity. Run the program for varied
values of n> 5000, and record the time taken to sort. Plot a graph of the time taken
versus n. The elements can be read from a file or can be generated using the random
number generator.
12 Design and implement C/C++ Program for N Queen's problem using Backtracking. 36-37
Analysis & Design of Algorithms Lab (BCSL404)
2023-24
LABORATORY PROGRAMS
1. Design and implement C/C++ Program to find Minimum Cost Spanning Tree of a given
connected undirected graph using Kruskal's algorithm.
#include<stdio.h>
void main()
{ int n,v,u,cost[10][10],parent[10]={0},i,j;
int count=1,mincost=0,min,a,b;
printf("\n enter no of vertices");
scanf("%d",&n);
printf("\n enter cost matrix");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=999;
}
while(count<n)
{ min=999;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]<min)
{ min=cost[i][j];
a=u=i;
b=v=j;
}
while(parent[u])
u=parent[u];
while(parent[v])
v=parent[v];
if(u!=v)
{
count++;
printf("\n edge(%d,%d)=%d",a,b,min);
mincost+=min;
parent[v]=u;
}
cost[a][b]=cost[b][a]=999;
} /*End of While */
printf("\n minimum cost=%d",mincost);
}
**********************END OF PROGRAM******************
/*OUTPUT
Enter no of vertices 6
edge(4,5)=1
edge(5,6)=2
edge(2,3)=3
edge(3,4)=4
edge(1,2)=7
minimum cost=17 */
2) Design and implement C/C++ Program to find Minimum Cost Spanning Tree of a given
#include <stdio.h>
int a,b,u,n,i,j,ne=1,v;
int visited[10],min,mincost=0,cost[10][10];
int main()
{
printf("\n Enter the no of vertices & graph data : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\n(%d,%d):",i,j);
scanf("%d",&cost[i][j]);
if(cost[i]==0)
cost[i][j]=999;
}
}
for(i=0;i<=n;i++)
visited[i]=0;
printf("\n The edges of spanning tree are :\n");
visited[1]=1;
while(ne<n)
{
for(i=1,min=999;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(cost[i][j]<min)
{
if(visited[i]==0)
continue;
else
{
min=cost[i][j];
a=u=i;
b=v=j;
}
}
}
}
if(visited[u]==0||visited[v]==0)
{
printf("\n %d edge (%d,%d) = %d",ne++,a,b,min);
mincost+=min;
visited[b]=1;
}
cost[a][b]=cost[b][a]=999;
}
printf("\n\n\n Minimum cost : %d",mincost);
return 0;
}
******************************END OF PROGRAM**************************
/* OUTPUT
(1,1):999
(1,2):1
(1,3):8
(1,4):2
(1,5):999
(1,6):999
(2,1):1
(2,2):999
(2,3):9
(2,4):999
(2,5):999
(2,6):999
(3,1):8
(3,2):9
(3,3):999
(3,4):7
(3,5):6
(3,6):999
(4,1):2
(4,2):999
(4,3):7
(4,4):999
(4,5):5
(4,6):3
(5,1):999
(5,2):999
(5,3):6
(5,4):5
(5,5):999
(5,6):4
(6,1):999
(6,2):999
(6,3):999
(6,4):3
(6,5):4
(6,6):999
1 edge (1,2) = 1
2 edge (1,4) = 2
3 edge (4,6) = 3
4 edge (6,5) = 4
5 edge (5,3) = 6
Minimum cost : 16 */
3a. Design and implement C/C++ Program to solve All-Pairs Shortest Paths problem using Floyd's
Information Science & Engineering,AIT Bangalore 14
Analysis & Design of Algorithms Lab (BCSL404)
2023-24
algorithm.
#include<stdio.h>
#include<time.h>
#define INFINITY 999
int min(int a,int b)
{
return a<b?a:b;
}
int main(void)
{
int a[10][10],n,i,j;
double startTime,endTime;
printf("\n Enter the no. of vertices:");
scanf("%d",&n);
printf("\n Enter the cost matrix, 0-self loop and 999-no edge\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
startTime=clock();
floyd(a,n);
endTime =clock();
printf("\n Shortest path matrix:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("Time taken is %10.9f\n",(double)(endTime-startTime));
return 0;
}
*******************************/
3b. Design and implement C/C++ Program to find the transitive closure using Warshal's
algorithm.
#include<stdio.h>
void warshall(int a[10][10],int n);
void main()
{
int i,j,n,a[10][10];
printf("enter the no of vertices\n");
scanf("%d",&n);
printf("enter the adjacency matrix\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf("(%d ,%d):",i,j);
scanf("%d",&a[i][j]);
}
warshall(a,n);
printf("Transitive closure for the given graph is \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
}
/******************OUTPUT***********************
*****************************************/
4. Design and implement C/C++ Program to find shortest paths from a given vertex in a weighted
#include<stdio.h>
int n,cost[10][10],dist[10];
int min(int a,int b);
void read_mat(int n)
{
int i,j;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf("(%d,%d)",i,j);
scanf("%d",&cost[i][j]);
}
}
if(a<b)
return a;
else
return b;
}
void main()
{
int i,j,s;
printf("enter the num of vertices\n");
scanf("%d",&n);
printf("enter the costadjacency matrix(999 for no edge);\n");
read_mat(n);
printf("enter source vertex\n");
scanf("%d",&s);
shortestpath(n,s);
printf("the shortest path b/n vertex %d to",s);
for(i=1;i<=n;i++)
printf("vertex %d is %d\n",i,dist[i]);
}
/* OUTPUT****
enter the num of vertices
6
enter the costadjacency matrix(999 for no edge);
(1,1)999
(1,2)6
(1,3)999
(1,4)7
(1,5)999
(1,6)999
(2,1)6
(2,2)999
(2,3)2
(2,4)3
(2,5)5
(2,6)999
(3,1)999
(3,2)2
(3,3)999
(3,4)999
(3,5)999
(3,6)4
(4,1)7
(4,2)3
(4,3)999
(4,4)999
(4,5)2
(4,6)999
(5,1)999
(5,2)5
(5,3)999
(5,4)2
(5,5)999
(5,6)3
(6,1)999
(6,2)999
(6,3)4
(6,4)999
(6,5)3
(6,6)999
enter source vertex
1
the shortest path b/n vertex 1 tovertex 1 is 0
vertex 2 is 6
vertex 3 is 8
vertex 4 is 7
vertex 5 is 9
vertex 6 is 12
*/
5. Design and implement C/C++ Program to obtain the Topological ordering of vertices in a given
digraph.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int i,j,k,n,a[10][10],indeg[10],flag[10],count=0;
printf("enter the number of vertices\n");
scanf("%d",&n);
printf("enter the adjacency matrix \n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<n;i++)
{
indeg[i]=0;
flag[i]=0;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
indeg[i]=indeg[i]+a[j][i];
printf("topological order is \n");
while(count<n)
{
for(k=0;k<n;k++)
{
if((indeg[k]==0)&&(flag[k]==0))
{
printf("%d->",(k+1));
flag[k]=1;
for(i=0;i<n;i++)
{
if(a[k][i]==1)
indeg[i]--;
}
}
}
count++;
}
printf("\n");
return 0;
}
/* OUTPUT
enter the number of vertices
6
enter the adjacency matrix
011000
000100
000100
000011
000000
000000
topological order is
1->2->3->4->5->6->
*/
6. Design and implement C/C++ Program to solve 0/1 Knapsack problem using Dynamic
Programming method.
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<math.h>
int max(int,int);
int v[10][10],w[10],p[10],x[10],count=0;
int findobjects(int n,int m);
void main()
{
int m,n,i,j;
printf("enter the number of objects\n");
scanf("%d",&n);
printf("enter the capacity of knapsack\n");
scanf("%d",&m);
printf("enter the weights of the objects\n");
for(i=1;i<=n;i++)
scanf("%d",&w[i]);
printf("enter the profits\n");
for(i=1;i<=n;i++)
scanf("%d",&p[i]);
for(i=0;i<=n;i++)
{
for(j=0;j<=m;j++)
{
if(i==0||j==0)
v[i][j]=0;
else if(j<w[i])
v[i][j]=v[i-1][j];
else
v[i][j]=max(v[i-1][j],v[i-1][j-w[i]]+p[i]);
}
}
printf("the output is:\n");
for(i=0;i<=n;i++)
{
for(j=0;j<=m;j++)
{
printf("%d\t",v[i][j]);
}
printf("\n");
}
printf("maximum profit is:%d\n",v[n][m]);
findobjects(n,m);
printf("objects included in knapsack \n");
for(i=1;i<=count;i++)
printf("%d\t",x[i]);
}
/* OUTPUT
*/
7. Design and implement C/C++ Program to solve discrete Knapsack and continuous Knapsack
problems using greedy approximation method.
#include<stdio.h>
void knapsack(int n, float weight[], float profit[], float capacity)
{
float x[20], tp = 0;
int i, j, u;
u = capacity;
if (i < n)
x[i] = u / weight[i];
tp = tp + (x[i] * profit[i]);
int main() {
float weight[20], profit[20], capacity;
int num, i, j;
float ratio[20], temp;
temp = weight[j];
weight[j] = weight[i];
weight[i] = temp;
temp = profit[j];
profit[j] = profit[i];
profit[i] = temp;
}
}
}
knapsack(num, weight, profit, capacity);
return(0);
}
/*OUTPUT
#include "stdio.h"
#include "math.h"
int i,j,k,set[10],d;
int n;
double pow(double,double);
void subset(int [],int,int);
int main()
{
printf("\n Enter the no of Elements : ");
scanf("%d",&n);
printf("\n Enter the Elements \n");
for(i=0;i<n;i++)
scanf("%d",&set[i]);
printf("\n Enter the Sum : ");
scanf("%d",&d);
subset(set,n,d);
return 0;
}
printf("\n\t %d",set[j]);
}
}
}
if(flag==0)
printf("\n No solutions are found!!!");
}
Output:
9. Design and implement C/C++ Program to sort a given set of n integer elements using Selection
Sort method and compute its time complexity. Run the program for varied values of n> 5000 and
record the time taken to sort. Plot a graph of the time taken versus n. The elements can be read
from a file or can be generated using the random number generator.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAX 300000
int n;
int main()
{
int a[MAX];
double startTime,endTime;
int i,j,temp,min;
printf("Enter the number of elements to sort\n");
scanf("%d",&n);
//To generate numbers randomly and store in array
for(i=0;i<n;i++)
a[i]=rand(); //rand() function to generate n random numbers
printf("\nBefore Sorting:\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
startTime=clock();
for(i=0;i<=n-2;i++)
{
min=i;
for(j=i+1;j<=n-1;j++)
{
if(a[j]<a[min])
min=j;
}
temp=a[min];
a[min]=a[i];
a[i]=temp;
}
endTime = clock();
printf("After Sorting:\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
printf("Time taken is %10.9f\n",(double)(endTime-startTime));
return 0;
}
10. Design and implement C/C++ Program to sort a given set of n integer elements using Quick
Sort method and compute its time complexity. Run the program for varied values of n> 5000 and
record the time taken to sort. Plot a graph of the time taken versus n. The elements can be read
from a file or can be generated using the random number generator.
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define MAX 500000
int partition(int a[],int low,int high);
int swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
return temp;
}
}
}
void main()
{
int a[MAX],n,i,low,high;
clock_t start,end;
float duration;
printf("\n enter the number of elements to sort");
scanf("%d", &n);
printf("\n elements are:\n");
for(i=0;i<n;i++)
{
//scanf("%d",&a[i]);
a[i]=random();
printf(“Before Sorting\n”);
printf("%d\t",a[i]);
}
printf("\n");
start=clock();
low=0,high=n-1;
quicksort(a,low,high);
end=clock();
duration=(end-start);
printf("\n sorted array is::\n");
for(i=0;i<n;i++)
printf("\n\t%d",a[i]);
printf("\n");
printf("time taken is %f",duration);
}
11. Design and implement C/C++ Program to sort a given set of n integer elements using Merge
Sort method and compute its time complexity. Run the program for varied values of n> 5000, and
record the time taken to sort. Plot a graph of the time taken versus n. The elements can be read
from a file or can be generated using the random number generator.
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<time.h>
#define MAX 300000
void simple_merge(int a[],int low,int mid,int high);
void merge_sort(int a[],int low,int high);
int n;
int main(void)
{
int a[MAX],i=0;
double startTime,endTime;
printf("Enter the number of elements to sort\n");
scanf("%d",&n);
//To generate randomly
for(i=0;i<n;i++)
a[i]=rand();
printf("\nBefore Sorting:\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
startTime=clock();
merge_sort(a,0,n-1);
endTime = clock();
printf("After Sorting:\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
printf("Time taken is %10.9f\n",(double)(endTime-startTime));
return 0;
}
else
{
c[k]=a[j];
j++;
k++;
}
}
while(i<=mid)
c[k++]=a[i++];
while(j<=high)
c[k++]=a[j++];
for(i=low;i<=high;i++)
a[i]=c[i];
}
12. Design and implement C/C++ Program for N Queen's problem using Backtracking.
#include<stdlib.h>
#include <stdio.h>
int count=0,x[5];
int nqueen(int,int);
int main()
{
int n;
printf("\n enter the number of queen");
scanf("%d",&n);
nqueen(1,n);
if(count==0)
printf("\n no solution found");
else
printf("\n number of solution found is:%d",count);
return 0;
}
printf("Q\t");
else
printf("0\t");
printf("\n");
}
printf("\n");
}
else
nqueen(k+1,n);
}
}
return 0;
}
/**************OUTPUT***************
solution=2
0 0 Q 0
Q 0 0 0
0 0 0 Q
0 Q 0 0
*************************/
finite number of input and generates valid finite number of output and should terminate within finite
amount of time.
2. What is a Flow Chart?
Flow chart is a Graphical Representation of a solution to the Problem.
3. What is the difference between Algorithm, Flow Chart, and Program?
● Algorithm specifies the different steps to be followed for solving a Problem.
● Flow Chart is a Graphical Representation of an Solution to the Problem.Both Algorithm and Flow
Chart are Machine Independent.
● Program is a Set of Instructions which is used as a tool to communicate to the machine to get our
work done, Program is Machine Dependent for particular Machine.
4. What is the Aim of DAA lab or why we need to study DAA Lab?
DAA is a discipline, where we are dealing with designing or writing the algorithm keeping in
Consideration of Space and Time Complexity, Such that Our Algorithm should execute in a very
minimum amount of time by Minimum Space or RAM.
5. Define Space and Time Complexity? Among this which one is more prioritized?
Space Complexeity is a measure of Amount of Space taken by a Program to finish its Execution.
Time Complexeity is a measure of amount of time taken by a program to complete its
Execution.Depending Upon Application it is considered, EX: For Mobile or Handheld Devices,We
give Preference for both Space and time.
For a Huge and Inter active Systems like Web Applications we give more Preferences to time
Complexeity.
6. What is Design and what is Analysis of a Program?
Design is a Process of Writing an algorithm to a given Problem so that it should accept finite number
of input and generates valid finite number of output and Should exit appropriately.
Analysis: Analysis is a next Phase of Writing an Algorithm, in this phase we calculate the Efficiency
of an Algorithm i.e time and space needed by an algorithm.
7. Write the general plan for analysing the recursive algorithms.
Identify the inputs.
Identify the output is depended only on number of inputs.
Identify the Basic Operation in ALgorithm.
Form or write the Recursive Relation to the Algorithm.
▪ Limitations of Algorithms:Explain few things about Decision trees and its use in solving a
Problem.
▪ Coping with Limitations of Algorithms:Explain Backtracking and one problem which
illustrates about Backtacking method and Wind Up.
12. What is the Time Complexeity of Bubble Sort,Selection Sort ,Merge Sort,Quick Sort?
Bubble Sort-n2,
Selection Sort- n2
Merge Sort-nlog.n
Quick Sort -nLogn, Worst case for Quick Sort- n2
13. Which sorting agorithm is more Efficient and why?
Quick Sorting is More Efficient ,because this algorithm is instable algorithm and
inplace.
14. What do you mean by the term Instable Algorithms.
The Instable Algorithms are one,which lower index is greater than higher index
15. Which algorithms are faster?
Instable Algorithms are much Faster compared to Stable Algorithms.
16. For what type of instance Merge sort do better than Quick Sort?
For an Larger input and a sorted input values.
17. For what type of instance Quick sort do better than Merge Sort?
For Smaller Set of input numbers.
18. What are Inplace Algorithms?
Inplace Algorithms are the one which doesn't occupies Extra Space.
19. Write the order of growth terms as per the time Execution in Ascending Order.
logn,n,nlogn,n2,n3,......nn,2n,n!
20. What is Brute Force Technique? When We Should USe?
Brute Force is a straight Forward Technique to solve a problem, we used to solve a Problem
through this approach when we don't have sufficient data to solve a problem in Efficient Way.
21. What is the difference between Divide and Conquer, Decrease and ConQuer?
Divide and Conquer can be solved to solve a problem with a larger data set and when there is no
dependency between any of the data sets.
❖ Divide and Solve as Small as Small sets.
30. Differentiate between Prims and Kruskals Algorithm for finding MST.
In Prims We consider any one vertex in the graph as Source and We compute the distance from that
source to other vertices ,after computing the vertices which has minimum value among (n-1) vertices is
added to tree vertices and that respective edges added to tree Edges Set.The above mentioned Process
continues till we reach (n-1) vertices.
In Kruskals we first arrange the edges in Ascending Order and then we start to form the tree which
wont form cycles,if adding that edges forms cycles then that edges is dropped from adding to tree
edges.The above said process is continues till we reach the count of
(N-1) Vertices.
31. What is the Application of Prims and Kruskals Algorithm?
In Networks to remove the Cyclicity of the Network.
32. Explain Job Sequencing With Deadlines?
Placing or scheduling the maximum number of Jobs to a machine without violating the deadlines
constraint of any of the Jobs in Sequence.
33. Why the Name Bubble Sort named?
Because in first Pass the first highest data will bubbles up, so since the largest element bubbles
up in the first and second largest element bubbles up in the Second pass and so on, so hence the name
bubble sort.
34. Why the Name Selection Sort?
The Selection sort is named because we initially first select an arrays first element as minimum and
will compare with other elements ,so in pass one first least element goes to the first position and so
on so forth for 2nd,3rd and so on.Selecting
35. What is the difference between Brute force strings matching to Horspool String Matching
Method?
In brute Force we compare each and every element of the text to the pattern by shifting the text
position by one and in Horspool method we shift it by number of shift positions recorded in the shift
table.
36. Explain Merge Sort?
In Merge Sort will divide the entire input set by 2 until we reach low<high and later will find a
solution to each item by comparing half of the array data set to the other half array data set and
finally we merge it to form a sinle array(conquer)
37. What is the Basic Operations in Merge sort and Quick sort?
In Merge Sort the Basic Operations is Comparisions and in Quick sort basic Operations is
Partitioning and hence also known as partitioning sort.
38. Why the Insertion Sort?
We are Inserting an element to its suitable place by comparing n elements for each pass.
39. What is the Use of DFS and BFS?
DFS and BFS both used to check the Connectivity of a graph, Cyclicity in a graph, Spanning tree of
a graph.
40. Differentiate between DFS and BFS.
DFS and BFS are both the Graph Traversing Technique, in which DFS Traverse the Graph in a
depth wise (Vertical) and BFS Traverse the Graph from left to right (Horizontal)
41. Which Data structures used in BFS and DFS.
BFS USes Queue as its data structure and DFS uses as stack its Data structure.
42. What are back edges in DFS and Cross Edges in BFS?
Back Edges and Cross edges are the Edges which already visited by an ancestor node.
43. What is Topological Sorting?
Topological Sorting is a Sorting Technique used for sorting Vertices in the Graph.
44. What is the Conditions necessary for a Topological Sorting
For a Topological Sorting the Graph Should be DAG (Directed Acyclic Graph)
45. What are the Different methods used to solve a topological Sorting?
(i) Source Removal Method
(ii) Using DFS based Scheme.
What is the Use of Topological Sorting?
Use of Topological Ordering is in the field of Operating System for Scheduling and in
Networks, Automation and Robotics.
46. What is Dijikstra's Algorithm?
Dijikstra's Algorithm is used to find the Single shortest Path from source to the other vertex.
47. What is a graph?
Graph is a component which is having a set of Edges and vertices G= {V, E}
48. What are the different ways that can be represents a graph?
Adjaceny Matrix and Adjacency List.
Masm,Tasm.The Size of the Procedures is small Compared to Functions and it uses the Mnemonics
like JLR,ADD,SUB,DIV,CMP and etc.
SubRoutines: Same as above (Procedures, used in languages like FORTRAN)
Macros: Macros are the functions which is small in Size, usually used as Library files, it is invoked
only if it is needed.
74. Name Standard Input, Standard output, Standard Error.
Standard Input-Keyboard
Standard Output-Monitor
Standard Error-Monitor
75. What are standard I/O functions?
printf () and scanf()
76. What is the use of using getch () in every Program? Does it Impact to the ouput of the
Program?
getch () is a informal input functions which makes the output screen to be displayed until we enter a
character(Read-input operations)
getch () doesn’t Impact in anyways
77. What are Command line Arguments
The Arguments which are passed at command line to the function main ()
Are called as Command line Arguments.