Bms Institute of Technology Department of Mca Sub Code - 16mca38 Algorithms Laboratory Viva Questions
Bms Institute of Technology Department of Mca Sub Code - 16mca38 Algorithms Laboratory Viva Questions
Viva Questions
1) What is the time complexity of linear search?
Θ(n)
Θ(log2n)
4. If the middle element is greater than the item being searched, this process
is repeated in the upper half of the list.
5. If the middle element is lesser than the item being searched, this process is
repeated in the lower half of the list.
6) What is heap?
A heap can be defined as a binary tree with keys assigned to its nodes
( one key per node) provided the following two conditions are met:
2. The parental dominance requirement – The key at each node is greater than
or equal to the keys at its children.
Θ( n logn)
Where the given array is divided into two equal parts. The left part of the array
as well as the right part of the array is sorted recursively. Later, both the left
part and right part are merged into a single sorted array.
n log n.
Brute force
(n2)
Yes.
Yes.
Algorithm selects the smallest number in the array and places it in its final
position the sorted array.
Selection Sort algorithm requires (n-1) swaps & hence (n) memory
writes. Thus it can be very useful if writes are the most expensive operation.
Greedy Technique.
To find the shortest path from source vertex to all other remaining vertices
A graph is said to be connected if for every pair of its vertices u and v there
is a path from u to v.
In TSP, given n cities with known distances b/w each pair , find the shortest
tour that passes through all the cities exactly once before returning to the
starting city.
In Dijkstra’s Algorithm, find the shortest path from source vertex to all other
remaining vertices
Dijkstra’s algorithm is to find the shortest path from source vertex to all
other remaining vertices.
It finds its application even in our day to day life while travelling.
(I) Divide the instance of a problem into two or more smaller instances
these solutions
Advantage: Fastest among all sorting algorithms Suitable when the input
size is very large
Disadvantage:
Recursion
46) When do you say that a Quick sort having best case complexity?
When the pivot exactly divides the array into equal half
47) When do you say that Quick sort having worst case complexity?
48) How many more comparisons are needed for average case
compared to best case?
38% more
49) when do you say that the pivot element is in its final position?
When all the elements towards the left of pivot are <= pivot and all the
elements towards the right of pivot are >= pivot.
macro defines the number of clock ticks per second which is available in the
TIME.H header file.
greedy technique
Joseph Kruskal.
It proceeds in a concentric manner by visiting first all the vertices that are
adjacent to a starting vertex, then all unvisited vertices two edges apart from it
and so on , until all the vertices are in the same connected component as the
starting vertex are visited.
57) What are Tree edge, Back edge & Cross edge ?
Tree edge: whenever a new unvisited vertex is reached for the first time, it is
attached as a child to the vertex from which it is being visited. Such an edge is
called a tree edge.
Back edge: An edge leading to a previously visited vertex other than its
immediate predecessor. Such an edge is called a back edge
Cross edge If an edge leading to a previously visited vertex other than its
immediate predecessor (i.e. its parent in the tree). Is encountered, the edge is
noted as a cross edge.
58) What are the various applications of BFS & DFS tree traversal
technique?
Application of BFS
Check whether there is only one root in the BFS forest or not.
If there is only one root in the BFS forest, then it is connected graph
otherwise disconnected graph.
Application of DFS
Topological sorting.
59) Which data structures are used in BFS & DFS tree traversal
technique?
60) What are the efficiencies of BFS & DFS algorithms for Adjacency
matrix and adjacency list representation?
Any subsets involving aj can be listed only after all the subsets involving
a1,…,aj-1(j=1,2,…,n-1)
Decrease by constant
It is a table that stores the shift information i.e it stores the distance of
each rightmost character in the first “m-1” characters of the pattern from the
last character of the pattern and stores the length of the pattern as the shift size
if the character is not present in the pattern.
In Horspool, if there is a mismatch then the shift size is obtained from the
shift table and the pattern is shifted accordingly.
-Bad symbol shift table (same as the shift table used by Horspool).The shift
information of this table is known as d1
Both solve the problems by dividing the problem into sub problems.
Using the solutions of sub problems, the solutions for larger instance of the
problem can be obtained.
74) What is the Space & Time complexity of DP algo for Binomial
Coefficient C(n, k)?
Θ(nk)
Only one instance of the sub problem is computed & stored. If the
same instance of sub problem is encountered, the solution is retrieved from the
table and never recomputed.
Greedy technique.
Locally optimal: i.e. it has to be the best local choice among all feasible choices
available on that step.
Unseen vertices : vertices which are not adjacent are called unseen.
They are helpful in routing applications: In the case of network where large
number of computers are connected, to pass the data from one node to another
node we can find the shortest distance easily by this algorithm.
Yes
- In which the element dij indicates the length of the path from ith vertex to the
jth vertex.
- It is the path which is having shortest length among all possible paths.
Non-optimization problem
Transitive property
Back tracking and branch and bound techniques used for large instance of
combinatorial problems.
Branch and Bound uses Best first search technique and is applicable to
optimization problems.