0% found this document useful (0 votes)
316 views13 pages

Bms Institute of Technology Department of Mca Sub Code - 16mca38 Algorithms Laboratory Viva Questions

The document contains questions and answers related to algorithms and data structures. It discusses time complexities of algorithms like linear search, binary search, and heap sort. It also summarizes merge sort, selection sort, and quicksort algorithms. Key concepts covered include binary trees, graphs, Dijkstra's algorithm, dynamic programming, and divide and conquer technique. Application of these algorithms and strategies to problems like traveling salesman, knapsack, and shortest paths are also mentioned.

Uploaded by

Anjan HR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
316 views13 pages

Bms Institute of Technology Department of Mca Sub Code - 16mca38 Algorithms Laboratory Viva Questions

The document contains questions and answers related to algorithms and data structures. It discusses time complexities of algorithms like linear search, binary search, and heap sort. It also summarizes merge sort, selection sort, and quicksort algorithms. Key concepts covered include binary trees, graphs, Dijkstra's algorithm, dynamic programming, and divide and conquer technique. Application of these algorithms and strategies to problems like traveling salesman, knapsack, and shortest paths are also mentioned.

Uploaded by

Anjan HR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

BMS INSTITUTE OF TECHNOLOGY


DEPARTMENT OF MCA
SUB CODE – 16MCA38
ALGORITHMS LABORATORY

Viva Questions
1) What is the time complexity of linear search?

Θ(n)

2) What is the time complexity of binary search?

Θ(log2n)

3) What is the major requirement for binary search?

The given list should be sorted.

4) What is binary search?

It is an efficient method of finding out a required item from a given list,


provided the list is in order.

The process is:

1. First the middle item of the sorted list is found.

2. Compare the item with this element.

3. If they are equal search is complete.

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.

5) What is parental dominance?


The key at each node is greater than or equal to the keys at its children.

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:

DEPARTMENT OF M.C.A Page 1


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

1 The tree’s shape requirement – The binary tree is essentially complete ( or


simply complete), that is, all its levels are full except possibly the last level,
where only some rightmost leaves may be missing.

2. The parental dominance requirement – The key at each node is greater than
or equal to the keys at its children.

7) What is height of Binary tree?

It is the longest path from the root to any leaf.

8) What is the time complexity of heap sort?

Θ( n logn)

9) What is Merge Sort?

Merge sort is an O (n log n) comparison-based sorting algorithm.

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.

10) Who invented Merge Sort?

John Von Neumann in 1945.

11) On which paradigm is it based?

Merge-sort is based on the divide-and-conquer paradigm.

12) What is the time complexity of merge sort?

n log n.

13) What is the space requirement of merge sort?

Space requirement: Θ(n) (not in-place).

14) When do you say an algorithm is stable and in place?

Stable – if it retains the relative ordering.

In – place if it does not use extra memory.

15 ) Name the design strategy used in Selection Sort.

Brute force

DEPARTMENT OF M.C.A Page 2


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

16) Define Brute force strategy.

Brute force is a straight forward approach to solving a problem, usually


directly based on the problem’s statement and definitions of the concepts
involved.

17) What is the time complexity of Selection Sort algorithm?

(n2)

18) Is Selection Sort Inplace?

Yes.

19) Is Selection Sort stable?

Yes.

20) Why is the name Selection Sort?

Algorithm selects the smallest number in the array and places it in its final
position the sorted array.

21) When is Selection Sort algorithm useful?

Selection Sort algorithm is useful for small inputs because it requires


(n ) comparisons.
2

Selection Sort algorithm requires (n-1) swaps & hence (n) memory
writes. Thus it can be very useful if writes are the most expensive operation.

22) What are the drawbacks of Selection Sort?

Inefficient on large lists.

It requires same number of iterations no matter how well-organized the


array is.

It uses internal sorting, means it would require the entire array to be in


main memory.

23) When is a problem said to have overlapping sub problems?

DEPARTMENT OF M.C.A Page 3


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

A problem is said to have overlapping subproblems if it can be broken down into


subproblems which are reused multiple times. This is closely related to
recursion.

24) What is principle of optimality?


The optimal solution to any instance of an optimization problem is composed
of optimal solutions to its subinstances.

25) Can knapsack problem be solved in any other technique?


It can be solved using many other techniques such as BruteForce, Greedy
technique, Branch and bound etc..

26) Mention few applications of dynamic programming.


Can be applied to find factorial, fibonacci numbers in which the required value
may depend on previously computed values.
To find the longest common substrings of the strings "ABAB", "BABA" and
"ABBA" are the strings "AB" and "BA" of length 2. Other common substrings are
"A", "B" and the empty string “”. etc..

27) Compare Dynamic programming and Divide and conquer.


Dynamic programming differs from the "Divide and Conquer" (D-and-C)
method in the fact that the problems solved by D-and-C can have many non-
overlapping subproblems - i.e, new subproblems may be generated when the
method is applied.
Both use recursion.

28) Who invented Dijkstra’s Algorithm?

Edsger Dijkstra invented this algorithm.

29) What is the other name for Dijkstra’s Algorithm?

Single Source Shortest Path Algorithm.

30) Which technique the Dijkstra’s algorithm is based on?

Greedy Technique.

31) What is the purpose of Dijkstra’s Algorithm?

To find the shortest path from source vertex to all other remaining vertices

32) Name the different algorithms based on Greedy technique.

Prim’s Algorithm, Kruskal’s algorithm

DEPARTMENT OF M.C.A Page 4


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

33) What is the constraint on Dijkstra’s Algorithm?

This algorithm is applicable to graphs with non-negative weights only.

34) What is a Weighted Graph?

A weighted graph is a graph with numbers assigned to its edges. These


numbers are called weights or costs.

35) What is a Connected Graph?

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.

36) What is the time complexity of Dijkstra’s algorithm?

For adjacency matrix, It is O(IVI*IVI)

For adjacency list with edges stored as min heap, it is O(IEIlogIVI)

37) Differentiate b/w Traveling Salesman Problem(TSP) and Dijkstra’s


Algorithm.

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

38) Differentiate b/w Prim’s Algorithm and Dijkstra’s Algorithm?

Prim’s algorithm is to find minimum cost spanning tree.

Dijkstra’s algorithm is to find the shortest path from source vertex to all
other remaining vertices.

39) What are the applications of Dijkstra’s Algorithm?

It finds its application even in our day to day life while travelling.

They are helpful in routing applications.

40) Who was the inventor of the Quicksort?

C.A.R.HOARE, a British Scientist.

DEPARTMENT OF M.C.A Page 5


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

41) Which design strategy does Quicksort uses?

Divide and Conquer

42) What is Divide and Conquer Technique?

(I) Divide the instance of a problem into two or more smaller instances

(II) Solve the smaller instances recursively

(III) Obtain solution to original instances by combining

these solutions

43) What is the another name for Quicksort?

Partition Exchange Sort

44) What are the advantages and disadvantages?

Advantage: Fastest among all sorting algorithms Suitable when the input
size is very large

Disadvantage:

Heavily based on recursive sorting technique

It takes O (n* log n) time and O (log n) additional space due to

Recursion

45)Is Quicksort Stable as well as In place?

Not Stable but In place.

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?

When any one of the subarray is empty

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?

DEPARTMENT OF M.C.A Page 6


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

When all the elements towards the left of pivot are <= pivot and all the
elements towards the right of pivot are >= pivot.

50) What is CLK_TCK?

macro defines the number of clock ticks per second which is available in the
TIME.H header file.

51) What technique does kruskal’s algorithm follow.

greedy technique

52) What is the time complexity.

With an efficient sorting algorithm, the time efficiency of an kruskal’s algorithm


will be in O(|E|log|E|).

53) Who is the inventor of kruskal’s algorithm.

Joseph Kruskal.

54) Which technique is used to solve BFS & DFS problems?

Decrease and Conquer

55) What is BFS traversal?

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.

If there still remains unvisited vertices, the algorithm to be restarted at an


arbitrary vertex of another connected component of a graph.

56) What is DFS traversal?

Consider an arbitrary vertex v and mark it as visited on each iteration, proceed


to an unvisited vertex w adjacent to v. we can explore this new vertex
depending upon its adjacent information. This process continues until dead end
is encountered.(no adjacent unvisited vertex is available). At the dead end the
algorithm backs up by one edge and continues the process of visiting unvisited
vertices. This process continues until we reach the starting vertex.

57) What are Tree edge, Back edge & Cross edge ?

DEPARTMENT OF M.C.A Page 7


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

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

Checking connectivity and checking acyclicity of a graph.

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.

For checking cycle presence, we can take advantage of the graph's


representation in the form of a BFS forest, if the latter vertex does not have cross
edge, then the graph is acyclic.

Application of DFS

To check whether given graph is connected or not.

To check whether the graph is cyclic or not.

To find the spanning tree.

Topological sorting.

59) Which data structures are used in BFS & DFS tree traversal
technique?

We use Stack data structure to traverse the graph in DFS traversal.

We use queue data structure to traverse the graph in DFS traversal.

60) What are the efficiencies of BFS & DFS algorithms for Adjacency
matrix and adjacency list representation?

Adjacency matrices: Θ(V2)

DEPARTMENT OF M.C.A Page 8


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

Adjacency linked lists: Θ(V+E)

61) Define set?


Set is unordered collection of distinct items.

62) Define power set?

The set of all subsets of a set is a power set.

63) Define squashed order?

Any subsets involving aj can be listed only after all the subsets involving
a1,…,aj-1(j=1,2,…,n-1)

64) What are the ways of generating subsets?

Decrease by constant

Bit string based algorithm

Minimal change algorithm

65) Explain time and space trade off strategy.

It is a strategy in which time efficiency can be achieved at the cost of


extra memory usage.

66) Which technique does the Horspool algorithm uses?

Input enhancement technique

67) Explain Input enhancement technique.

It is a technique in which the problem’s input is preprocessed in whole or in


part and the additional information stored is obtained to solve the problem.

68) What is a shift table?

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.

69) Which is better Brute Force or Horspool algorithm for string


matching?

Horspool is better as it reduces the number of comparisons.

DEPARTMENT OF M.C.A Page 9


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

70) Differentiate between Brute-Force technique and Horspool


algorithm for string matching.

a) In brute-force, comparison starts from left where as in Horspool comparison


starts from right.

b) In brute-force technique, if there is a character mismatch then we shift the


pattern to the right by 1 position.

In Horspool, if there is a mismatch then the shift size is obtained from the
shift table and the pattern is shifted accordingly.

71) Differentiate between Horspool and Boyer -Moore algorithms.

Horspool algorithm uses only Shift table to obtain the shift


information.

Boyer - Moore algorithm uses 2 tables.

-Bad symbol shift table (same as the shift table used by Horspool).The shift
information of this table is known as d1

-Good suffix shift table

The shift information from this table is known as d2.

Shifting is done by taking max(d1,d2).

72) What is Dynamic Programming?

It is a technique for solving problems with overlapping sub problems.

73) What does Dynamic Programming have in common with Divide-


and-Conquer?

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)

75) What is a principle difference between the two techniques?

DEPARTMENT OF M.C.A Page 10


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

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.

Very precisely re - computations are not preformed.

76) What is a spanning tree ?

A spanning tree of a weighted connected graph is its connected acyclic(no


cycles) subgraph (i.e. a tree)that contains all the vertices of a graph.

77) What is a minimum spanning tree ?

Minimum spanning tree of a connected graph is its spanning tree of smallest


weight.

78) Prim’s algorithm is based on which technique.

Greedy technique.

79) State greedy technique for solving problem.

A greedy approach constructs a problem through a sequence of steps each


expanding a partially constructed solution obtained so far, untill the complete
solution is reached.

On each step the choice must be made as

Feasible: i.e. it has to satisfy the problem’s constraints.

Locally optimal: i.e. it has to be the best local choice among all feasible choices
available on that step.

Irrevocable: i.e. once made, it cannot be changed on subsequent steps of the


algorithm.

What are fringes and unseen vertices?

Fringes: vertices which are connected are called fringes.

Unseen vertices : vertices which are not adjacent are called unseen.

80) Name some of the application greedy technique

DEPARTMENT OF M.C.A Page 11


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

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.

Communication Networks: Suppose there are 5 different cities and we want to


establish computer connectivity among them, then we take into the account of
cost factor for communication links.

Building a road network that joins n cities with minimum cost.

81) Does Prim’s Algorithm always yield a minimum spanning tree ?

Yes

82) What is the purose of Floyd’s algoreithm?

- To find the all pair shortest path.

83) What is the time efficiency of floyd’s algorithm?

- It is same as warshall’s algorithm that is θ(n3).

84) What is distance matrix?

- In which the element dij indicates the length of the path from ith vertex to the
jth vertex.

85) What is shortest path?

- It is the path which is having shortest length among all possible paths.

86) warshall’s algorithm is optimization problem or non-optimization


problem ?

Non-optimization problem

87) For what purpose we use Warshall’s algorithm?

Warshall’s algorithm for computing the transitive closure of a directed graph

88) Warshall’s algorithm depends on which property?

Transitive property

DEPARTMENT OF M.C.A Page 12


16MCA38 – Analysis and Algorithms of Laboratory Lab Viva Questions

89) what is the time complexity of Warshall’s algorithm?

Time complexity of warshall’s (n3)

90) what is hard problem?

Optimization problems which are having complexity of exponential or factorial.

91) hard problems can be solved by which method?

Back tracking and branch and bound techniques used for large instance of
combinatorial problems.

92) what is state space tree?

Constructing a tree of choices being made and processing is known as state-space-


tree. Root represents an initial state before the search for solution begins.

93) what are promising and non-promising state-space-tree?

Node which may leads to solution is called promising.

Node which doesn’t leads to solution is called non-promising.

94) Differentiate between backtracking and Branch and Bound.

Branch and Bound uses Best first search technique and is applicable to
optimization problems.

Backtracking is applicable to non-optimization problems most of the times and


sometimes optimization problems. It uses DFS search technique.

95) In Backtracking what does the leaf node indicates?

It indicates either a non promising dead ends or solutions to the problem.

DEPARTMENT OF M.C.A Page 13

You might also like