1 Foundation Of Algorithm Analysis

Design and Analysis of Algorithms · Unit 1 · 4 hrs

Foundation of Algorithm Analysis

Exam-focused notes for Foundation of Algorithm Analysis (Design and Analysis of Algorithms, CSC325): what the TU syllabus asks and how it has actually been tested, with 13 solved past questions from this unit.

What this unit covers

  • Algorithm and its properties
  • RAM model
  • Time and Space Complexity
  • detailed analysis of algorithms (Like factorial algorithm)
  • Concept of Aggregate Analysis
  • Asymptotic Notations: Big-O, Big-Ω and Big-Ө Notations their Geometrical Interpretation and Examples
  • Recurrences: Recursive Algorithms and Recurrence Relations
  • Solving Recurrences (Recursion Tree Method, Substitution Method, Application of Masters Theorem)

Solving Recurrences

20825 marks

Solve the recurrence relation T(n) = 2T(n/2) + n using recursion tree method. [5]

- Recurrence: $T(n) = 2T\left(\dfrac{n}{2}\right) + n$ - Branching factor: $a = 2$ (each node makes 2 recursive calls) - Subproblem shrink factor: $b = 2$ (size divided by 2) - Cost at a node of size $m$: $m$ (the "$+n$" term) - Base case: $T(1) = \Theta(1)...

Full solved answer →
20815 marks

Solve the following recurrence relations using master's method.

  1. $T(n) = 2T\left(\frac{n}{2}\right) + n^3,\ n > 1;\quad T(n) = 1,\ n = 1$

  2. $T(n) = 2T\left(\frac{n}{4}\right) + 1,\ n > 1;\quad T(n) = 1,\ n = 1$

[5]

For $T(n) = aT\left(\frac{n}{b}\right) + f(n)$ with $a \geq 1$, $b 1$: Compute the critical exponent $\logb a$ and compare $f(n)$ with $n^{\logb a}$: Case Condition Result ------------------------- 1 $f(n) = O(n^{\logb a - \epsilon})$, $\epsilon 0$ $T(n) = ...

Full solved answer →
2080

Recurrence Relations and Solving using Substitution Method

A recurrence relation is an equation or inequality that describes a function in terms of its values on smaller inputs. To solve a recurrence relation means to obtain a function defined on the natural numbers that satisfies the recurrence. When we analyze re...

Full solved answer →
20795 marks

Solve the following recurrence relations using masters method.

a. $T(n) = 2T(n/4) + kn^2,\ n > 1;\ T(1) = 1$

b. $T(n) = 5T(n/4) + kn,\ n > 1;\ T(1) = 1$

[5]

For $T(n) = aT(n/b) + f(n)$ with $a \geq 1$, $b 1$, compare $f(n)$ with $n^{\logb a}$: - Case 1: $f(n) = O(n^{\logb a - \epsilon})$ $\Rightarrow$ $T(n) = \Theta(n^{\logb a})$ - Case 2: $f(n) = \Theta(n^{\logb a})$ $\Rightarrow$ $T(n) = \Theta(n^{\logb a}\lo...

Full solved answer →
20785 marks

Explain the recursion tree method for solving the recurrence relation. Solve following recurrence relation using this method. T(n)=2T(n/2) +1 for n>1, T(n)=1 for n=1 [5]

The recursion tree method is a technique for solving recurrence relations by expanding the recurrence into a tree. Each node represents the cost incurred at a subproblem, and the children of a node represent the recursive subproblems generated. The total co...

Full solved answer →
20765 marks

Solve the following recurrence relation using the master method.

a. $T(n) = 7 T(n/2) + n^2$

b. $T(n) = 4 T(n/4) + kn$

[5]

- Part a: $T(n) = 7T(n/2) + n^2$ - Part b: $T(n) = 4T(n/4) + kn$ (where $k$ is a positive constant) For a recurrence $T(n) = aT(n/b) + f(n)$ with $a \geq 1$, $b 1$, compare $f(n)$ with $n^{\logb a}$: Case Condition Result ------------------------- 1 $f(n) =...

Full solved answer →

Asymptotic Notations

20815 marks

Write short notes on: a) Big Oh, Big Omega, Big theta b) Class P, Class NP and NP-Complete [5]

--- Big Oh notation gives the asymptotic upper bound of a function. Definition: A function f(x) is said to be O(g(x)) if and only if there exist two positive constants c and x₀ such that: For all x = x₀ : f(x) <= c g(x) This means g(n) is the upper bound of...

Full solved answer →
207610 marks

What do you mean by the complexity of an algorithm? Explain the asymptotic notations used to describe the time/space complexity of any algorithm with their geometrical interpretation and example.[10]

Algorithm complexity is a measure of the amount of time and/or space (memory) required by an algorithm as a function of the input size n. - Time Complexity -- the number of basic operations performed as a function of input size n (using the RAM model, where...

Full solved answer →

RAM model

20805 marks

Define RAM model. Write down iterative algorithm for finding factorial and provide its detailed analysis. [5]

Definition: The Random Access Machine (RAM) model is a model for counting the steps in an algorithm in order to analyze its time complexity. In this model: - Basic operations (+, -, , /) are counted as 1 step - Memory references (read/write) are counted as ...

Full solved answer →
207810 marks

What are the elementary properties of algorithm? Explain. Why do you need algorithm? Discuss about analysis of the RAM model for analysis of algorithm with suitable example.[10]

--- An algorithm is a finite set of instructions where each instruction can be executed in finite time to perform computation by taking some value as input and to produce value(s) as output. The following are the elementary properties (characteristics) of a...

Full solved answer →

Concept of Aggregate Analysis

20805 marks

Write short notes on a) Aggregate Analysis b) Selection problems [5]

Definition: Aggregate analysis is a technique used in amortized analysis that determines the upper bound T(n) on the total cost of a sequence of n operations, then calculates the average (amortized) cost per operation as T(n)/n. Steps in Aggregate Analysis:...

Full solved answer →

Time and Space Complexity

20795 marks

Write short notes on: a) Best, Worst and average case complexity b) Greedy Strategy [5]

--- When analyzing an algorithm, the running time often depends not just on the size of the input but also on the particular instance of the input. To capture this, we define three cases: --- - It gives the lower bound on the running time of the algorithm f...

Full solved answer →

detailed analysis of algorithms

20785 marks

Write an algorithm to find the maximum element of an array and analyze its time complexity. [5]

An algorithm is a finite set of instructions where each instruction can be executed in finite time, taking input value(s) and producing output value(s). The iterative approach is used here to find the maximum element. --- Input: Array A of n elements (index...

Full solved answer →