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

design analysis of algorithm

term paper

Uploaded by

olivertech
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
5 views6 pages

design analysis of algorithm

term paper

Uploaded by

olivertech
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

MURANG’A UNIVERSITY OF TECHNOLOGY

SCHOOL OF COMPUTING AND

INFORMATION TECHNOLOGY DEPARTMENT

OF INFORMATION TECHNOLOGY

SIT 300: DESIGN & ANALYSIS OF

ALGORITHM

CAT 1

Murwa Oliver Stivine


SC211/0818/2017
Date: 14th October 2024
Design and Analysis of Algorithm
Question Bank
1. Define the following terms as used in Design and Analysis of Algorithms.
i) Big Oh Notation
ii) Little Omega Notation
iii) Recurrence
iv) Amortized Analysis
v) Complexity of an algorithm.
2. Explain the divide and conquer strategy in which the division into two sub arrays is made so
that the sorted sub arrays do not need to be merged later.
3. Define stack, explain push and pop operations performed on stack.
4. Explain the term Algorithm giving FIVE characteristics of a good algorithm.
5. What do you understand by the term ‘Back Tracking’?
6. Explain: Worst case, Best case and Average case complexity?
7. Explain into details Directed Acyclic Graph & Principal of Optimality.
8. State and Explain the Prim’s Algorithm to find out Minimum Spanning Tree with illustration.
9. Explain any Three Asymptotic Notations giving examples.
10. What do you mean by time and space complexity? Among Quick sort, Insertion sort & Heap
sort, which algorithm is best to sort data and why?
11. Write a greedy method control abstraction for the subset paradigm.
12. Differentiate between state space tree and a problem state.
13. State graph coloring algorithm. Explain strategy used for solving it along with an example.
14. Define Cast adjacency matrix.
15. What is Hamiltonian cycle? Write an algorithm to find a Hamiltonian cycle.
ANSWERS
1. i) Big Oh Notation

Big Oh (O) notation is used to describe an upper bound on the time complexity or space
complexity of an algorithm. It represents the worst-case scenario, where the growth rate of
the algorithm’s running time (or space) is at most proportional to the given function, as the
input size grows indefinitely.

ii) Little Omega Notation (ω-notation)

Little Omega (ω) notation is used to describe a lower bound on the time complexity of an
algorithm. It signifies that for sufficiently large input sizes, the running time will always
exceed a certain threshold. It gives a strict lower bound, meaning the algorithm will always
take more time than the given function in the best-case scenario.

iii) Recurrence

Refers to a way of describing the running time of a recursive algorithm. It expresses the
overall running time of an algorithm as a function that depends on the size of the input,
typically broken into smaller sub problems.

iv) Amortized Analysis

Amortized Analysis is a technique for analysing the average running time of an algorithm
over a sequence of operations. Rather than looking at the worst-case time for a single
operation, amortized analysis considers the total cost over a series of operations and averages
the cost per operation.

v) Complexity of an Algorithm

Complexity of an Algorithm refers to a measure of the amount of resources (time and


space) an algorithm consumes as the input size increases.

2. Divide and Conquer Strategy with No Need for Merging

This refers to a divide and conquers approach where the problem is divided into sub
problems in such a way that the solutions to the sub problems do not need to be merged
afterward. A classic example is binary search, where the array is divided into two parts, and
only one half is searched. Since the other half is discarded and no merging is needed, this
eliminates the need to combine the results of the two sub problems.In binary search, the
algorithm splits the input in half and only searches one half based on a comparison, without
the need to recombine or merge results.
3. Stack: Push and Pop Operations

A stack is a linear data structure that follows the Last In, First Out (LIFO) principle.
Elements are added and removed from the same end, called the top of the stack.

 Push Operation: This operation adds an element to the top of the stack.
o Example: If the stack is [1, 2, 3], and you push 4, the stack becomes [1,
2, 3, 4].
 Pop Operation: This operation removes the element from the top of the stack.
o Example: If the stack is [1, 2, 3, 4] and you pop, the stack becomes [1,
2, 3].

4. Definition and Characteristics of an Algorithm

An algorithm is a step-by-step procedure or set of rules for solving a specific problem or


performing a computation in a finite amount of time.

Characteristics of a Good Algorithm:

1. Finiteness: The algorithm must terminate after a finite number of steps.


2. Definiteness: Each step of the algorithm must be clear and unambiguous.
3. Input: The algorithm should take some input values.
4. Output: The algorithm should produce at least one output.
5. Efficiency: The algorithm should make efficient use of time and space resources.

5. Backtracking

Backtracking is a problem-solving technique that involves building a solution incrementally


and abandoning a solution (backtracking) as soon as it is determined that this solution cannot
possibly lead to a valid or optimal result. It is commonly used in constraint satisfaction
problems like the N-Queens problem and solving mazes.

6. Worst Case, Best Case, and Average Case Complexity

 Worst Case Complexity: The maximum time or space an algorithm will take to solve
a problem, regardless of the input. It is usually represented using Big O notation.
o Example: For QuickSort, the worst case occurs when the pivot is always the
largest or smallest element, giving O(n2)O(n^2)O(n2).
 Best Case Complexity: The minimum time or space an algorithm will take to solve a
problem. It shows the most favorable input scenario.
o Example: For QuickSort, the best case occurs when the pivot divides the
array into two equal halves each time, giving O(nlog⁡n)O(n \log n)O(nlogn).
 Average Case Complexity: The expected time or space an algorithm takes on
average, considering all possible inputs.
o Example: For QuickSort, the average case complexity is O(nlog⁡n)O(n \log
n)O(nlogn).
7. Directed Acyclic Graph (DAG) and Principle of Optimality

 Directed Acyclic Graph (DAG): A graph with directed edges where no cycles exist.
This structure is used in many algorithms, such as topological sorting and dynamic
programming.
 Principle of Optimality: In dynamic programming, it states that an optimal solution
to a problem can be constructed from optimal solutions of its sub problems. It forms
the basis for solving problems by breaking them into overlapping sub problems.

8. Prim’s Algorithm for Minimum Spanning Tree (MST)

Prim’s Algorithm finds a Minimum Spanning Tree (MST) for a connected, weighted,
undirected graph. It starts from a single node and grows the MST one edge at a time, always
choosing the minimum weight edge that connects a vertex inside the MST to a vertex outside.

Steps:

1. Start with any vertex and mark it.


2. Select the smallest edge that connects a marked vertex to an unmarked vertex.
3. Add this edge to the MST and mark the new vertex.
4. Repeat until all vertices are marked.

9. Three Asymptotic Notations with Examples

1. Big O Notation: Represents the upper bound.


o Example: O(n2)O(n^2)O(n2) for bubble sort.
2. Big Omega Notation: Represents the lower bound.
o Example: Ω(n)\Omega(n)Ω(n) for linear search.
3. Theta Notation: Represents the tight bound (both upper and lower).
o Example: Θ(nlog⁡n)\Theta(n \log n)Θ(nlogn) for merge sort.

10. Time and Space Complexity Comparison

 Time Complexity: Refers to the amount of time an algorithm takes as a function of


the input size.
 Space Complexity: Refers to the amount of memory an algorithm uses as a function
of the input size.

Best Sorting Algorithm:

 Quicksort is generally preferred for large data sets due to its average-case time
complexity of O(nlog⁡n)O(n \log n)O(nlogn), despite its worst case
O(n2)O(n^2)O(n2). It is faster than Insertion Sort O(n2)O(n^2)O(n2) and Heap Sort
O(nlog⁡n)O(n \log n)O(nlogn) for most practical cases due to better cache performance
and lower constant factors.
11. Greedy Method Control Abstraction for Subset Paradigm

The greedy method selects a local optimal solution at each stage with the hope of finding the
global optimum. A common abstraction:

vbnet
Copy code
function GreedyMethod(X):
solution = empty set
while feasible(solution, X):
select next best option from X
add to solution
return solution

12. State Space Tree vs Problem State

 State Space Tree: A tree representation of all the possible states that can be reached
in a problem.
 Problem State: A specific configuration of the problem at a given moment in time.

13. Graph Coloring Algorithm

Graph Coloring assigns colors to the vertices of a graph so that no two adjacent vertices
share the same color.

Strategy:

1. Assign a color to a vertex.


2. Move to the next vertex and assign the smallest possible color not used by its
neighbors.
3. Repeat for all vertices.

14. Cast Adjacency Matrix

An adjacency matrix is a 2D array used to represent a graph. If a graph has nnn vertices, the
adjacency matrix is an n×nn \times nn×n matrix where an entry a[i][j]a[i][j]a[i][j] is 1 if there
is an edge between vertex iii and vertex jjj, and 0 otherwise.

15. Hamiltonian Cycle and Algorithm

A Hamiltonian Cycle is a cycle in a graph that visits each vertex exactly once and returns to
the starting vertex.

Algorithm:

 Start from a vertex.


 Recursively visit unvisited vertices, ensuring no vertex is visited twice.
 If you reach the starting vertex after visiting all other vertices, you have a
Hamiltonian cycle.

You might also like