Manipulating an Abstraction (Iteration) CT @ VT An algorithm with - - PowerPoint PPT Presentation

manipulating an abstraction iteration
SMART_READER_LITE
LIVE PREVIEW

Manipulating an Abstraction (Iteration) CT @ VT An algorithm with - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

Introduction to Computational Thinking

Manipulating an Abstraction (Iteration)

slide-2
SLIDE 2

CT@VT An algorithm with iteration

Slide 2 Fall 201 2015

for each BOOK in BOOK LIST START BOOK LIST = get all books TOTAL = 0 TOTAL = TOTAL + current BOOK’s price END print TOTAL grab next book no more books

slide-3
SLIDE 3

CT@VT Combining iteration and decision

Slide 3 Fall 201 2015

for each BOOK in BOOK LIST START BOOK LIST = get all books TOTAL = 0 TOTAL = TOTAL + current BOOK’s price END print TOTAL grab next book no more books false true BOOK’s price > $40

slide-4
SLIDE 4

CT@VT Abstraction and Big Data

 Abstraction identifies the properties of interest

  • f 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:

Slide 4 Fall 201 2015

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

slide-5
SLIDE 5

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

Slide 5 Fall 201 2015

 If it works for a

few items it will work for millions

  • f items!!

AKA: looping, repetition

slide-6
SLIDE 6

CT@VT Example

 Temperature abstraction  Temperature data set

Slide 6 Fall 201 2015 City: State: Temperature: City: Los Angeles State: CA Temperature: 100 City: Ames State: IA Temperature: 65 City: Blacksburg State: VA Temperature: 77 City: New York State: NY Temperature: 86 City: Miami State: FL Temperature: 89

 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

slide-7
SLIDE 7

CT@VT Flowchart

Slide 7 Fall 201 2015

statements

for each element

City: Blacksburg State: VA Temperature: 77 City: New York State: NY Temperature: 86 City: Miami State: FL Temperature: 89

slide-8
SLIDE 8

CT@VT Example

Slide 8 Fall 201 2015 City: Los Angeles State: CA Temperature: 100 City: Ames State: IA Temperature: 65 City: Blacksburg State: VA Temperature: 77 City: New York State: NY Temperature: 86 City: Miami State: FL Temperature: 89

Find the total

  • f all of the

temperatures

slide-9
SLIDE 9

CT@VT Example

Slide 9 Fall 201 2015 City: Los Angeles State: CA Temperature: 100 City: Ames State: IA Temperature: 65 City: Blacksburg State: VA Temperature: 77 City: New York State: NY Temperature: 86 City: Miami State: FL Temperature: 89

Find the total number of temperatures

slide-10
SLIDE 10

CT@VT Combining iterations

Slide 10 Fall 201 2015

Find the average temperature: average = total/number Iterate to find total Iterate to find number

slide-11
SLIDE 11

CT@VT Combining iterations

Slide 11 Fall 201 2015

Find the average temperature: average = total/number

  • ne iteration

combine steps

slide-12
SLIDE 12

CT@VT Iteration and Decision

Slide 12 Fall 201 2015

Find the maximum temperature. set current-max 0 for each city [ if temp > current-max [ set current-max temp ] ]

slide-13
SLIDE 13

CT@VT Next steps today

 Work on the iteration problems in your

cohort

 Exchange algorithms for problem 2  Cohort feedback/reports  Discussion

Slide 13 Fall 201 2015