ALGORITHMS - PowerPoint PPT Presentation

About This Presentation
Title:

ALGORITHMS

Description:

... call it a 'guess' Divide 'A' by the 'guess' call the result ' ... All done (your last guess is pretty good) Square Roots. g1=1. A=50. g2=50/1=50. g1=(1 50)/2=25.5 ... – PowerPoint PPT presentation

Number of Views:11
Avg rating:3.0/5.0
Slides: 24
Provided by: thaddeusf
Category:
Tags: algorithms | guess

less

Transcript and Presenter's Notes

Title: ALGORITHMS


1
ALGORITHMS
  • CSC 171
  • LECTURE 1

2
What is Computer Science?
  • What is Science?
  • What is a Computer?
  • What is Computation?

3
Computer Science
  • Is Computer Science, science?
  • Is computation part of nature?
  • Is information part of nature?
  • How do we study computation?

4
Computational Science
  • A mode of scientific investigation that includes
    several phases
  • Development of a mathematical model (equation) of
    some physical phenomenon or system
  • Development of an algorithm to solve the model
  • Implementation of the algorithm in software
  • Simulation of the phenomenon using software
  • Graphical visualization of the results
  • Interpretation and validation of the results,
    which may lead to refinement of the original
    model and repetition of the cycle

5
History
  • Muhammad ibn Musa Al'Khowarizmi (ca. 825)
  • Described rules to be followed for arithmetics
    using Hindu numerals.
  • A written process to be followed to achieve some
    goal
  • Translated into Latin in 1202 by Leonardo
    Fibonacci

6
ALGORITHM
  • An algorithm is a procedure for solving problems
    in terms of
  • The actions to be executed (statements)
  • The order in which these actions are executed
  • Algorithms are independent of any specific
    computer language which may be used to for their
    implementation.
  • Often expressed informally as pseudocode.

7
Some Algorithms
  • How do I get to the pit?
  • Your classmate
  • Your parents
  • A robot
  • Move forward x meters
  • Turn right y radians

8
Abstraction
  • To one computer
  • x y 5
  • To another
  • Load y in accumulator
  • Load 5 in register A
  • Add register 5 to accum
  • Store accum in x

9
Statements
  • What do we need for Statements
  • Syntax
  • the form in which statements may be written
  • Semantics
  • meaning attached to syntactic constructs

10
Example
  • Syntax
  • F (9/5) C 32
  • 2 F 3)C 9 / 5(
  • Semantics
  • Take the Celsius temperature
  • Multiply it by 1.8
  • Add 32
  • The result is the Fahrenheit temperature

11
Example Finding square roots
  1. Determine the value you want a square root of
    call it A
  2. Start with 1 call it a guess
  3. Divide A by the guess call the result
    second_guess
  4. If guess is not close to second_guess, then set
    your guess to the average of guess and second
    guess and go to step 3.
  5. All done (your last guess is pretty good)

12
Square Roots
  • g11
  • A50
  • g250/150
  • g1(150)/225.5
  • g250/25.51.96
  • g1(25.51.96)/213.73
  • g250/13.733.641
  • g1(13.733.641)/2 8.68
  • g2 50/8.685.76
  • g1(8.685.76)/27.22
  • g250/7.226.92
  • g1(7.226.92)/27.07
  • g2(50/7.07)7.072
  • All done

13
Language
  • What does language do?
  • Transfer information (describe)
  • Action oriented languages (directions)
  • Functional languages
  • Area Pi Radius Radius
  • Object oriented languages
  • model the world around us

14
Computer Languages
  • To a human we might say
  • Write Hello, CSC 171
  • To a computer we might say
  • System.out.println(Hello, CSC 171)

15
History
  • 1612 Napier invented and decimal points and
    logarithms.
  • 1622 William Oughtred created the slide rule

16
History
  • 1622 William Oughtred created the slide rule

17
A Computer Program
  • public class myFirstProgram
  • public static void main(String args)
  • System.out.println(Hello, CSC171)

18
Programs in General
  • Programs contain 3 types of things
  • Comments notes to humans
  • Headers references to other code
  • Code instructions to humans

19
The Containment Pattern
  • Starts with some begin symbol
  • (
  • Ends with some end symbol
  • )
  • General Pattern ltbegingtltcontentsgtltendgt

20
Named containment
  • ltheadergt ltcontainmentgt
  • ltheadergt ltbegingtltcontentsgtltendgt
  • Often used as a mechanism of abstraction

21
The sequence pattern
  • A sequence is a list of one or more instructions
    to be followed in order
  • Sequence can be empty or
  • Sequence can be
  • ltinstructiongt ltsequencegt
  • ltinstructiongt ltinstructiongt
    ltsequencegt
  • Etc
  • Robot example complex instructions

22
Objects
  • A class of things are objects with similar
    attributes
  • Objects are instances of a class
  • A class is a general description of an object
  • A cookie cutter defines a class of cookies
  • An cookie is object
  • Rubber stamp

23
myFirstProgram.java
  • Contains a class definition, which contains
  • A method named main, which contains
  • An instruction to the System.out object
  • The instuction is a comand to print something
  • That something is a String of characters
  • Hello, CSC171 is a data item
Write a Comment
User Comments (0)
About PowerShow.com