algorithms n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Algorithms PowerPoint Presentation
Download Presentation
Algorithms

Loading in 2 Seconds...

play fullscreen
1 / 18

Algorithms - PowerPoint PPT Presentation


  • 144 Views
  • Uploaded on

2.2. Algorithms. Overview. In this presentation we will discuss: What is an algorithm? 5 steps in developing an algorithm A Jeroo example. An algorithm is. A plan for solving a problem 5 steps in algorithm development Describe the problem clearly Analyze the problem

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Algorithms' - brigid


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
overview
Overview
  • In this presentation we will discuss:
    • What is an algorithm?
    • 5 steps in developing an algorithm
    • A Jeroo example
an algorithm is
An algorithm is...
  • A plan for solving a problem
  • 5 steps in algorithm development
    • Describe the problem clearly
    • Analyze the problem
    • Develop a high-level algorithm
    • Refine the algorithm by adding detail
    • Review the algorithm
step 1 describe the problem
Step 1: describe the problem
  • Not as easy as it seems.
  • Common defects:
    • Description relies on unstated assumptions
    • Description is ambiguous
    • Description is incomplete
    • Description has contradictions
  • Natural spoken languages are not very precise.
  • It’s the developer’s job to spot any of these problems BEFORE any problem solving happens.
step 2 analyze the problem
Step 2 : Analyze the problem
  • Similar to a mathematician determining what factors and given and what must be proven in a complex set of equations.
  • Ask:
    • What data is available?
    • What formulas are needed?
    • What rules apply?
    • What relationships exist among the data values?
    • What determines a complete solution? (When am I done?)
step 3 develop a high level algorithm
Step 3: Develop a high-level algorithm
  • An overview. Not detailed.
  • For example:
  • Step 1 : the problem
    • I need to send a birthday card to my brother, Mark.
  • Step 2: Analyze
    • I don’t have a card. I prefer to buy a card rather than make one myself.
  • Step 3: High Level Algorithm
    • Go to a store that sells cards
    • Select and purchase a card
    • Mail the card
high level algorithms
High-level algorithms
  • Go to a store that sells cards
  • Select and purchase a card
  • Mail the card
  • Lacks enough detail for a computer or robot to understand
  • Which store?
  • How will you get to the store? (bike, car, bus?)
  • What kind of card does Mark like? (funny, risqué, outdoorsy?)
step 4 refine the algorithm by adding detail
Step 4: Refine the algorithm by adding detail
  • Stepwise refinement= Keep adding levels of detail.
  • To know what level of detail is needed
    • You need to know how it will ultimately be implemented

Birthday card example

Who is going?

Me? Very little detail needed

Another family member? Minimal detail

Someone unfamiliar with the area? Lots of detail about directions

A robot? Minute detail.

stepwise refinement
Stepwise refinement
  • The more complex the problem, the more steps it takes to refine it to sufficient detail.
  • High Level   detailed level
  • For very large problems you go through the process many times, developing intermediate level algorithms as you go.
step 5 review
Step 5: Review
  • First: Work through the algorithm step by step and determine whether or not it actually solves the problem.
  • Then ask:
  • Does it solve a particular problem or a general one? Should it be generalized?
    • A program to find the area of a circle with radius = 5.2 could easily be generalized to find the area of any circle with the addition of a single variable.
  • Can it be simplified?
  • Is this solution similar to something already done?
a jeroo example
A Jeroo example
  • Step 1: the problem clearly defined.
  • A Jeroo starts at (0,0) facing East with no flowers in its pouch. There is a flower at location (0,3). The Jeroo should pick the flower and plant it at location (2,3) and then hop one square to the East. There are no other nets, flowers or Jeroos on the island.
analysis of the problem step 2
Analysis of the problem (step 2)
  • The flower is 3 spaces ahead of the Jeroo
  • The flower should be planted 2 spaces south of its current location
  • The Jeroo should end up at location (2,4) facing east
  • There are no obstacles to worry about

NORTH

Jeroo

flower

Start positions

high level algorithm step 3
High-Level Algorithm (step 3)

Create a Jeroo named Bob

Bob should:

Get the flower

Plant the flower

Hop East

Start positions

End positions

detailed algorithm step 4
Detailed Algorithm (step 4)
  • Create a Jeroo named Bob
  • Bob should:
    • Get the flower
      • Hop 3 times
      • Pick the flower
    • Plant the flower
      • Turn right
      • Hop 2 times
      • Plant a flower
    • Hop East
      • Turn left
      • Hop once
review step 5
Review (step 5)
  • The high-level algorithm created 3 distinct, easy sub-problems. This seems like a good technique.
  • This solves a very specific problem.
  • It actually works for any setup where the Jeroo starts anywhere and the flower is 3 spaces directly ahead of it.
good programming practices
Good programming practices

Detailed Algorithm:

  • Create a Jeroo named Bob
  • Bob should:
    • Get the flower
      • Hop 3 times
      • Pick the flower
    • Plant the flower
      • Turn right
      • Hop 2 times
      • Plant a flower
    • Hop East
      • Turn left
      • Hop once

method main()

{

Jeroo bob = new Jeroo();

// ---- Get the flower ---

// --- Plant the flower ---

// --- Hop east ---

}

Comments clearly mirror the high-level algorithm

then add detail
Then add detail

method main()

{

Jeroo bob = new Jeroo();

// ---- Get the flower ---

bob.hop(3);

bob.pick();

// --- Plant the flower ---

bob.turn(RIGHT);

bob.hop(2);

bob.plant();

// --- Hop east ---

//Etc.

}

  • Detailed Algorithm:
  • Create a Jeroo named Bob
  • Bob should:
    • Get the flower
      • Hop 3 times
      • Pick the flower
    • Plant the flower
      • Turn right
      • Hop 2 times
      • Plant a flower
    • Hop East
      • Turn left
      • Hop once