Unit 5: Day 1
Tasks
52.1a Introduce the Lists and Functions Unit
- This unit is all about Scalability and Data. We follow the following progression in high school computer science:
- Individual Variables → Lists → Objects (objects are not part of CSP but are part of the CSA course)
- All code together → Code written in simple functions → Code written in functions with parameters/arguments → Code written in functions with return values
52.2 What is Data and Why are Lists Important?
- Discuss why current variables do not work for bigger, more realistic programs
- How would you do it? Could you do it? – see next pages for scenarios
- Discuss a couple of the scenarios
- Discuss the following AP Concepts
- DAT-2.A Describe what information can be extracted from data
- DAT-2.A.1 Information is the collection of facts and patterns extracted from data.
- DAT-2.A.2 Data provide opportunities for identifying trends, making connections, and addressing problems.
- DAT-2.A.3 Digitally processed data may show correlation between variables. A correlation found in data does not necessarily indicate that a causal relationship exists. Additional research is needed to understand the exact nature of the relationship.
- DAT-2.A.4 Often, a single source does not contain the data needed to draw a conclusion. It may be necessary to combine data from a variety of sources to formulate a conclusion
- We will be looking briefly at algorithms including:
- Total and average list
- Find the highest or lowest
- Linear searching (very slow)
- Binary Searching is faster but must be on sorted data (sorting is a concept next year)
52.3 Arrays Example Zero - Wages/Shifts array
- Code sample below
- Javascript uses an ARRAY for its list data structure
- As Arrays start at ZERO in Javascript and in many other languages, we will start at example zero.
- This may be the first time your students are exposed to a FOR loop. If so, you may want to introduce it separately before using it with the List. I often do a 99 Bottles type activity before we begin using the FOR loop with lists.
- AP CSP Note: On the exam, their lists start at ONE not ZERO. This will require some clarification and review with the students closer to exam time.
- Discuss that arrays can be created in 2 ways: Empty and Full. This example focuses on empty today.
52.4 Theory Video on Algorithms Part 1
- Two great full length documentaries are included in our theory unit. I recommend showing one or both over the course of this unit (show half of one today and half next class).
- Option 1: The Secret Rules of Modern Living Algorithms
- Option 2: Big Data Revolution Documentary
- Discuss the following AP Concepts:
- DAT-2.C.2 Data sets pose challenges regardless of size, such as: the need to clean data, incomplete data, invalid data, the need to combine data sources
- DAT-2.C.3 Depending on how data were collected, they may not be uniform. For example, if users enter data into an open field, the way they choose to abbreviate, spell, or capitalize something may vary from user to user.
- DAT-2.C.4 Cleaning data is a process that makes the data uniform without changing their meaning (e.g., replacing all equivalent abbreviations, spellings, and capitalizations with the same word).
52.5 Simulations and Visualizations
- Discuss the concept of Simulations and visualizations and discuss how both were used in the above videos
- For example, how could the air traffic algorithm discussed in the video be used to simulate and make decisions about other airports
- Discuss the following AP Concepts:
- AAP-3.F.1 Simulations are abstractions of more complex objects or phenomena for a specific purpose.
- AAP-3.F.2A Simulation is a representation that uses varying sets of values to reflect the changing state of a phenomenon.
- AAP-3.F.3 Simulations often mimic real-world events with the purpose of drawing inferences, allowing investigation of a phenomenon without the constraints of the real world.
- AAP-3.F.4 The process of developing an abstract simulation involves removing specific details or simplifying functionality.
- AAP-3.F.5 Simulations can contain bias derived from the choices of real-world elements that were included or excluded.
- AAP-3.F.6 Simulations are most useful when real-world events are impractical for experiments (e.g., too big, too small, too fast, too slow, too expensive, or too dangerous).
Arrays/Lists Example Zero - Wages
let wage = 15.50;
let shifts = []; //this is how you indicate that the variable is an array
function setup() {
let sketch = createCanvas(800, 800);
sketch.parent("myP5canvas");
shifts[0] = 4; //I worked 4 hours on my first shift this pay period
shifts[1] = 8;
shifts[2] = 4;
shifts[3] = 6;
shifts[4] = 3.5;
shifts.push(5.5);
// wage = window.prompt("What is your hourly wage?");
print("How much did I earn each shift?");
for(let i=0; i<shifts.length; i++){
print("$" + (shifts[i]*wage));
}
//Oops, you made a mistake
shifts[1] = 7;
//how to print 2 decimal places
print("Updated Earnings")
for(let i=0; i<shifts.length; i++){
print("$" + (shifts[i]*wage).toFixed(2));
}
}//end setup
function draw() {
background(200, 50, 50);
text("see console", 50,50);
}//end draw
Scenario Questions
- You are the statistician for the NBA. You want to store all the players’ names, teams, points, rebounds, assists, etc and be able to display them in a nice looking table. How would you do it? Could you do it? If not, why not?
- You want to set up a clothing store. You sell 20 items with several sizes and colours for each. You want your customer to be able to request an item, check and then update the inventory for the next customer. How would you do it? Could you do it? If not, why not?
- You want to create a family tree program. For each person, you want to store their name, birth and death year, parents and children and a few other facts. Your long term plans are to use Swing to draw all the connections between parents and children. How would you do it? Could you do it? If not, why not?
- You are running a large music festival. You want to store all the band names and all the people who play each instrument in each band. Your goal is to say I want to know the Maroon 5’s drummer’s name so that you can pay them. How would you do it? Could you do it? If not, why not?
Continue to Unit 5: Day 2 »