Title: Euclids Algorithm
1Euclids 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
2Flowchart of Euclids Algorithm
3Properties of an Algorithm
- Every step is unambiguous
- Clearly defined input and output
- It must be executable in a finite amount of time
4Properties 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
5Properties 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
6Properties 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
7Is this an Algorithm?
8Is this an Algorithm?
- Do the following 34783287636 times
- Say Ooga chaka
9Is this an Algorithm?
- Find a bag of sugar.
- Using a teaspoon, scoop out a smidgen of sugar
and pour it on the table.
10Is 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
11Is this an Algorithm?
- Find a bag of sugar.
- Dump it out on the table.
12Data 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
13Data 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!
14What is Computer Science?
- It is the study of algorithms and data
structures, including their - formal and mathematical properties
- hardware realizations
- linguistic realizations
- applications
15What 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
16What 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
17What 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
18What 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.
19What is a program?
- The implementation of an
- algorithm
20What is a programming language?
- A formal language for
- encoding programs
21(No Transcript)
22Some Computer Programming Languages
- http//dmoz.org/Computers/Programming/Languages/
23Some Other Programming Languages
- A traditional first program is one that prints
Hello, World! on your computer screen
24Hello 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.
25Hello 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.
26Hello 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.
27Hello 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.
28Hello 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.
29Hello 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.
30Hello 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.
31Hello 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.
32Hello 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.
33Hello World in Befunge
- "!dlrow olleH"gtv
- ,
- __at_
34Hello World in Brainfudge
- gtgtgtgtltltltlt-gt.gt.
...gt.ltlt .gt..------.--
------.gt.gt.
fudge is not the correct word here. You can
guess what is.
35Hello 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.
36More Ways to Write Hello World
- http//www.infiltec.com/j-h-wrld.htm
37Hello World in Python