Full teaching narration is free with Private Starter.Create free account
Back to curriculum
Computer ScienceGrade 4· U.S. National — Common Core & NGSS
Aligned to:U.S. educational frameworks

Design and Debug a Classroom Voting Algorithm

Students create, test, and revise a step-by-step algorithm for collecting votes, counting results, and resolving errors fairly.

Design and Debug a Classroom Voting Algorithm

Illustrations are auto-generated and may be placeholders. They can be refreshed to match the narration.

Full teaching narration is included free with a Private Starter account.Create free account

What Is an Algorithm?

An algorithm is an ordered set of steps for completing a task or solving a problem. The steps should be clear enough that another person can follow them and get the expected result. For example, a class might vote between a nature documentary and a space documentary. A simple voting algorithm could tell each student to mark one choice, place the ballot in a box, and wait while two students count the votes. Order matters. Counting before all ballots are collected could produce an incorrect result. Algorithms can also include decisions. If a ballot has two choices marked, the algorithm must explain what to do. People design algorithms, test them, find problems, and improve them. A classroom voting algorithm should produce an accurate result while treating every voter and every choice fairly.

A voting flow diagram shows a student marking a ballot, placing it in a box, and counters checking a ballot with two marks.
A voting flow diagram shows a student marking a ballot, placing it in a box, and counters checking a ballot with two marks.Source: Illustrated for this lesson

Outline the Voting Steps

Before voting begins, write the steps so everyone understands the process. First, list the choices using the same size print and amount of information. Next, prepare one identical ballot for each eligible student. Explain that each student may mark only one choice. Have students vote privately and place their ballots in the same sealed box. Record the number of students who received ballots. After voting ends, open the box with two counters present. Sort the ballots by choice, count each group, and compare the total number of ballots with the number distributed. For example, if 24 students receive ballots, the box should contain 24 ballots. Finally, announce the totals and follow an agreed rule for a tie, such as holding a new vote between the tied choices.

A classroom voting plan shows equal ballots going into a sealed box before two counters count and check for a tie.
A classroom voting plan shows equal ballots going into a sealed box before two counters count and check for a tie.Source: Illustrated for this lesson

Run the Algorithm

Run the algorithm as a test before using it for an important class decision. Choose a small sample question, such as whether to use red or blue paper for a display. Keep important conditions controlled: give each tester one ballot, use the same ballot box, provide the same directions, and allow the same voting time. Assign students different roles, including voters, ballot distributor, observers, and two counters. As the test runs, observers should record what actually happens without changing the steps. Suppose 10 students receive ballots, but the counters find only 9 in the box. Do not guess the result. Pause and identify where the missing ballot could have been lost. A test helps reveal failure points while the consequences are small. Record vote totals, unusual events, questions, and any steps that caused confusion.

A practice vote shows observers recording that ten ballots were given out but only nine were found in the box.
A practice vote shows observers recording that ten ballots were given out but only nine were found in the box.Source: Illustrated for this lesson

Find Bugs and Unfair Steps

A bug is a mistake or unclear part of an algorithm that can lead to the wrong result. Review the test record and examine each failure point. A missing ballot, a ballot counted twice, unclear marks, or incorrect addition can reduce accuracy. Also look for unfair steps. For example, showing one choice in large colorful letters and another in small plain letters may influence voters. Letting some students vote twice gives them more power than others. Discuss each problem calmly and use evidence from the test instead of blaming a person. Ask whether every eligible voter had one equal opportunity, whether choices were presented neutrally, and whether the count could be checked. Classify each issue as an accuracy bug, a fairness problem, or both. Then decide which problem must be fixed before the algorithm is used again.

A review board sorts voting issues into accuracy bugs, fairness problems, and problems that fit both groups.
A review board sorts voting issues into accuracy bugs, fairness problems, and problems that fit both groups.Source: Illustrated for this lesson

Revise and Retest

Revise the algorithm by replacing unclear or faulty steps with precise directions. If ballots went missing, add a step requiring the distributor to count unused ballots and compare that number with the ballots collected. If marks were hard to understand, add boxes beside each choice and show one neutral example of a valid mark. If addition errors occurred, require two counters to count separately and compare totals. Then retest with the same number of voters and the same choices used in the first test. Keeping these variables the same makes it easier to tell whether the revision worked. For example, if the first test distributed 10 ballots but found only 9, the revised test succeeds when all 10 are accounted for. If another problem appears, revise and test again. Persevering through repeated tests is part of designing a dependable algorithm.

A revised voting process shows unused ballots checked, a valid mark demonstrated, and two separate counts compared during a retest.
A revised voting process shows unused ballots checked, a valid mark demonstrated, and two separate counts compared during a retest.Source: Illustrated for this lesson

Reflect on Accuracy and Fairness

After retesting, decide whether the algorithm is ready by examining evidence. Accuracy means the recorded totals match the valid ballots and the arithmetic is correct. Fairness means each eligible student has an equal chance to vote, choices are presented neutrally, privacy is protected, and the same rules apply to everyone. Write a short explanation of the final algorithm, including the ordered steps, the bugs discovered, the revisions made, and the test results. For example, explain that separate counts by two students both produced 12 votes for Choice A and 11 for Choice B. Then hold a class discussion in which students listen, ask questions, and support claims with evidence. The class might agree to use the algorithm, request another test, or suggest one more revision. A careful group decision values both a correct count and respectful treatment of every voter.

A final review compares matching vote totals with a checklist for equal opportunity, neutral choices, and private voting.
A final review compares matching vote totals with a checklist for equal opportunity, neutral choices, and private voting.Source: Illustrated for this lesson