ADA Solved Model Paper 2024
ADA Solved Model Paper 2024
Best case efficiency of the algorithm is its efficiency for the best case inputs of size n for
which algorithm runs the fastest among all possible inputs of that size. Best case is the
function which performs the minimum number of steps on input data of n elements.
6. List two graph traversal algorithm and write one difference between them
Two graph traversal algorithms are: Breadth-First Search (BFS) and Depth-First Search
(DFS).
DFS recursively explores edges until reaching the end of a branch before backtracking,
while BFS explores all neighbours at each level before moving to the next.
7. What is optimality?
Optimality is the property that the algorithm finds the best trajectory, provided one exists.
The principle of optimality is a fundamental aspect of dynamic programming, which states
that the optimal solution to a dynamic optimization problem can be found by combining
the optimal solutions to its sub-problems.
10. Define binary tree. List three types of binary tree traversal.
A binary tree is a tree data structure in which each node has at most two children, referred
to as the left child and the right child.
Hashing is the process of transforming any given key or a string of characters into another
value. Hashing is a fundamental data structure that efficiently stores and retrieves data in a
way that allows for quick access. Data is converted into these fixed-length strings, or hash
values, by using a special algorithm called a hash function.
A hash table is a data structure that implements an associative array, also called a
dictionary or simply map, which is an abstract data type that maps keys to values.
12. Define Backtracking and Branch-Bond Technique.
Backtracking is an algorithmic technique whose goal is to use brute force to find all
solutions to a problem. It involves systematically exploring all possible solutions by
incrementally building candidates and abandoning them as soon as it is determined that
they cannot lead to a valid solution.
The branch and bound method is a problem solving technique that is used to solve
optimization problems. The technique involves dividing the search space of a problem into
smaller sub-problems and using bounds to eliminate the sub problems that cannot contain
the optimal solution.
A recursive algorithm is a type of algorithm that calls itself one or more times in order to
solve the problem. It involves breaking down the problem into smaller sub problems and
solving each sub problem recursively until the original problem is solved.
A decision tree is a flowchart-like structure in which each internal node represents a "test"
on an attribute (e.g. whether a coin flip comes up heads or tails), each branch represents
the outcome of the test, and each leaf node represents a class label (decision taken after
computing all attributes)
Hamilton circuit problem is a problem of determining whether a given graph contains the
Hamiltonian circuit where Hamiltonian circuit is a path in a graph that visits every vertex
exactly once and returns to the starting vertex. In other words, it is a closed path that
passes through every vertex of the graph exactly once. i.e., it forms a cycle. If such a cycle
exists, the graph is said to be a Hamiltonian graph.
A complete binary tree is a type of binary tree in which all levels are fully filled except
possibly for the last level. If the last level is not completely filled, all nodes are as far left
as possible. This ensures that the tree remains balanced and efficient for operations such as
insertions and deletions.
17. Define Brute force method.
Class NP is the class of decision problems that can be solved in polynomial time by
nondeterministic polynomial algorithms. This class of problems is called nondeterministic
P type problems or NP problems.
- if statements
- if-else statements
Asymptotic Notations are mathematical tools that helps us analyse the performance of
algorithms they allow us to describe how the running time or space requirements of an
algorithm change as its input size increase towards infinity
1.big O notation
2 Omega notation
3.Theta notation
BIG QUESTIONS:
1. Write the algorithm for Merge Sort and trace the merge sort for
39,27,43,3,9,2,10,23
2.Explain worst case, best case and average case efficiencies.
2. Explain pre-order tree traversal.
In a pre-order traversal, the traversal process follows the sequence Node- Left-Right,
starting from the root. This means that the current node is visited first, then the left subtree
is traversed, and finally, the right subtree is traversed.
\
4. Write a program to solve Towers of Hanoi problem.
5. Explain Hashing function.
The conventional method of matrix multiplication involves three nested loops . and
each for loop executes 'n' times and therefore running time for the above
conventional method is O(n3).
Topological sorting is a way to order the vertices in a DAG such that if there is an edge
from vertex A to verter B. then A comes before B in the ordering. This is useful for
determining the order in which tasks should be performed in a project or the order in
which events occurred in a timeline.
As 'n' is non-negative integer and it starts reducing by 1 for each recursion, the algorithm
should stop when n becomes '0. So the operations need to be performed until n becomes 0.
T(n) = T (n-1) +1
= T (n-2)+1+1
= T (n-3)+1+1+1
b. Add this edge to the MST and mark the unvisited vertex as visited.
The nature of prim's algorithm makes it necessary to provide each vertex not in the current
tree with the information about the shortest edge connecting the vertex to a tree vertex.
Vertices that are adjacent to any of the tree vertices can be given the ∞ label indicating
their "infinite" distance to the tree vertices.
14. Explain Asymptotic Notations use to describe the running time of the algorithm.
Asymptotic notations are the mathematical notations used to describe the running time of
an algorithm when the input tends towards a particular value or a limiting value.
There are mainly three asymptotic notations:
Big Oh notation
Omega notation
Theta notation
scenario.
15. Trace the quick sort algorithm for the following numbers
45,36,15,92,35,71,64,39,37.
Dijkstra's algorithm is a greedy algorithm that efficiently finds the shortest path from a
single source vertex to all other vertices in a weighted, directed or undirected graph with
non-negative edge weights. It works by selecting the destination vertex based on a greedy
criterion and iteratively generating the shortest path to a new destination or traget vertex,
In simple terms, Dijkstra's algorithm generates the shortest paths in increasing order of
their length. At each stage, it selects the vertex with the shortest tentative distance as the
next destination vertex. By doing so, it gradually builds a spanning tree of the graph,
where the edges on the shortest path from the source vertex to all other vertices form the
tree.
14. Solve 4 – Queens problem by back tracking technique. Draw solution state space
tree.
18. Find the optimal solution for a Knapsack problem using Branch and bound
method with M=40, N=4.
{w1,w2,w3,w4}={20,25,10,15}
{p1,p2,p3,p4}={20,40,35,45}.
19. Find the minimum weight spanning tree using prim’s algorithm.
20. Write Kruskal's algorithm to obtain minimum cost spanning tree with example
21.What is dynamic programming ? Mention the difference between divide and
conquer and dynamic programming.
Brute Force
Brute force is a straightforward approach to solving a problem, usually directly based
on the problem’s statement and definitions of the concepts involved. If there are n
items to choose from, then there will be 2 n possible combinations of items for the
knapsack. An item is either chosen or not chosen. A bit string of 0’s and 1’s is
generated which is of length n. If the i th symbol of a bit string is 0, then the i th item
is not chosen and if it is 1, the i th item is chosen.
Dynamic Programming
Dynamic Programming is a technique for solving problems whose solutions satisfy
recurrence relations with overlapping subproblems. To design a dynamic
programming algorithm for the 0/1 Knapsack problem, we first need to derive a
recurrence relation that expresses a solution to an instance of the knapsack problem in
terms of solutions to its smaller instances.
Memory Functions
Unlike dynamic programming, memory functions solve in a top-down manner only
subproblems that are necessary. In addition, it maintains a table of the kind that would
5 have been used by a bottom-up dynamic programming algorithm.
Greedy Algorithm
Greedy algorithms are a class of algorithms that make locally optimal choices at
each step with the hope of finding a global optimum solution. The key idea is to
select the best possible choice at each step, leading to a solution that may not always
be the most optimal but is often good enough for many problems.
In the knapsack problem, we need to pack a set of items, with given values and sizes (such as
weights or volumes), into a container with a maximum capacity . If the total size of the items
exceeds the capacity, you can't pack them all.
Efficiency: The divide and conquer technique can be very efficient for solving problems
that can be broken down into smaller subproblems. This is because the technique can solve
each subproblem independently, which can speed up the overall solution time
Flexibility: The divide and conquer technique can be used to solve a wide variety of
problems This is because the technique can be applied to any problem that can be broken
down into smaller subproblems.
Simplicity: The divide and conquer technique is relatively simple to understand and
implement This makes it a good choice for problems that need to be solved quickly or by
people with limited programming experience.
Parallel Computing: Divide and Conquer involves breaking down a problem into
independent sub problems, and hence it's possible to execute the sub-problems in parallel
by taking advantage of multi- core processors and distributed computing systems.
Complexity: The divide and conquer technique can be more complex than other
techniques for solving problems. This is because the technique requires the problem to be
broken down into smaller sub problems which can be time-consuming and error-prone.
Memory Usage: The divide and conquer technique can require more memory than other
techniques for solving problems. This is because the technique requires the sub-problems
to be stored in memory which can be a problem for problems with large data sets.
Inefficient for Small Problems: The divide and conquer technique can be inefficient for
small problems. This is because the time it takes to divide the problem into sub-problems
and then recombine the solutions can be more than the time it would take to solve the
problem directly.
Overhead of Recursion: Divide and Conquer algorithms are usually implemented with
recursion, which leads to a certain overhead due to the recursive function calls and
merging of sub-solutions.
25. Explain Dijkstra algorithm with example
Dijkstra’s algorithm is a popular algorithms for solving many single-source shortest path
problems having non-negative edge weight in the graphs i.e., it is to find the shortest
distance between two vertices on a graph. It was conceived by Dutch computer
scientist Edsger W. Dijkstra in 1956. The algorithm maintains a set of visited vertices and
a set of unvisited vertices. It starts at the source vertex and iteratively selects the
unvisited vertex with the smallest tentative distance from the source. It then visits the
neighbors of this vertex and updates their tentative distances if a shorter path is found.
This process continues until the destination vertex is reached, or all reachable vertices
have been visited.