Euclids Algorithm - PowerPoint PPT Presentation

1 / 37
About This Presentation
Title:

Euclids Algorithm

Description:

Output: the greatest common divisor (GCD) of a and b ... thus causing the computer to overheat slightly, which could damage the casing ... – PowerPoint PPT presentation

Number of Views:266
Avg rating:3.0/5.0
Slides: 38
Provided by: tobydon
Category:

less

Transcript and Presenter's Notes

Title: Euclids Algorithm


1
Euclids Algorithm
  • Input positive integers a and b
  • Output the greatest common divisor (GCD) of a
    and b
  • Repeat the following until a and b are the same
    value
  • if a gt b
  • set a to a b
  • else
  • set b to b a
  • Return a as the answer

Try this algorithm by hand with a 91 and b 65
2
Flowchart of Euclids Algorithm
3
Properties of an Algorithm
  • Every step is unambiguous
  • Clearly defined input and output
  • It must be executable in a finite amount of time

4
Properties of an Algorithm
  • Every step is unambiguous
  • This is because it is going to be run by a
    computer that is so stupid that if it had a nose
    it wouldnt know how to stuff crayons up it.
  • Clearly defined input and output
  • It must be executable in a finite amount of time

5
Properties of an Algorithm
  • Every step is unambiguous
  • Clearly defined input and output
  • You know that stuff that you use for that thing?
    If we could get a computer to do it, then, you
    know, it will be, like, easier if thats what you
    need, you know. Sort of. Right? Dont look at me
    like Im crazy --- this is a good idea and you
    know it!
  • It must be executable in a finite amount of time

6
Properties of an Algorithm
  • Every step must unambiguous
  • Clearly defined input and output
  • It must be executable in a finite amount of time
  • Programs that run forever are not usually very
    interesting because, you know, THE HEAT DEATH OF
    THE UNIVERSE WILL OCCUR AT SOME POINT WHILE THE
    PROGRAM IS RUNNING thus causing the computer to
    overheat slightly, which could damage the casing

7
Is this an Algorithm?
  • Say Ooga chaka
  • Goto 1

8
Is this an Algorithm?
  • Do the following 34783287636 times
  • Say Ooga chaka

9
Is this an Algorithm?
  • Find a bag of sugar.
  • Using a teaspoon, scoop out a smidgen of sugar
    and pour it on the table.

10
Is this an Algorithm?
  • Find a bag of sugar.
  • If the bag is empty, then give up.
  • Using a teaspoon, scoop out one teaspoon of sugar
    and pour it on the table.
  • Goto step 2

11
Is this an Algorithm?
  • Find a bag of sugar.
  • Dump it out on the table.

12
Data Structures
  • All algorithms process data
  • At the lowest level of a real-world computer,
    data is represented as sequences of 0s and 1s
  • 101101001010101 is a binary string, or bit string
    for short
  • A bit is a 0 or a 1 --- bit is short for binary
    digit
  • Modern computers are built up from bits because
    bit-processing hardware is cheap and reliable

13
Data Structures
  • Building on bit strings, we can create more
    complex data structures such as
  • Numbers integers, floating point numbers,
    imaginary numbers
  • Strings of characters
  • a web page is just a string of characters
  • Sequences of numbers, e.g. arrays and matrices
  • An image is just an array of numbers representing
    colors
  • Tables of records containing the name and address
    of all students who fall asleep during class
  • Anything can be represented by a sequence of bits!

14
What is Computer Science?
  • It is the study of algorithms and data
    structures, including their
  • formal and mathematical properties
  • hardware realizations
  • linguistic realizations
  • applications

15
What is Computer Science?
  • It is the study of algorithms and data
    structures, including their
  • formal and mathematical properties
  • What can be computed? What is the most efficient
    way to solve a particular problem?
  • hardware realizations
  • linguistic realizations
  • applications

16
What is Computer Science?
  • It is the study of algorithms and data
    structures, including their
  • formal and mathematical properties
  • hardware realizations
  • Whats the structure of a CPU? How is computer
    memory implemented? What is the most
    cost-effective kind of computer hardware?
  • linguistic realizations
  • applications

17
What is Computer Science?
  • It is the study of algorithms and data
    structures, including their
  • formal and mathematical properties
  • hardware realizations
  • linguistic realizations
  • Whats the clearest/shortest way to describe
    computations? Whats the best way to organize
    large programs?
  • applications

18
What is Computer Science?
  • It is the study of algorithms and data
    structures, including their
  • formal and mathematical properties
  • hardware realizations
  • linguistic realizations
  • applications
  • Graphics, artificial intelligence, databases,
    networking, software engineering, etc.

19
What is a program?
  • The implementation of an
  • algorithm

20
What is a programming language?
  • A formal language for
  • encoding programs

21
(No Transcript)
22
Some Computer Programming Languages
  • http//dmoz.org/Computers/Programming/Languages/

23
Some Other Programming Languages
  • A traditional first program is one that prints
    Hello, World! on your computer screen

24
Hello World in Assembly Language
  • MODEL SMALL
  • IDEAL
  • STACK 100H
  • DATASEG
  • MSG DB 'Hello, world!'
  • CODESEG
  • MOV AX, _at_data
  • MOV DS, AX
  • MOV DX, OFFSET MSG
  • MOV AH, 09H DOS output ASCII
    string
  • INT 21H
  • MOV AX, 4C00H
  • INT 21H
  • END

Assembly language is very low-level, and so quite
efficient. However, large assembly programs are
extremely difficult to create and understand.
25
Hello World in FORTRAN
  • PROGRAM HELLO
  • WRITE(, 10)
  • 10 FORMAT('Hello, world!')
  • STOP
  • END

FORTRAN was one of the first high-level languages
and was developed in the 1950s. It is still
popular today for scientific computing.
26
Hello World in COBOL
  • IDENTIFICATION DIVISION.
  • PROGRAM-ID. HELLO-WORLD.
  • ENVIRONMENT DIVISION.
  • DATA DIVISION.
  • PROCEDURE DIVISION.
  • DISPLAY "Hello, world!".
  • STOP RUN.

Developed in the late 1950s specifically for
writing business programs. Still popular in some
places, but (thankfully!) being replaced by more
modern languages.
27
Hello World in BASIC
  • 10 PRINT "Hello, world!"
  • 20 END

BASIC stands for Beginners All-purpose Symbolic
Instructional Code, and was developed for
teaching programming in the mid 1960s. Very
popular language, although falling out of favour.
28
Hello World in C
  • include ltstdio.hgt
  • int main()
  • printf("Hello, world!\n")
  • return 0

C was developed in the early 1970s to help
implement the Unix operating system. Popular and
influential language.
29
Hello World in C
  • include ltiostreamgt
  • int main()
  • stdcout ltlt "Hello, world!\n"

A (near) superset of C, C improves many aspects
of C and also adds object-oriented programming.
30
Hello World in Ada
  • with Ada.Text_Io
  • procedure Hello is
  • begin
  • Ada.Text_Io.Put_Line ("Hello, world!")
  • end Hello

Developed in the 1970s by the US military, Ada
was supposed to be the ultimate programming
language. But it is very complex, and never
caught on.
31
Hello World in Java
  • public class Hello
  • public static void main(String args)
  • System.out.println("Hello, world!")

Java was developed in the early 1990s as an
improved version of C. Along with C, Java is
currently one of the most popular general-purpose
programming languages.
32
Hello World in C
  • using System
  • class HelloWorldApp
  • public static void Main() Console.WriteLine("H
    ello, world!")

Developed by Microsoft as a sort of response to
Java. Similar to Java.
33
Hello World in Befunge
  • "!dlrow olleH"gtv
  • ,
  • __at_

34
Hello World in Brainfudge
  • gtgtgtgtltltltlt-gt.gt.
    ...gt.ltlt .gt..------.--
    ------.gt.gt.

fudge is not the correct word here. You can
guess what is.
35
Hello World in Ook
  • Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook.
    Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook?
    Ook! Ook! Ook? Ook! Ook? Ook. Ook. Ook. Ook! Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook. Ook. Ook.
    Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook?
    Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook?
    Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook.
    Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook?
    Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook! Ook! Ook!
    Ook! Ook! Ook! Ook. Ook? Ook. Ook? Ook. Ook? Ook.
    Ook? Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook.
    Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook!
    Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook!
    Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook!
    Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook.
    Ook! Ook.

36
More Ways to Write Hello World
  • http//www.infiltec.com/j-h-wrld.htm

37
Hello World in Python
  • print "Hello, world!"
Write a Comment
User Comments (0)
About PowerShow.com