0% found this document useful (0 votes)
64 views6 pages

Mailam Engineering College: Mailam (Po), Villupuram (DT) - Pin: 604 304 Department of Computer Applications

The document is a set of viva questions for the binary search algorithm from the Algorithms Lab of Mailam Engineering College. It contains 9 questions that test understanding of binary search, including what it is, its time complexity, how it works to search a sorted list by dividing it in half at each step, and comparing the search key to the middle element. It also asks about average case analysis and compares binary search to other search algorithms like sequential search.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views6 pages

Mailam Engineering College: Mailam (Po), Villupuram (DT) - Pin: 604 304 Department of Computer Applications

The document is a set of viva questions for the binary search algorithm from the Algorithms Lab of Mailam Engineering College. It contains 9 questions that test understanding of binary search, including what it is, its time complexity, how it works to search a sorted list by dividing it in half at each step, and comparing the search key to the middle element. It also asks about average case analysis and compares binary search to other search algorithms like sequential search.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

ALGORITHMS LAB

Mailam Engineering College


(Approved by AICTE, New Delhi, Affiliated to Anna University, Chennai
& Accredited by National Board of Accreditation (NBA), New Delhi)

Mailam (Po), Villupuram (Dt). Pin: 604 304


DEPARTMENT OF COMPUTER APPLICATIONS
ALGORITHMS LAB MC9223
VIVA QUESTIONS FOR BINARY SEARCH ALGORITHM
1. What is binary search?
The Binary search algorithm is one of the most efficient sorting techniques, which
requires the list to be sorted in sorted in ascending order. To search for an element in the
list, the binary search algorithm splits the list into two and locates the middle element in the
lists the search element is less than the middle element, the first part of the list is searched
else the second part of the list is searched. This process continues until the search element
is equal to the middle element or the list consists of only one element that is not equal to
the search element.
2. A binary tree with 20 nodes has--------------------------------------------------null
branches.
21
Explanation:
Let us take a tree with 5 nodes (n=5)

It will have only 6 (ie,5+1) null branches. In general, a binary tree with n nodes has
exactly n+1 null nodes.
3. How many different trees are possible with 10 nodes?
1014
Explanation:
For example, consider a tree with 3 nodes (n=3), it will have the maximum
combination of 5 different (ie, 2 3 3 = 5) trees.

In general: If there are n nodes, there exist 2 n n different trees.

Prepared by
Mrs. A.Subathra Devi

ALGORITHMS LAB
4. There are 8, 15, 13, 14 nodes were there in 4 different trees. Which of them
could have formed a full binary tree?
15
In general: There are 2 n 1 nodes in a full binary tree.
Full binary trees contain odd number of nodes. So there cannot be full binary trees
with 8 or 14 nodes, so rejected. With 13 nodes you can form a complete binary tree but not
a full binary tree. So the correct answer is 15.
5. In the given binary tree, using array, at which location can you store the node
4?

Answer: At location 6
Explanation:

Where LCn means Left Child of node n and RCn means Right Child of node n
6. What is Dynamic Programming?
Dynamic Programming is an algorithm design method that can be used when the
solution to a problem can be viewed as the result of a sequence of decisions. An example
for algorithm using dynamic programming is multistage graphs.
7. What are the time complexities for the following algorithms?
Binary search : O(logn)
8. For the following array, find the average number of key comparison made by
binary search in a successful search in the array. (Assume that each key is
searched for with the same probability)
[ 4, 20, 25, 30, 40, 42, 60, 70, 80, 90, 95, 98, 100 ].
Time complexity for binary search = O(log n)
Here n = 13
Average no. of key comparisions = O(log 213)
= log10 13 / log10 2
= 1.114 / 0.301
= 3.7
9. Which is the fastest searching technique?
If the list is in sorted order, Binary search is the fastest searching technique, but if the
list is not in sorted order, Sequential search is the fastest searching technique.

STAFF HANDLING

HOD

PRINCIPAL

Prepared by
Mrs. A.Subathra Devi

ALGORITHMS LAB

Mailam Engineering College


(Approved by AICTE, New Delhi, Affiliated to Anna University, Chennai
& Accredited by National Board of Accreditation (NBA), New Delhi)

Mailam (Po), Villupuram (Dt). Pin: 604 304


DEPARTMENT OF COMPUTER APPLICATIONS
ALGORITHMS LAB MC9223
VIVA QUESTIONS FOR WARSHALLS ALGORITHM
1. What is Warshalls algorithm?
Warshalls algorithm is used to find the transitive closure of a given directed graph.
The transitive closure of a directed graph with n vertices can be defined as the n by n
matrix. In which the element in the ith row and jth column is 1 if there exists a nontrivial
directed path from the ith vertex to the jth vertex. Otherwise 0.
2. Draw the structure of Warshalls algorithm.

3. What is an adjacency matrix?


The adjacency matrix A= { aij } of a directed graph is the Boolean matrix that has 1
I its ith row and jth column if and only if there is a directed edge from the ith vertex to the
jth vertex.
4. What is transitive closure? State the algorithm used to find transitive closure?
The transitive closure of a directed graph with n vertices can be defined as the n by n
Boolean matrix T={ tij}, in which the element in the ith row (1<=i<=n) and the jth column
(1<=j<=n) is 1 if there exists a non-trivial directed path from the ith vertex to the jth
vertex, otherwise tij is 0.
5. Write the procedure to find the transitive closure of a directed graph using
warshalls algorithm. [JUN 11]
algorithm.
Warshall(A[1..n,1..n])
R(0)=A
For k=1 to n do
For I=1 to n do
For j=1 to n do
R(k)[I,j] = R(k-1)[I,j] or R(k-1)[I,k] and R(k-1)[k,j]
Return R(n)

6. What is the difference between dynamic programming and divide and conquer?

Prepared by
Mrs. A.Subathra Devi

ALGORITHMS LAB

Dynamic Programming

Divide And Conquer

1. Divide the given problem into many subproblems.


Find the individual solutions and
Combine them to get the solution for the
main problem.

1. Many decisions and sequences are


guaranteed and all the overlapping subinstances are considered.

2. Follows top down technique.

2. Follows bottom up technique.

3. Split the input only at specific points.

3. Split the input at every possible point


rather than at a particular point.

4. Each problem is independent.

4. Sub-problems are dependent on the main


problem.

7. Time Complexity of Warshalls algorithm:

STAFF HANDLING

HOD

PRINCIPAL

Mailam Engineering College


Prepared by
Mrs. A.Subathra Devi

ALGORITHMS LAB
(Approved by AICTE, New Delhi, Affiliated to Anna University, Chennai
& Accredited by National Board of Accreditation (NBA), New Delhi)

Mailam (Po), Villupuram (Dt). Pin: 604 304


DEPARTMENT OF COMPUTER APPLICATIONS
ALGORITHMS LAB MC9223
VIVA QUESTIONS FOR STRASSENS ALGORITHM
1. What is Divide and conquer technique.
[DEC 10 & 12]
The algorithm works by a function to compute on n inputs the divide-and-conquer
strategy suggests splitting the inputs in to k distinct subsets, 1 kn, yielding k subproblems. The sub-problems must be solved, and then a method must be found to combine
sub-solutions into a solution of the whole. If the sub-problems are still relatively large, then
the divide-and conquer strategy can possibly be reapplied.
2. How does divide and conquer algorithm work?
Three Steps of the Divide and Conquer Approach

[JUN 12]

Divide the problem into two or more smaller sub-problems.


Conquer the sub-problems by solving them recursively.
Combine the solutions to the sub-problems into the solutions for the original
problem.

3. List out the applications of divide and conquer techniques?


The applications of divide and conquer techniques are as follows,

Merge sort
Quick sort
Tree traversals
Binary search
Matrix multiplication-Strassens algorithm

4. Write the algorithm of divide and conquer techniques?


Calculating a0 + a1 + + an-1
ALGORITHM RecursiveSum(A[0..n-1])
//Input: An array A[0..n-1] of orderable elements
//Output: the summation of the array elements
if n > 1
return ( RecursiveSum(A[0.. n/2 1]) + RecursiveSum(A[n/2 .. n 1]) )
5. Define Strassens Matrix Multiplication.
The Strassens Matrix Multiplication algorithm discovered by Volker Strassen, and
usually called Strassens Algorithm, which allows us to multiply two n-by-n matrices with a
number of multiplications that is a small multiple of n(ln 7)/(ln 2), when n is of the form 2k. This
means we will be able to multiply matrices using about n 2.8 multiplications instead of n3.
6. Write the formula for calculating Strassens Matrix Multiplication?

Prepared by
Mrs. A.Subathra Devi

ALGORITHMS LAB
c00

c01

c10

c11

m1
m2
m3
m4
m5
m6
m7

=
=
=
=
=
=
=

a00

a01

a10

a11

b00

b01

b10

b11

m1+m4-m5+m7

m3+m5

m2+m4

m1+m3-m2+m6

(a00 + a11) * (b00 + b11)


(a10 + a11) * b00
a00 * (b01 - b11)
a11 * (b10 - b00)
(a00 + a01) * b11
(a10 - a00) * (b00 + b01)
(a01 - a11) * (b10 + b11)

It has 7 multiplications and 18 additions


7. Draw the structure of divide-and-conquer technique.
The divide-and-conquer technique is shown in the figure, which depicts the case of
dividing a problem into two smaller sub-problems.

STAFF HANDLING

HOD

PRINCIPAL

Prepared by
Mrs. A.Subathra Devi

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy