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

INTERNAL_1-DAA-KEY

This document outlines the internal exam for the Design and Analysis of Algorithms course at SRI Rajaa Rajan College of Engineering & Technology, scheduled for September 2024. It includes various questions covering fundamental concepts such as algorithms, time and space complexity, algorithm techniques, and asymptotic notation, along with specific problem types like sorting and searching. The exam consists of two parts: Part A with short answer questions and Part B requiring detailed explanations on selected topics.

Uploaded by

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

INTERNAL_1-DAA-KEY

This document outlines the internal exam for the Design and Analysis of Algorithms course at SRI Rajaa Rajan College of Engineering & Technology, scheduled for September 2024. It includes various questions covering fundamental concepts such as algorithms, time and space complexity, algorithm techniques, and asymptotic notation, along with specific problem types like sorting and searching. The exam consists of two parts: Part A with short answer questions and Part B requiring detailed explanations on selected topics.

Uploaded by

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

SRI RAAJA RAAJAN COLLEGE OF ENGINEERING & TECHNOLOGY

Amaravathipudur Post, Karaikudi Tk

INTERNAL EXAM I – Sep 2024

Reg.
Yr/Sem/Dept: II/III/AI&DS Date: 27.9.24
No:

AD3351 DESIGN AND ANALYSIS OF ALGORITHM 50 Marks

Answer ALL Questions


PART A – (7*2 = 14 Marks)

1. What is Algorithm? (AU.,NOV/DEC2023,APR/MAY2023)

A finite set of instruction that specifies a sequence of operation is to be carried out in order to solve a

specific problem or class of problems is called an Algorithm.

2. Distinguish sequential and parallel algorithm. ( AU ., Nov/Dec 2023)

3. Write the Pseudocode for Euclid’s algorithm ( AU .,NOV/DEC 2023)

def gcd(a, b):

while b != 0:

temp = b

b=a%b

a = temp

return a

# Example usage:

num1 = 48

num2 = 18

print("The GCD of", num1, "and", num2, "is", gcd(num1, num2))

4. Compare between worst-case, best-case, and average- case efficiencies of algorithm (AU.,

APR/MAY 2023)

The best-case time complexity represents the minimum amount of time an algorithm takes to

complete when given an input that leads to the most favorable conditions.
The average-case time complexity represents the average amount of time an algorithm takes to

complete over all possible inputs of a given size. It considers the expected performance over a

distribution of inputs.

The worst-case time complexity represents the maximum amount of time an algorithm takes to

complete when given an input that leads to the least favorable conditions.

5. Define Time and Space complexity (AU., APR/MAY 2010)

Time complexity measures the amount of time an algorithm takes to complete as a function of the size
of the input (denoted as n).

Space complexity measures the amount of memory space an algorithm uses as a function of the size of

the input.

6. List some Algorithm techniques

i) Dynamic programming

ii) Backtracking

iii) Greedy algorithm

iv) Divide & algorithm

7. Write the properties of Algorithm.

i) Input

ii) Output

iii) Well-definedness

iv) Definiteness

PART B – (3*12 = 36 Marks) (Any Three)

8. Describe the following important problem types i) Sorting ii) Searching iii) Combinatorial iv)

Graph problems (AU ., Nov/Dec 2023)

i) Sorting

 Description: Sorting involves arranging data in a particular order, typically ascending or descending.
It's a fundamental operation that often serves as a precursor to other algorithms, making the data easier
to work with.
 Examples: Bubble Sort, Merge Sort, Quick Sort, Heap Sort.
ii) Searching

 Description: Searching refers to finding specific data within a collection of data. This can be done in
an unordered or ordered manner, and the efficiency of the search often depends on the structure of the
data.
 Examples: Linear Search, Binary Search, Depth-First Search (DFS), Breadth-First Search (BFS).

iii) Combinatorial

 Description: Combinatorial problems deal with the arrangement and combination of objects according
to specific rules. These problems are often associated with optimization and counting.
 Examples: Permutations, Combinations, Traveling Salesman Problem, Knapsack Problem.

iv) Graph Problems

 Description: Graph problems involve the study of graphs, which are mathematical structures used to
model pairwise relations between objects. They can represent networks like social networks, computer
networks, or biological networks.
 Examples: Shortest Path (Dijkstra's Algorithm), Minimum Spanning Tree (Prim's and Kruskal's
Algorithms), Graph Coloring, Network Flow.

9. Explain the steps for Analyzing the efficiency of the algorithm with example ( AU .,NOV/DEC2023)

Steps for Analyzing Algorithm Efficiency

1. Understand the Algorithm:


o Clearly understand how the algorithm works and its input/output requirements.
2. Identify the Basic Operation:
o Determine the basic operation (e.g., comparison, assignment) that significantly affects the
running time of the algorithm.
3. Analyze the Input Size:
o Define the variable (usually n) that represents the size of the input.
4. Calculate the Number of Basic Operations:
o Count how many times the basic operation is executed as a function of the input size n.
5. Express the Time Complexity:
o Express the total number of basic operations using Big-O notation (e.g., O(n), O(n^2), O(log
n)).
6. Analyze the Space Complexity:
o Determine the amount of memory space required by the algorithm as a function of the input
size n.
7. Optimize (If Necessary):
o If the efficiency is not satisfactory, consider modifying the algorithm to improve its time or
space complexity.

10. Explain briefly Asymptotic notation with suitable example (AU ., Nov/Dec 2023 /APR/MAY2023)

Asymptotic Notations are mathematical tools used to analyze the performance of algorithms
by understanding how their efficiency changes as the input size grows.
There are mainly three asymptotic notations:
1. Big-O Notation (O-notation)
2. Omega Notation (Ω-notation)
3. Theta Notation (Θ-notation)
1. 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 (Average Case) You add the running times for each possible input combination and take the average
in the average case.
Let g and f be the function from the set of natural numbers to itself. The function f is said to be Θ(g), if
there are constants c1, c2 > 0 and a natural number n0 such that c1* g(n) ≤ f(n) ≤ c2 * g(n) for all n ≥ n0

Theta notation

Mathematical Representation of Theta notation:


Θ (g(n)) = {f(n): there exist positive constants c1, c2 and n0 such that 0 ≤ c1 * g(n) ≤ f(n) ≤ c2 * g(n) for
all n ≥ n0}
Note: Θ(g) is a set
The above expression can be described as if f(n) is theta of g(n), then the value f(n) is always between c1 *
g(n) and c2 * g(n) for large values of n (n ≥ n0). The definition of theta also requires that f(n) must be non-
negative for values of n greater than n0.
The execution time serves as both a lower and upper bound on the algorithm’s time complexity.
It exist as both, most, and least boundaries for a given input value.
A simple way to get the Theta notation of an expression is to drop low-order terms and ignore leading
constants. For example, Consider the expression 3n3 + 6n2 + 6000 = Θ(n3), the dropping lower order terms
is always fine because there will always be a number(n) after which Θ(n3) has higher values than Θ(n2)
irrespective of the constants involved. For a given function g(n), we denote Θ(g(n)) is following set of
functions.
Examples :
{ 100 , log (2000) , 10^4 } belongs to Θ(1)
{ (n/4) , (2n+3) , (n/100 + log(n)) } belongs to Θ(n)
{ (n^2+n) , (2n^2) , (n^2+log(n))} belongs to Θ( n2)
Note: Θ provides exact bounds.
2. Big-O Notation (O-notation) :
Big-O notation represents the upper bound of the running time of an algorithm. Therefore, it gives the
worst-case complexity of an algorithm.
.It is the most widely used notation for Asymptotic analysis.
.It specifies the upper bound of a function.
.The maximum time required by an algorithm or the worst-case time complexity.
.It returns the highest possible output value(big-O) for a given input.
.Big-O(Worst Case) It is defined as the condition that allows an algorithm to complete statement execution
in the longest amount of time possible.

If f(n) describes the running time of an algorithm, f(n) is O(g(n)) if there exist a positive constant C and n0
such that, 0 ≤ f(n) ≤ cg(n) for all n ≥ n0
It returns the highest possible output value (big-O)for a given input.
The execution time serves as an upper bound on the algorithm’s time complexity.

Mathematical Representation of Big-O Notation:


O(g(n)) = { f(n): there exist positive constants c and n0 such that 0 ≤ f(n) ≤ cg(n) for all n ≥ n0 }
For example, Consider the case of Insertion Sort. It takes linear time in the best case and quadratic time in
the worst case. We can safely say that the time complexity of the Insertion sort is O(n2).
Note: O(n2) also covers linear time.
If we use Θ notation to represent the time complexity of Insertion sort, we have to use two statements for
best and worst cases:
 The worst-case time complexity of Insertion Sort is Θ(n2).
 The best case time complexity of Insertion Sort is Θ(n).
The Big-O notation is useful when we only have an upper bound on the time complexity of an algorithm.
Many times we easily find an upper bound by simply looking at the algorithm.
Examples :
{ 100 , log (2000) , 10^4 } belongs to O(1)
U { (n/4) , (2n+3) , (n/100 + log(n)) } belongs to O(n)
U { (n^2+n) , (2n^2) , (n^2+log(n))} belongs to O( n^2)
Note: Here, U represents union, we can write it in these manner because O provides exact or upper
bounds .
3. 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.
The execution time serves as a lower bound on the algorithm’s time complexity.
It is defined as the condition that allows an algorithm to complete statement execution in the shortest
amount of time.
Let g and f be the function from the set of natural numbers to itself. The function f is said to be Ω(g), if
there is a constant c > 0 and a natural number n0 such that c*g(n) ≤ f(n) for all n ≥ n0

Mathematical Representation of Omega notation :


Ω(g(n)) = { f(n): there exist positive constants c and n0 such that 0 ≤ cg(n) ≤ f(n) for all n ≥ n0 }
Let us consider the same Insertion sort example here. The time complexity of Insertion Sort can be written
as Ω(n), but it is not very useful information about insertion sort, as we are generally interested in worst-
case and sometimes in the average case.
Examples :
{ (n^2+n) , (2n^2) , (n^2+log(n))} belongs to Ω( n^2)
U { (n/4) , (2n+3) , (n/100 + log(n)) } belongs to Ω(n)
U { 100 , log (2000) , 10^4 } belongs to Ω(1)

11. Explain the fundamentals of Algorithmic Problem Solving with neat Diagram.

Algorithmic problem solving is a systematic approach to solving computational problems. The process
involves several key steps to develop an efficient and effective algorithm. Let's break down the fundamentals
and include a neat diagram for better understanding.

Fundamentals of Algorithmic Problem Solving

 Problem Definition:
o Clearly define the problem that needs to be solved, including the input and the expected output.
 Understanding the Problem:
o Analyze the problem thoroughly to understand its requirements and constraints.
 Designing an Algorithm:
o Develop a step-by-step procedure to solve the problem. This includes choosing appropriate
data structures and techniques.
 Proving the Correctness:
o Ensure that the algorithm produces the correct output for all possible inputs.
 Analyzing the Algorithm:
o Determine the time complexity and space complexity to evaluate the efficiency of the
algorithm.
 Implementing the Algorithm:
o Write the code to implement the algorithm in a programming language.
 Testing and Debugging:
o Test the algorithm with various inputs to ensure it works as expected and debug any issues that
arise.
 Optimization (if necessary):
o Optimize the algorithm to improve its performance if needed.

Prepared by: D.Sujatha,AP/CSE Approved by:

You might also like