Download presentation
Presentation is loading. Please wait.
Published byBenedict Lewis Modified over 9 years ago
1
Introduction to Algorithms Engineering 1D04, Teaching Session 1
2
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng1 Introductions
3
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng2 Course Webpage: http://elm.mcmaster.ca/
4
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng3 Introduction to Algorithms Problems require solutions. The solution to a problem must be stated clearly. A clear sequence of steps for solving a specific problem is called an algorithm.
5
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng4 Introduction to Algorithms Task 1 Get into groups of 4 and create an algorithm to safely cross a road. Try to be as precise as possible. Some groups will get to share their algorithms.
6
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng5 Task 1 Problems The order in which tasks are performed is often not obvious. The individual steps themselves are often ambiguous. Often, the chicken never gets across the road. It would be nice to have a more formal way of describing the actions involved in performing a task.
7
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng6 Waking up!! Get Out of Bed Brush Teeth Eat Breakfast Brush Teeth Again Wash Get Dressed Put on Shoes Run to Catch Bus
8
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng7 Get Out of Bed Start Brush Teeth WashGet Dressed Eat BreakfastBrush TeethRun to Catch Bus Put on Shoes Finish Start / Stop Box Statement Box Waking in the Morning
9
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng8 Start / Stop Box Statement Box Flowchart Elements
10
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng9 Waking up!! Unfortunately, we are not all that organized. We can’t all have such a structured morning experience.
11
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng10 Waking up!! Unfortunately, we are not all that organized. We can’t all have such a structured morning experience. What if we’re short on time? Does this change our decision making process?
12
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng11 Start / Stop Box Decision Box Statement Box Flowchart Elements
13
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng12 Decision Box Are you hungry? Yes No Eat breakfast Catch bus Decision Box
14
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng13 Get Out of Bed Start Brush Teeth WashGet Dressed Eat BreakfastBrush TeethRun to Catch Bus Put on Shoes Finish Is There Extra Time? Yes No Waking in the Morning with Decision
15
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng14 Waking in the Morning with Decision Get Out of Bed Brush Teeth If There is Extra Time Eat Breakfast Brush Teeth (Again) Wash Get Dressed Put on Shoes Run to Catch Bus
16
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng15 Crossing the Road Some tasks need to be repeated until a condition is satisfied. Walking can be described as move left foot forward, move right foot forward, left foot, right foot …. This can be visualized by a loop in the flowchart.
17
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng16 Move Left Foot Forward Move Right Foot Forward Are you on the other side? Yes No Finish … Crossing the Road
18
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng17 Crossing the Road … While you’re not on the other side Move Left Foot Forward Move Right Foot Forward
19
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng18 Introduction to Algorithms Task 2 Return to your groups. Make a flowchart for safely crossing a road and derive a natural language description from it. Be as detailed as possible. Compare it to your previous natural language description.
20
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng19 Algorithms What are the most important characteristics of an algorithm?
21
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng20 Algorithms What are the most important characteristics of an algorithm? A step-by-step procedure for solving a problem Finite number of steps Depends only on input
22
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng21 Algorithms Need only: sequential actions decisions “while” loops (iteration) Anything that is computable can be computed using just these control structures
23
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng22 A More Mathematical Example Let’s try an algorithm that is more mathematical Do these two lines intersect? Line 1: (x 1, y 1 ) (x 2, y 2 ) Line 2:(u 1, v 1 ) (u 2, v 2 ) (same groups - work it out)
24
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng23 Intersecting Lines
25
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng24 Intersecting Lines What problems will you face?
26
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng25 Intersecting Lines Work on the problem between now and Lab 2 - you will need to solve this in that lab session.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.