Euclid's Algorithm and Algorithm Efficiency: Understanding Big O Notation, Slides of Data Structures and Algorithms

An analysis of euclid's algorithm for finding the highest common factor of two numbers and discusses the importance of algorithm efficiency. It covers the concept of big o notation and how it is used to compare the growth rates of different algorithms. The document also includes examples and clarifications.

Typology: Slides

2012/2013

Uploaded on 04/30/2013

dinpal
dinpal 🇮🇳

3.6

(12)

73 documents

1 / 46

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Analyzing Algorithms and Problems
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

Partial preview of the text

Download Euclid's Algorithm and Algorithm Efficiency: Understanding Big O Notation and more Slides Data Structures and Algorithms in PDF only on Docsity!

Analyzing Algorithms and Problems

Euclid's Algorithm

  • In Euclid's 7th book in the Elements series (written about 300BC), he gives an algorithm to calculate the highest common factor (largest common divisor) of two numbers x and y where (x < y). This can be stated as:
  • 1.Divide y by x with remainder r.
  • 2.Replace y by x, and x with r.
  • 3.Repeat step 1 until r is zero.
  • When this algorithm terminates, y is the highest common factor.

Euclid's Algorithm

  • Euclid's Algorithm determines the greatest common divisor of two natural numbers a, b. That is, the largest natural number d such that d | a and d | b. - GCD(33,21)= - 33 = 121 + 12 - 21 = 112 + 9 - 12 = 19 + 3 - 9 = 3

Time vs. Input Graph

How do you know if you have the best

algorithm?

A lower bound can be established because a basic number of operations must be performed. Thus, any algorithm that performs that number would be optimal, even if no such algorithm has been found that uses that number of steps.

Hanoi Tower

  • Long time ago, there were three towers in Honoi. In the very beginning, there were 64 disks with different sizes stacking on the A tower, small disks always stepping on the bigger disks. A monk had to move all disks to the C tower following rules: - 1. Each time only one disk could be moved from a tower, to any other; - 2. At anytime, small disks should step on the bigger disks, not allowing big disks step on smaller disks.

. Count the number of basic operations

performed by the algorithm on the worst-case input

  • A basic operation could be:
    • An assignment
    • A comparison between two variables
    • An arithmetic operation between two variables. The worst-case input is that input assignment for which the most basic operations are performed.

Algorithm Efficiency

  • Determining the efficiency of an Algorithm is done by counting the number of basic operations that are carried out when the algorithm is executed
  • A basic operation is an operation carried out by the algorithm that is language independent, such as addition, subtraction, comparison of two values, etc…

Asymptotic Notation for Big O

  • Big O (Omicron) can be defined as
    • Note: the following two conditions must be met:
      • The limit must exist
      • The limit c < ∞