1 / 12

Algorithms

Algorithms. By Tanya Duffy. What are Algorithms?. Describe step by step how to solve a problem Represented by Pseudo code or Flowcharts Pseudo code uses English & some keywords Flowcharts are diagrams using lines and arrows to elements. Terminator. Process. Decision. Subprogram.

pia
Download Presentation

Algorithms

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithms By Tanya Duffy

  2. What are Algorithms? • Describe step by step how to solve a problem • Represented by Pseudo code or Flowcharts • Pseudo code uses English & some keywords • Flowcharts are diagrams using lines and arrows to elements Terminator Process Decision Subprogram

  3. Four Programming Structures • Sequence • Selection • Repetition • Subprograms

  4. Sequence Flowchart BEGIN Pseudocode BEGIN Fill a kettle with water Boil the water in the kettle Put the tea leaves in the pot Pour boiling water in the pot END Problem: Write a set of instructions that describe how to make a pot of tea Fill a kettle with water Boil the water in the kettle Put the tea leaves in the pot Pour the boiling water in the pot END

  5. Selection Pseudocode BEGIN IF the telephone is ringing THEN Answer the telephone END IF END BEGIN Problem 1: Write a set of instructions to describe when to answer the phone. The telephone is ringing False True Answer the telephone END

  6. Selection Flowchart BEGIN Problem 2: Write a set of instructions to follow when approaching a set of traffic control lights Pseudocode BEGIN IF the signal is green THEN proceed through the intersection ELSE Stop the vehicle ENDIF END The signal is green False True Stop the vehicle Proceed through the intersection END

  7. Selection BEGIN Problem 3: Write a set of instructions that describes how to respond to all possible signals at a set of traffic control lights. Signal is Pseudocode BEGIN CASEWHERE signal is red : stop the vehicle amber : stop the vehicle green : proceed through the intersection OTHERWISE : proceed with caution ENDCASE END red amber green otherwise Stop the vehicle Stop the vehicle Proceed through the intersection Proceed with caution END

  8. Repetition BEGIN Pseudocode BEGIN WHILE the train is moving keep wholly within the carriage ENDWHILE END PRE-TEST Problem: Determine a safety procedure for travelling in a carriage on a moving train The train is moving False True Keep wholly within the carriage END

  9. Repetition BEGIN Pseudocode BEGIN REPEAT beat the egg whites UNTIL fluffy END POST-TEST Problem: Determine a procedure to beat egg whites until fluffy Beat the egg whites Egg whites fluffy False True END

  10. Subprograms Guess the Number Problem In a simple number game your opponent thinks of a secret number between 1 and 100. In no more than 10 guesses you have to try to guess the number. After each guess your opponent tells you if your guess was too high, too low or correct. Your opponent also keeps track of how many guesses you have had and tells you the game is over when you use all of your ten guesses or when you guess the number correctly. Describe an algorithm which takes the role of your opponent in this game. Include in your solution a subprogram which checks for illegal guesses (those less than 1 or greater than 100). Include also the subprogram which generates a secret number between 1 and 100. Do not expand this but assume it is available.

  11. Solving a Maze Getting a robot or a computer to find its own way through a maze is not easy. There are problems in detecting the walls to avoid collisions, problems in getting out of “dead-ends”, problems in avoiding logic traps where the computer or robot is simply unable to progress any further… For a human who can see the entire maze, the answer is easy!! But if you were a robot who could only see just 1 square directly ahead, how could you get HOME?

  12. Pseudocode • Very precise form of written instructions • Layout and words follow set rules • KEYWORDS always written in UPERCASE letters • All but simplest pseudo code algorithms split into several separate lists called Sub Programs

More Related