Lecture-1+2-DAA-Math-Analysis(6)

Page 1: Introduction

  • Copyright Regulation 1969: Material is copied by Curtin University of Technology under the Copyright Act 1968.

Page 2: Course Structure

  • Course: Design and Analysis of Algorithms

  • Focus Areas:

    • Big O Notation

    • Recurrence Relations

Page 3: Pre-requisites

  • Understanding of Data Structures and Algorithms is required.

  • Advanced data structures will be used to enhance algorithm performance.

Page 4: Recommended Textbooks

  • Introduction to Algorithms by Cormen, Leiserson, and Rivest (3rd or 4th edition).

Page 5: Definition of Algorithm

  • Origin: Al Khwarizmi (9th century); his methodologies led to the term 'algorithm'.

  • An algorithm is defined as:

    • A computational procedure.

    • Takes input and produces output.

    • Solves a computational problem.

  • Characteristics:

    • Correctness: must always provide the right output.

    • Tractability: must solve in reasonable time.

    • Forms: can be expressed in various ways (English, code, designs).

Page 6: Example Problem - Sorting

  • Sorting Problem:

    • Input: sequence of n numbers (a1, a2, ..., an)

    • Output: reordered sequence (b1, b2, ..., bn) satisfying b1 ≤ b2 ≤ ... ≤ bn

    • Example:

      • Input: (30, 20, 41, 51, 3, 20)

      • Output: (3, 20, 20, 30, 41, 51)

Page 7: Insertion Sort Algorithm

  • Insertion Sort implementation:

    1. Loop through elements from 2 to n.

    2. Identify key as the current element.

    3. Rearrange elements in sorted order.

    • Characteristics:

      • In-place sorting: only requires constant memory.

      • Stable: maintains order of repeated elements.

      • Efficient for small/sorting-nearly sorted inputs.

Page 8: Insertion Sort Illustration

  • Stepwise Sorting Example:

    1. Start with: [5, 2, 4, 6, 1, 3]

    2. Proceeding through steps until fully sorted.

Page 9: Example Problem - Greatest Common Divisor (GCD)

  • GCD Definition:

    • Input: Two integers X and Y.

    • Output: Largest integer Z that divides both X and Y.

    • Example:

      • Input: X = 1035, Y = 759

      • Output: GCD = 69.

    • Methods to calculate GCD:

      1. Factorization method.

      2. Euclidean algorithm.

Page 10: Euclid's Algorithm for GCD

  • Recursive Method:

    • GCD(X, Y) = GCD(X mod Y, Y).

    • Example implementation shown.

Page 11: Least Common Multiple (LCM)

  • LCM Definition:

    • Input: Two integers X and Y.

    • Output: Smallest integer Z divisible by both X and Y.

    • Example: LCM of 1035 and 759 = 11385.

Page 12: Computing LCM via GCD

  • LCM Formula:

    • LCM(X, Y) = (X * Y) / GCD(X, Y).

    • Example for computation shown.

Page 13: Integer Multiplication Example

  • Example: Multiply X = 12, Y = 34.

    • Straightforward multiplication yield Z = 408.

Page 14: Al Khwarizmi’s Multiplication Algorithm

  • Steps:

    1. Halve the first number.

    2. Double the second.

    3. Continue until the first number is 1.

    4. Sum results based on odd-numbered rows.

Page 15: Large Integer Multiplication

  • For n-digit numbers, straightforward methods become inefficient.

  • Divide and Conquer Approach:

    • Calculate using smaller subproblems.

Page 16: Karatsuba's Algorithm

  • Karatsuba's Multiplication:

    • Acknowledged for reducing multiplications from four to three.

  • Offers improved performance over traditional methods.

Page 17: Adding Consecutive Numbers

  • Input: Integer n (e.g., 1 + 2 + ... + n)

    • Efficient method: Sum = n(n + 1)/2.

    • Example with n = 10 gives total 55.

Page 18: Algorithm Efficiency

  • Algorithms can significantly differ in performance.

    • Example: Insertion Sort vs. Merge Sort time comparisons.

Page 19: CPU Comparison and Efficiency

  • Even slower CPUs can outperform faster ones with optimal algorithms due to efficiency.

Page 20: Designing an Algorithm

  • Steps involve reducing problems, employing brute force, improving efficiency.

Page 21: Algorithm Design Techniques

  • Tricks:

    • Better data structures for efficient access.

    • Preprocessing input for algorithm optimization.

Page 22: Advanced Design Techniques

  • Divide & Conquer, Greedy Approach, and Dynamic Programming.

Page 23: Algorithm Efficiency Metrics

  • Measure speed and sometimes memory use.

Page 24: Computation Model Basics

  • Usually based on Random Access Machine (RAM) principles.

Page 25: Operations in RAM Model

  • Illustrative examples of operation steps in algorithms.

Page 26: Insertion Sort Cost Analysis

  • Breakdown of time complexity in terms of steps.

Page 27: Insertion Sort Running Time

  • Discusses varying scenarios based on element arrangement.

Page 28: Best Case Scenario for Insertion Sort

  • Sorted array scenario leading to optimal complexity.

Page 29: Worst Case for Insertion Sort

  • Analysis of reverse-sorted input yielding maximum complexity.

Page 30: Function Growth

  • Faster growing functions become dominant for large n.

Page 31: Big O Notation Basics

  • O(g(n)) represents an asymptotic upper bound.

Page 32: Big O Example

  • Demonstration of function comparisons using Big O notation.

Page 33: Example of Proving Big O

  • Providing proofs for function bounds using constants.

Page 34: Order of Constant Operations

  • Constants represented in Big O notation for algorithm steps.

Page 35: Analysis of Execution Order

  • Executing lines repetitively leads to linear complexity.

Page 36: Final Complexity of Fragments

  • Summarizing individual complexities to derive overall complexity.

Page 37: Back to Example

  • Demonstrating further on overall complexity summation.

Page 38: Simple Big O Visualizations

  • Illustratic examples portraying algorithmics in graph form.

Page 39: Understanding Complexity Proofs

  • Conveys that complexity proofs may not always be necessary.

Page 40: Nested Loops

  • Analyzing iteration complexities in nested structures.

Page 41: Aim for Tight Bound

  • Discusses the importance of achieving tight upper bounds in Big O notation.

Page 42: Big-Omega Notation W(n)

  • Representation of asymptotic lower bounds.

Page 43: Example of Big Omega

  • Demonstrating the proof of lower bounds through function comparisons.

Page 44: Big-Theta Notation Q(n)

  • Defines asymptotic tight bounds encompassing both upper and lower bounds.

Page 45: Examples of Big-Theta Proofs

  • Guiding through proofs to confirm respective bounds.

Page 46: Extended Proof Techniques

  • Discussing deeper strategies and examples for Big-Theta proofs.

Page 47: Other Algorithmic Examples

  • Various algorithm examples to demonstrate theoretical bounds and their implications.

Page 48: Additional Analysis of Operations

  • Signs of complexity can originate from single or multiple operations.

Page 49: Worst Case Analysis

  • Examining how worst case scenarios are determined.

Page 50: Best Case Analysis

  • Conditions under which best case efficiencies occur.

Page 51: Average Case Complexity

  • Discussing uniform probability of inputs leading to average complexities.

Page 52: Expected Case Analysis

  • Identifying standard inputs leading to expected performance.

Page 53: Summary of Algorithm Time Analysis

  • Recap on modeling computation and strategies for efficiency measurement.

Page 54: Memory Analysis in Algorithms

  • Discusses considerations regarding memory use in practical applications.

Page 55: Selection Sort Algorithm

  • Stepwise breakdown of a fundamental sorting algorithm.

Page 56: Selection Sort Example

  • Illustrates how selection sort achieves an ordered array.

Page 57: Time Complexity Analysis of Selection Sort

  • Detailed examination of time complexities in selection sorting.

Page 58: Inductive Proof Basics

  • Introduces induction as a method to prove algorithm correctness.

Page 59: Induction and Algorithm Analysis

  • Extended view on how induction applies to algorithm proof.

Page 60: Inductive Example

  • Concrete example applying inductive principles in proofs.

Page 61: Fibonacci Sequence Proof

  • Illustrates the Fibonacci sequence characteristics and its analyzation.

Page 62: Induction Proof of Fibonacci

  • Steps to establish the bounds of Fibonacci numbers using induction.

Page 63: Analyzing Recursive Functions

  • Discussing how to manage time complexity in recursive functions through recurrence.

Page 64: Recursive Selection Sort Analysis

  • Analysis of the recursive approach to selection sorting.

Page 65: Iterative Method for Recurrence

  • Discussing strategies to analyze time complexity via iterative substitution.

Page 66: Inductive Strategy for Recurrences

  • Instruction on utilizing guesswork paired with induction for proof.

Page 67: Recursion Tree Application

  • Framework to visualize and derive complexities from recursive calls.

Page 68: Proving Time Complexity

  • Further exploration into proving time bounds of recursive functions.

Page 69: Master Method Overview

  • Understanding the Master Theorem for deriving complexities of algorithms.

Page 70: Case Analysis in Master Theorem

  • Detailed explanation of conditions that determine complexity cases.

Page 71: Master Theorem Application

  • Guidelines for employing the Master Theorem in analysis.

Page 72: Example of Master Theorem Application (Case 1)

  • Illustration of solving a particular case using the Master Theorem.

Page 73: Another Case Example with Master Theorem

  • Further example analysis within different framework conditions.

Page 74: Master Theorem for Advanced Complexity

  • Case studies revisiting previous examples under enhanced complexity conditions.

Page 75: Completing Case 3 Analysis

  • Overview of satisfying Master Theorem conditions under Case 3 scenarios.

Page 76: Finalizing the Master Theorem Cases

  • Show full expectations of scenario outcomes based on derived results.

Page 77: Proving Algorithmic Correctness via Loop Invariants

  • Establishing correctness through established criteria of loop invariants.

Page 78: Correctness of Insertion Sort

  • Application of loop invariant proof to verify insertion sort correctness.

Page 79: Continued Verification of Insertion Sort

  • Iterative aspects of proving the insertion sort maintains its sorting property.

Page 80: Selection Sort Correctness Confirmation

  • Detailed proof illustrating selection sort correctness through invariant usage.