Introduction to Computational Thinking Variables State Construct algorithms
Introduction to Computational Thinking Variables & State Construct algorithms in an informal language Identify the variables used in the algorithm Identify a state during the performance of the algorithm Explain the importance of precision in algorithms (C) Dennis Kafura 1
CT@VT Work for today … n n n Write an algorithm for the first card problem distributed to your cohort (15 minutes) “Robot” execution and discussion (15 minutes) Write an algorithm for the second card problem distributed to your cohort (15 minutes) “Robot” execution and discussion (15 minutes) Review of variables and state (C) Dennis Kafura Slide 2
CT@VT Role of Variables (dynamic) (C) Dennis Kafura (static) Slide 3
CT@VT Variable n n A property refers to information used in an abstraction A variable refers to information used by an algorithm Property Variable Has a name? Yes Has a value? Yes Has a type? Yes Change value? No Yes (C) Dennis Kafura Slide 4
CT@VT Variables in the Maze n Algorithms The maze algorithm implicitly uses variables to denote the position of the avatar in the maze q q Location (where it is in the maze: grid number) Heading (which way it is facing: compass direction) North West Variables for the Avatar 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 East South Location Heading Value of each variable (C) Dennis Kafura Slide 5
CT@VT During execution -1 (C) Dennis Kafura Location Heading 1 East Slide 6
CT@VT During execution -2 Location 2 (C) Dennis Kafura Heading East Slide 7
CT@VT During execution -3 (C) Dennis Kafura Location Heading 6 South Slide 8
CT@VT During execution -4 (C) Dennis Kafura Location Heading 8 North Slide 9
CT@VT n State q q n the value of all variable at a give point in the execution of the algorithm changes as the algorithm is executed (performed) only one state exists at a time; previous states forgotten variables are stored in a computer’s memory History q q record of all of the sequence of states useful in understanding and explaining the execution of an algorithm (C) Dennis Kafura Slide 10
- Slides: 10