1 / 17

New Mexico Computer Science For All

New Mexico Computer Science For All. More Algorithms Maureen Psaila-Dombrowski. Algorithms. Algorithm : A set of instructions that can be used repeatedly to solve a problem or complete a task . As you problem grows, the need for a good algorithm grows

keola
Download Presentation

New Mexico Computer Science For All

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. New Mexico Computer Science For All More Algorithms Maureen Psaila-Dombrowski

  2. Algorithms • Algorithm: A set of instructions that can be used repeatedly to solve a problem or complete a task. • As you problem grows, the need for a good algorithm grows • Need a systematic way to solve the problem • Two Problems • Counting • Mazes

  3. Counting • Something we all know about • Three counting problems • Students in your class • Students in your school • High school students in your state

  4. Count Students in Class • Easy • Teacher can count • Students can count off • Pseudocode set ClassCountto 0 while (students left in class to count) set ClassCountto ClassCount+ 1

  5. Count Students in School • Harder • One possible method – “Brute Force” • Gather the students • Line them up • Count them • Have someone count the • Have them count off • Another method – Divide and Conquer (algorithmic principle, break the problem into smaller pieces and then solve) • Leave students in classrooms • Have each classroom count their students (ClassCount) • Add up the students from classroom (SchoolCount)

  6. Pseudocode: Count Students in School In each classroom set ClassCountto 0 while (students left in class to count) set ClassCountto ClassCount+ 1 For the school set SchoolCount to 0 while (still classrooms left to count) go to each classroom ask number of student in class (ClassCount) set SchoolCount = SchoolCount + ClassCount

  7. High School Students in State • Even Harder • Can’t line them up • Divide and Conquer • Have each School count their students • At each school • Leave students in classrooms • Have each classroom count their students • Add up the students from each classroom (ClassCount) • Have the schools report their student numbers (SchoolCount) • Add up all the School’s student numbers to get the number of high school students in the state (StateCount)

  8. Pseudocode: Count Students in State In each classroom in each school set ClassCount to 0 while (students left in class to count) set ClassCount to ClassCount + 1 For the school set SchoolCount to 0 while (still classrooms left to count) go to each classroom ask number of student in class (ClassCount) set SchoolCount = SchoolCount + ClassCount For the state set StateCountto 0 while (still schools left to count) go to each school ask number of student in school (SchoolCount) set StateCount= StateCount+ SchoolCount

  9. Mazes Easy - Don’t need an algorithm

  10. Mazes Perhaps you need an algorithm (systematic approach) for this one

  11. Mazes – Two Approaches • Wall Following • Good if you can’t see the whole maze • Works on simply connected mazes • Pick a wall (right or left) and keep following it – never change

  12. Mazes – Two Approaches • Wall Following Pseudocode (left wall following) Find the nearest wall on the left Turn left if you can and move forward If you can’t turn left Move forward if you can If you can’t move forward Turn right and move forward

  13. Left Wall Following Video Reference: ‪AloucasHellas. (2013, October 10). Maze Solving Algorithms: Left Hand Rule (LHR)[Video file]. Retrieved from http://www.youtube.com/watch?v=NA137qGmz4s

  14. Mazes – Two Approaches • Dead End Filling • Good if you CAN see the whole maze • Find all the dead ends and fill them in • Works if there are dead ends Find All the Dead Ends Fill Them In Maze

  15. Mazes – Two Approaches • Dead End Filling Pseudocode: Find dead ends Scan the maze Identify dead end (walls on 3 sides) Remember the dead ends Fill in the dead ends Go to dead end While not at junction (walls on 2 sides) Fill in maze Solution is left – solve maze!

  16. Dead End Filling Video Reference: ‪Mazemaster225. (2013, October 10). Maze Strategy: Dead End Filling.[Video file]. Retrieved from http://www.youtube.com/watch?v=yqZDYcpCGAI

  17. Summary • Algorithm: A set of instructions that can be used repeatedly to solve a problem or complete a task. • The bigger the problem the more you need a systematic way to solve the problem • Two Problems • Counting • Divide and Conquer: Algorithmic principle • Mazes • Wall Following • Dead End Filling

More Related