Bubble Sort - kimschles/schlesinger-knowledge GitHub Wiki

Learning Objectives

By the end of the session you will be able to:

  1. Define the term algorithm in your own words

  2. Describe the step-by-step process the bubble sort algorithm uses to sort a list

  3. Write an expression that describes the maximum number of passes the bubble sort algorithm makes while sorting a list

The Numbers
Time: 30 minutes

Number of Students: 80 students 15 legislators

Number of Learning Facilitators: 7 Galvanize Instructors: Sarah, Teddi, Mairin, Anna, Dize, Kim and Martha

? Galvanize Staff Members

Objective Introductions and Framing
Time 5 minutes Introduce Galvanize Instructors

Computers can’t do anything without you Being a Computer scientists, software engineers, or web developers is a job you could do. Computer science is approachable

Objective Define the term algorithm in your own words
Time 5 minutes
Activity Algorithms, and algorithmic thinking, is something we all use in our regular lives. An algorithm is a step-by-step procedure for accomplishing a task.

Example of a non-CS algorithm: Making a Peanut Butter and Jelly Sandwich Step 1: Assemble the ingredients: bread, peanut butter, jelly Step 2: Get the kitchen items you need: a plate, a knife, a towel Step 3: Get two pieces of bread Etc….

Discussion Question: What are some other step-by-step processes, or algorithms you use?

(Have participants turn and talk to their neighbor. After enough processing time, cold call on 3-4 students to hear different answers)

Discussion Question: Turn and talk to your neighbor, and explain the term algorithm in your own words.

Assessment Write down your definition of the term algorithm on your worksheet.
Exemplar Response An algorithm is a step-by-step procedure for accomplishing a task.
Objective Describe the step-by-step process the bubble sort algorithm uses to sort a list
Time 10 minutes
Activity Humans rely on algorithmic thinking to get things done, and computers do, too.

As a software engineer, you will write code that sorts lists. Today, we are going to learn one of many algorithms that can sort a list of numbers from smallest to largest. The sorting algorithm we are learning today is called ‘Bubble Sort.’

Computers are very literal, and we have to tell them every step to take like the PB&J exercise. So, let’s see how each step Bubble Sort works.

Whole Group Demonstration and Think-Aloud: (Five adults will act out the bubble sort: 4 people holding numbers, and 1 acting as the computer program. One instructor will model and ‘think aloud’ each step)

[7,10, 8, 1] (Note, the order matters for the demo to show 3 different passes)

Step 1: Start at the left side of the list, and compare the first and second numbers. If the two numbers are not in order from smallest to largest, switch the numbers. If they are in order, leave the numbers as they are.

Step 2: Move to the second number in the list. Compare the second and third numbers. If the numbers are not in order from smallest to largest, switch the numbers. If they are in order, leave the numbers as they are.

Step 3: Repeat this process until you’ve evaluated every number in the list.

Step 4: Look at the list. Is it sorted correctly? If not yet, do another ‘pass,’ and continue the list is sorted correctly.

Key Term: Pass- when you’ve evaluated every item in the list.

Small Group Problem Solving: The students will break into small groups led by a Galvanize Instructor. Each group will have a set of numbers printed on individual sheets of paper. The instructor should help organize the girls so that they can

Note: The most important part of the small group activity is that each girl has an opportunity to explain the step-by-step process in their own words. Please ensure that you leave enough time for the students to talk this through with one or two other students.

If you have extra time, please have the students think about this question: Why do you think the algorithm is called Bubble Sort?

Answer: The largest numbers eventually ‘bubble up’ to the right of the list.

Assessment In your own words, describe the step-by-step process the bubble sort algorithm uses to sort a list
Exemplar Response Step 1: Start at the left side of the list, and compare the first and second numbers. If the two numbers are not in order from smallest to largest, switch the numbers. If they are in order, leave the numbers as they are.

Step 2: Move to the second number in the list. Compare the second and third numbers. If the numbers are not in order from smallest to largest, switch the numbers. If they are in order, leave the numbers as they are.

Step 3: Repeat this process until you’ve evaluated every number in the list.

Step 4: Look at the list. Is it sorted correctly? If not yet, do another ‘pass,’ and continue the list is sorted correctly.

Objective Write an expression that describes the maximum number of passes the bubble sort algorithm makes while sorting a list
Time 5 minutes
Activity Small Group Activity : Every group should pick three numbers to make up their ‘experiment’ list. The girls should experiment with the lists and find the maximum number of passes. Feel free to have the young women ‘act out’ bubble sort, or do it on paper.

[1,2,3] [2,3,1] [3,2,1]

Answer: The edge case is if the smallest number is in the last position in the list. In the event this is true, the number of passes is n-1

Assessment Write an expression that describes the maximum number of passes the bubble sort algorithm makes while sorting a list.
Exemplar Response n-1 (Note: n = the number of items in the list)
Objective Wrap Up & Reflection
Time 5 minutes
Activity What is one thing you know now that you didn’t know before we started? What are you curious about? What will you google the next time you’re at a computer? List of resources
⚠️ **GitHub.com Fallback** ⚠️