ADA Solved
ADA Solved
ADA Solved
Important Questions
Section A
1. List and define the two kinds of algorithm efficiency.
→ Time efficiency : A measure of amount of time for an algorithm to execute.
→ Space efficiency : A measure of amount of memory needed for an algorithm to
execute.
BFS DFS
BFS stands for “ breadth first search” DFS stands for “Depth first search”
Traverses the tree level wise. Traverses the tree depth wise.
Implemented using Queue which is Implemented using Stack which is LIFO
FIFO list. list.
BFS requires more memory compare to DFS requires less memory compare to
DFS BFS
Section B
15. With an example, explain Step counts w.r.t to computing the time efficiency of
algorithm.
→In step count , we attempts to find the time spent in all the parts of program and
finally sum up the steps value which is the final value of efficiency of the algorithm.
Example: x=a+b; →1 step*1=1
for(i=1;i<=n;i++)
X=a+b; - →1step*n=n
19. Explain the basic steps to be followed in analysing the efficiency of recursive
algorithm.
→ Basic steps to be followed in analysing the efficiency of recursive algorithm:
1.Selection of a parameter Indicating Input Size : the initial step involves the
determination of a parameter that indicates the size of the input. The initial parameter
serves as a measure of the algorithms efficiency. For example, in sorting algorithms,
the parameter could be the size of the list(n) that is to be sorted.
2. Identification of the Algorithm's Basic Operation : The basic operation of an
algorithm is typically the operation that is most frequently executed. More often this
operation is located in the innermost loop of the algorithm. For example, in the
context of a sorting algorithm, the basic operation might be the comparison of two
elements.
3. Reason for Basic Operation to be Executed more than Once : Find out the
reasons why the basic operations to be executed more than once.
4. Setting up a recurrence relation, with an appropriate initial condition, for
expressing the number of times the basic operation is executed.
5. Solving the recurrence relation for finding the complex function and order of
growth.
23. Write a Program to find value of a^n using brute force and divide and conquer method.
→ def bpower(a, n):
pow = 1
for i in range(n):
pow = pow * a
return pow
# Main block
a=int(input("Enter a :"))
n=int(input("Enter n :"))
print("Brute Force method a^n : ",bpower(a,n))
print("Divide and Conquer a^n : ",dpower(a,n)
24. Sort the list [ 21, 21, 23, 21, 22, 23, 22, 23 ] using distribution counting.
Section C
2.Mid-Square Method : In this method, we square the key first. Then we take digits
from the middle of this number as the generating address.
The hash function is : H(K)=m.
3.Folding Method : This is the easiest way of computing the key where the key is
broken into pieces and then adding all of them to get the hash address.
The hash function is : H(K) = K1 + K2 +……+Kn.
4.Mixed Method : It is the combination of division method and folding method.
30. Apply Horspool’s algorithm to search for the pattern GREAT in the text
SAURAVISREALLYGREAT