announcements
DESCRIPTION
Announcements. MyITLab Access assessments have been extended to Nov 8… that’s it! We have some programming chapters coming up that blast through the material at lighting speed Let us slow down this week and examine the basics in detail. This week…. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/1.jpg)
MyITLab Access assessments have been extended to Nov 8… that’s it!
We have some programming chapters coming up that blast through the material at lighting speed
Let us slow down this week and examine the basics in detail
![Page 2: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/2.jpg)
Today, Wednesday: Algorithms, Pseudo-code and Flowcharts
Wednesday, FridayIntro to programming with JavaScript
![Page 3: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/3.jpg)
Algorithms exist outside the world of computers.
Think back to when you were little…
What was thefirst algorithm
that you learned?
![Page 4: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/4.jpg)
Tying your shoes Opening a door Going down the stairs Cooking Kraft Dinner Parallel Parking a car Landing an aircraft
![Page 5: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/5.jpg)
An algorithm is a sequence of steps that describe the solution to a problem.
Building a fence constructing a building Cooking your lunch
![Page 6: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/6.jpg)
In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing. It is formally a type of effective method in which a list of well-defined instructions for completing a task will, when given an initial state, proceed through a well-defined series of successive states, eventually terminating in an end-state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as probabilistic algorithms, incorporate randomness.
![Page 7: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/7.jpg)
Finite Finite number of steps Finite amount of time to execute the steps
Ordered sequence There is a first step Each step has a unique next step
Unambiguous Each step is understandable by executor Each step has only one interpretation
![Page 8: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/8.jpg)
Pre-conditions Post-conditions Inputs Outputs Start End Steps Decisions
![Page 9: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/9.jpg)
Pre-conditions are those things that must exist before we can ‘start’.
We might require certain ‘inputs’ to be present.
Example: KD requires milk, butter, pot, water, heat
![Page 10: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/10.jpg)
Post-conditions is what we expect when everything is done.
It encompasses the ‘world’ of the algorithm when it has successfully ended.
Example:Do we have a fine KD meal?Yes if we follow the recipe from start to end!
![Page 11: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/11.jpg)
Algorithms should fully describe every step from beginning to end.
It should describe what inputs are being modified and how.
Sometimes we need to make a decision (is the water boiling? No, wait another minute…)
Note: Even KD will taste badly if we boil the water, cheese, milk and butter and forget to add the noodles at the proper time.
![Page 12: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/12.jpg)
In life, we frequently find multiple methods of solving a particular problem.
How do we know if one sequence of steps is faster than another?
We could time it! Several times under various conditions just to
be sure.
But do we track the:a. Best time? b. Worst time?? c. Average time???
![Page 13: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/13.jpg)
A math term that describes the worst case scenario of an algorithm.
Why WORST CASE and not BEST CASE?1. Most algorithms give great results under ideal
situations.2. We only see an advantage under poor
conditions.
![Page 14: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/14.jpg)
SEQUENTIAL1..10 DIVIDE AND
CONQUER 1..10 3 9 1 … 6
Guaranteedwithin 10Guesses
O(n)
>5 <8 >6 If yes, it is
7 otherwise the number was 6.
O(log n)
1 2 3 … 10
Guaranteed
within 10Guesses
O(n)
RANDOM1..10
![Page 15: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/15.jpg)
Scales to larger input values extremely well. Twisting the equation around, we get the following:
2x = nwhere x=number of guesses to find n
In reality, we have a 50/50 chance on the last guestion meaning sometimes we need 1 more to have the answer.
Some examples:2^4 = 16 which means 1..16 within 4+1 guestions.2^10 = 1024 2^20 = 1 million
(We can guess any number from 1 to 1 million in 20+1 guestions!! Wow, bet a friend, loser buys a pizza)
![Page 16: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/16.jpg)
1) > 500,000 no2) > 250,000 yes3) > 375,000 no4) > 312,500 no5) > 281,250 no6) > 265,625 no7) > 257,813 no8) > 253,907 yes9) > 255,860 no10) > 254,884 no
11)> 254,396 no12)> 254,152 no13)> 254,030 no14)> 253,969 yes15)> 254,000 no16)> 253,985 no17)> 253,977 no18)> 253,973 no19)> 253,975 no20)> 253,974 no
21) Is the number 253, 974?If the reply is no, we know that the number is: 253,973
![Page 17: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/17.jpg)
A method of describing the steps of an algorithm using english-like sentences.
May contain formulae when necessary to explain the details
Not unlike a ‘recipe’ A programmer can read the pseudocode
and create a program
![Page 18: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/18.jpg)
What’s wrong with this set of instructions (found on a shampoo bottle)?
LatherRinseRepeat
Is This better?
Wet hair.Repeat 2 times.
Apply shampoo.Rinse.
Dry hair.
![Page 19: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/19.jpg)
Going from WLU to Rogers Centre (Toronto):1. Exit UW campus on south side (University Ave W) 2. Head southwest from University Ave W -
go 1.3 km 3. Turn left at ERB St W - go 1.6 km Yes, Google
suggests this route!4. Turn right at King St S - go 13.5 km5. Take the HWY-401 E ramp - go 66 km6. Bear right at HWY-401 Collectors E towards
Dixie Road - go 6.5 km7. Take the HWY-427 S towards Q.E.W. - go 7.7 km8. Take the Gardiner Expy E - go 13.6 km9. Take the Spadina Ave exit - go 0.9 km10. Turn right at Blue Jays Way - go 0.1 km
![Page 20: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/20.jpg)
![Page 21: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/21.jpg)
Sample problem: given a group of people, find who is the tallest.
for any one person in the group get persons_name get persons_height name_so_far persons_name tallest_so_far persons_heightend for this personrepeat for each remaining person in the group get persons_name get persons_height if persons_height > tallest_so_far then // this
person is taller name_so_far persons_name tallest_so_far persons_heightend of repetitiondisplay name_so_far " is the tallest, with height "
tallest_so_far
Sample problem: given a group of people, find who is the tallest.
for any one person in the group get persons_name get persons_height name_so_far persons_name tallest_so_far persons_heightend for this personrepeat for each remaining person in the group get persons_name get persons_height if persons_height > tallest_so_far then // this
person is taller name_so_far persons_name tallest_so_far persons_heightend of repetitiondisplay name_so_far " is the tallest, with height "
tallest_so_far
![Page 22: Announcements](https://reader036.vdocument.in/reader036/viewer/2022081519/56813507550346895d9c5617/html5/thumbnails/22.jpg)
Flowcharts visually describe an algorithm