Introduction to Computational Thinking Manipulating an Abstraction (Iteration)
CT @ VT An algorithm with iteration START BOOK LIST = get all books TOTAL = 0 for each BOOK grab next book in BOOK LIST no more books TOTAL = TOTAL + current BOOK’s price print TOTAL END Fall 201 2015 Slide 2
CT @ VT Combining iteration and decision START BOOK LIST = get all books TOTAL = 0 for each BOOK in grab next book BOOK LIST true no more books BOOK’s price > $40 false print TOTAL TOTAL = TOTAL + current BOOK’s price END Fall 201 2015 Slide 3
CT @ VT Abstraction and Big Data Abstraction identifies the properties of interest of some kind of artifact (books, people, …) We are not interested in the abstraction of a single instance (one book, one person,…) but a large number of instances of that kind Examples: Big Data set … each instance has… All Books on Amazon Author, title, price All Movies on NetFlix Title, rating, length All Stocks on NYSE Name, price, date, time All Temperatures in US City, state, temperature Fall 201 2015 Slide 4
CT @ VT Iteration and Big Data Definition repeatedly executing a set of statements where some data is different on each execution until a condition changes If it works for a few items it will work for millions of items!! AKA: looping, repetition Fall 201 2015 Slide 5
CT @ VT Example City: Temperature abstraction State: Temperature: Temperature data set City: Miami City: New York City: Blacksburg City: Los Angeles City: Ames State: FL State: NY State: VA State: CA State: IA Temperature: 89 Temperature: 86 Temperature: 77 Temperature: 100 Temperature: 65 Iteration can be used to process a data set Each element is processed once Each iteration applies the statements to the “current” element The iteration continues as long as there are more elements remaining that have not been processed Fall 201 2015 Slide 6
CT @ VT Flowchart City: Miami City: New York City: Blacksburg State: FL State: NY State: VA Temperature: 89 Temperature: 86 Temperature: 77 for each element statements Fall 201 2015 Slide 7
CT @ VT Example City: Miami City: New York City: Blacksburg City: Los Angeles City: Ames State: FL State: NY State: VA State: CA State: IA Temperature: 89 Temperature: 86 Temperature: 77 Temperature: 100 Temperature: 65 Find the total of all of the temperatures Fall 201 2015 Slide 8
CT @ VT Example City: Miami City: New York City: Blacksburg City: Los Angeles City: Ames State: FL State: NY State: VA State: CA State: IA Temperature: 89 Temperature: 86 Temperature: 77 Temperature: 100 Temperature: 65 Find the total number of temperatures Fall 201 2015 Slide 9
CT @ VT Combining iterations Find the average temperature: average = total/number Iterate to find total Iterate to find number Fall 201 2015 Slide 10
CT @ VT Combining iterations Find the average temperature: average = total/number combine steps one iteration Fall 201 2015 Slide 11
CT @ VT Iteration and Decision Find the maximum temperature. set current-max 0 for each city [ if temp > current-max [ set current-max temp ] ] Fall 201 2015 Slide 12
CT @ VT Next steps today Work on the iteration problems in your cohort Exchange algorithms for problem 2 Cohort feedback/reports Discussion Fall 201 2015 Slide 13
Recommend
More recommend