0% found this document useful (0 votes)
804 views

ADA Solved Model Paper 2024

Uploaded by

Sherin Dorothy
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)
804 views

ADA Solved Model Paper 2024

Uploaded by

Sherin Dorothy
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/ 43

2 MARKS QUESTIONS

1. Define Algorithm. List the methods for specifying the algorithm.

An algorithm is a sequence of instructions that a computer must perform to solve a


well-defined problem. It is a step by step procedure for performing some task in a finite
amount of time.

Methods of specifying algorithm: natural language, flow charts, pseudocode, and


programming languages

2. What is best case efficiency?

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.

3. What is Huffman codes?


Huffman codes are variable length prefix codes derived from a Huffman Tree and are used
for lossless data compression. Data can be encoded efficiently using Huffman Codes.

4. What are divide and conquer techniques?


A divide-and-conquer algorithm recursively breaks down a problem into two or more sub-
problems of the same or related type, until these become simple enough to be solved
directly. The solutions to the sub-problems are then combined to give a solution to the
original problem.

5. Define time complexity and space complexity.


Time complexity measures the execution time of the algorithm related to input size. It
gives the amount of time an algorithm takes for execution.
Space complexity measures the memory usage of the algorithm relative to input size. It
gives the amount of memory an algorithm requires for execution

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.

8. Write the differences between recursive and non-recursive algorithm.


A recursive sorting algorithm calls on itself to sort a smaller part of the array, then
combining the partially sorted results. Quick-sort is an example.
A non-recursive algorithm does the sorting all at once, without calling itself. Bubble-sort
is an example of a non-recursive algorithm.

9. Define minimum cost spanning tree.


A minimum spanning tree (MST) is a subset of the edges of a connected, edge-weighted
graph that connects all the vertices together without any cycles and with the minimum
possible total edge weight.

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.

Three types of traversal are:


 Pre-order
 In-order
 Post-order

11. What is hashing? Define hash table.

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.

13. What is recursive algorithm?

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.

14.What is Decision tree?

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)

15. Define Hamilton circuit problem.

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.

16. Define Binary Tree and Complete Binary tree.

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.

Brute force is a straightforward approach to solving a problem, usually directly based on


the problem statement and definitions of the concepts involved. It involves trying all
possible solutions to a problem until the correct one is found.

18.What is P and NP problems?

Class P is a class of decision problems that can be solved by deterministic algorithms in


polynomial time. This class of problems is called polynomial class problems or P- class
problems or P problems

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.

19.What is Knapsack problem ?

The Knapsack Problem is a classic optimization problem in computer science and


mathematics. It involves selecting a subset of items from a given set of items, subject to a
weight constraint, such that the total value of the selected items is maximized. The
problem is called the Knapsack Problem because it can be thought of as packing a
knapsack with items of different weights and values, where the goal is to maximize the
total value of the items that can be carried in the knapsack without exceeding its weight
capacity.

20.List the different types of control structures.

The different types of control structures in programming are:

1. Sequential: Executes statements in a linear sequence.

2. Selection (Conditional): Makes decisions based on conditions.

- if statements

- if-else statements

- switch or case statements

3. Iteration (Looping): Repeats a block of code.

- for loops - while loops - do-while loops

4. Branching (Jump): Alters the flow of control.

- break - goto - continue -return - exit

21. Compare DFS and BFS

Depth-First Search is a graph traversal technique used in computer science and


mathematics to explore all the vertices of a graph or tree data structure.
Breadth-First Search is a fundamental graph traversal algorithm used in computer science
and mathematics to explore all the nodes of a graph or tree data structure.

22. Illustrate asymptotic notations.

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

Types of asymptotic notations:

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.

6. Explain Strassen’s matrix multiplication method.

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).

To improve the efficiency of matrix multiplication problem, Strassen suggested that


for matrix multiplication it is sufficient to have 7 multiplication and 18 additions or
subtractions.
7. Explain DFS traversal algorithm.
8. Explain topological sorting. Find topological sort of a given graph using removal
method.

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.

Topological sort for the given graph is as follows


9. Analyze time efficiency for finding a factorial number.

The Basic Steps Involved are:

1. Input parameter size: n

2. Basic operation required: n * Fact (n - 1)

3. Reason if the operation be called more number of items:

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.

4. Recurrence relation and initial condition:

T(n)=T(n-1)+1, T(0) = 0 for n > 0

5. Solution for the recurrence relation:

T(n) = T (n-1) +1

= T (n-2)+1+1

= T (n-3)+1+1+1

= T (0) + 1 + 1 + .... n times

Therefore, the number of multiplications required = n

The time complexity in finding the factorial of a number = O(n)


10. What are the differences between mathematical and empirical analysis of
algorithms?
11. Solve sum of subsets using backtracking for S={3,4,5,6},M=13 by constructing a
solution tree.

12. Explain knapsack problem .


13. Explain Prims algorithm

The General Steps of Prim's Algorithm

1. Initialize an empty MST and a set of visited vertices.

2. Choose an arbitrary vertex as the starting point and mark it as visited.

3. Repeat the following steps until all vertices are visited:

a. Find the minimum-weight edge that connects a visited vertex to an unvisited


vertex.

b. Add this edge to the MST and mark the unvisited vertex as visited.

4. Output the MST.

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

Big-Oh Notation (O-notation)


 Big-Oh notation represents the upper bound of the running time of an algorithm.
Thus, it gives the worst-case complexity of an algorithm. Big-Oh gives the upper bound
of a function
 O(g(n)) = { f(n): there exist positive constants c and n0 such that 0 ≤ f(n) ≤ cg(n) for
all n ≥ n0 }
 The above expression can be described as a function f(n) belongs to the set O(g(n))
if there exists a positive constant c such that it lies between 0 and cg(n), for sufficiently
large n.
 For any value of n, the running time of an algorithm does not cross the time
provided by O(g(n)).
 Since it gives the worst-case running time of an algorithm, it is widely
used to analyze an algorithm as we are always interested in the worst-case

scenario.

Omega Notation (Ω-notation)


Omega notation represents the lower bound of the running time of an algorithm.
Thus, it provides the best case complexity of an algorithm. Omega gives the lower
bound of a function.
Ω(g(n)) = { f(n): there exist positive constants c and n0
such that 0 ≤ cg(n) ≤ f(n) for all n ≥ n0 }
The above expression can be described as a function f(n) belongs to the set Ω(g(n)) if
there exists a positive constant c such that it lies above cg(n), for sufficiently large n. For
any value of n, the minimum time required by the algorithm is given by Omega Ω(g(n)).

Theta Notation (Θ-notation)


Theta notation encloses the function from above and below. Since it represents the upper
and the lower bound of the running time of an algorithm, it is used for analyzing the
average-case complexity of an algorithm. Theta bounds the function within constants
factors.
For a function g(n), Θ(g(n)) is given by the relation:
Θ(g(n)) = { f(n): there exist positive constants c1, c2 and n0
such that 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) for all n ≥ n0 }
The above expression can be described as a function f(n) belongs to the set Θ(g(n)) if
there exist positive constants c1 and c2 such that it can be sandwiched between c1g(n)
and c2g(n), for sufficiently large n.
If a function f(n) lies anywhere in between c1g(n) and c2g(n) for all n ≥ n0, then f(n)
is said to be asymptotically tight bound.

15. Trace the quick sort algorithm for the following numbers

45,36,15,92,35,71,64,39,37.

Soln: Tracing of quick sort for the given number is as follows


16. Explain Dijikstra’s algorithm.

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.

Dynamic programming is a computer programming technique where an algorithmic


problem is first broken down into sub-problems, the results are saved, and then the
sub-problems are optimized to find the overall solution — which usually has to do
with finding the maximum and minimum range of the algorithmic query.
22. What are the different strategies to solve Knapsack problem? Mention its
constraints.

The knapsack problem is the following problem in combinatorial optimization. Given


a set of items, each with a weight and a value, determine which items to include in the
collection so that the total weight is less than or equal to a given limit and the total value is
as large as possible.

Different strategies to solve the Knapsack problem

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.

Possible greedy strategies to the 0/1 Knapsack problem:


1. Choose the item that has the maximum value from the remaining items; this
increases the value of the knapsack as quickly as possible.
2. Choose the lightest item from the remaining items which uses up capacity as slowly
as possible allowing more items to be stuffed in the knapsack.
3. Choose the items with as high a value per weight as possible
Branch and Bound
Branch and bound is a technique used only to solve optimization problems. Branch
and bound is based on the construction of a ‘state space tree’. A state space tree is a
rooted tree where each level represents a choice in the solution space that depends on
the level above and any possible solution is represented by some path starting out at
the root and ending at a leaf.
In the context of the Knapsack problem, if there are N possible items to choose from,
then the k th level represents the 7 state where it has been decided which of the first k
items have or have not been included in the knapsack. In this case, there are 2 k nodes
on the k th level and the state space tree’s leaves are all on level N

Constraints of knapsack problem

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.

23.Explain 4-queen's problem.


24. Write the advantages and disadvantages of divide and conquer technique.

Advantages of divide and conquer technique

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.

Disadvantages of Divide and Conquer Technique

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.

You might also like