Pathfinding Algorithms and Facial Scanning

How does code relate to real-life scenarios and social implications of computing?

When to Use This Extra

This lesson primarily focuses on social implications, but it does require some light understanding of code. It is best used anytime after Unit 1, when you feel your students need a brief break from writing code to instead think about it critically.

Overview

In this lesson, students will begin by considering different algorithms for pathfinding by looking at their pseudocode and creating code summaries of these classic algorithms. They will then brainstorm what โ€˜costโ€™ could mean in a pathfinding algorithm beyond just distance and will consider technological implications to move around the city. Finally, students will rewrite the A* Algorithm based on contemporary technological concerns.

Objectives

Students will be able toโ€ฆ

  • Verbalize the generalization between Dijkstraโ€™s Algorithm and the A* Pathfinding Algorithm

  • Determine cost in a pathfinding algorithm

  • Discuss how surveillance technology and other obstacles could affect the โ€˜costโ€™ of a path or route.

Suggested Duration

~1 - 2 Periods (45 - 90 minutes)

NYS Standards

9-12.IC.1 Evaluate the impact of computing technologies on equity, access, and influence in a global society.

9-12.IC.5 Describe ways that complex computer systems can be designed for inclusivity and to mitigate unintended consequences.

9-12.CT.6 Demonstrate how at least two classic algorithms work and analyze the trade-offs related to two or more algorithms for completing the same task.

Vocabulary

  • Pathfinding Algorithms - a method that searches a graph by starting at one vertex and exploring adjacent nodes until the destination node is reached

  • Dijkstra's Algorithm - works by visiting vertices in the graph starting with the objectโ€™s starting point. It then repeatedly examines the closest not-yet-examined vertex, adding its vertices to the set of vertices to be examined. It expands outwards from the starting point until it reaches the goal.

  • A* Algorithm - combines pieces of Dijkstra's Algorithm with other pathfinding algorithms to find paths to a goal quickly and efficiently.

  • Heuristic - a problem-solving strategy or method that is not guaranteed to find the optimal solution, but is designed to find a satisfactory solution in a reasonable amount of time

Resources

Do Now/Warm Up (~5 min)

Display one of the maps below - itโ€™s up to you if you want students to look at a more realistic map, or the node map. The node map will be seen again in AP CSP when talking about networks, redundancy, and fault-tolerance.

Option A Prompt: How many paths can you find from Courtenay Industrial Park to a house on Queen Street?

Option B Prompt: How many paths can you find from Node A to Node H?

Pathfinding Algorithms

Once students have had a chance to find as many paths as possible, ask them to share out a few paths and then also ask about their strategies for finding paths.

Thinking about strategies launches them into the discussion of pathfinding algorithms, which are just the processes by which people have deduced we can find paths efficiently. Explain to students that today we will learn about two, but focus in on one.

The first pathfinding Algorithm we will discuss is Dijkstraโ€™s algorithm. This involves assigning each piece of a route a โ€˜costโ€™ related to the distance it will take to travel, and then systematically testing every possible option and discarding the long ones until you are left with only the shortest, most efficient path. You can see this demonstrated in these two gifs:

It is up to you to decide how much code your students are ready for; the wikipedia page provides a great algorithm breakdown that you can turn into pseudo-code together, or you can begin by investigating their pseudocode and trying to put it into more plain English. Plan on spending ~3-5 minutes reviewing this.

Once students have at least a passing familiarity with this algorithm, explain that while it will find the shortest path, it takes quite a while since it has to check so many (especially on a large grid of notes, like the top gif). Luckily, another algorithm was developed - the A* Algorithm.

The A* Algorithm is only going to look at possible solutions - it wonโ€™t spend time on things that donโ€™t actually lead to the final destination. It also uses something called a heuristic, which is a fancy word for an educated guess, to begin by searching with what it thinks will take the least time to get to the finish based on the starting location. This also assigns a โ€˜costโ€™ to each path based on distance, and if we want to get really nitty-gritty about it, it could be described like this:

f(n) = g(n) + h(n) โ†’ which is to say total cost = actual cost (distance) from beginning to end + my best guess of how it will take me to get to the finish

In practice, it looks a little like this (this gif finds two different correct solutions and then reaches a maze that has no solution):

As we can see, this algorithm doesnโ€™t need to check everything because of that heuristic - it already has a best guess of where it needs to go. From there, it checks the neighboring squares for options to continue the path, and it only explores other options when its best guess doesnโ€™t work out as intended. Similar to Dijkstraโ€™s algorithm, spend some time here reviewing the algorithm and/or pseudocode on Wikipedia. The goal is to get students to a place where they can summarize the purpose of these algorithms, but beyond that, you can choose to go as deep or shallow as youโ€™d like in the experience!

Pathfinding In Real Life

These pathfinding algorithms are a useful idea in computing; we will see something similar when learning about networks, and you might even see these things applied in maze solving or game design. But what about in the real world? We could certainly use a computer algorithm to do things like finding us a path from home to school, and it would give us the shortest distance. (If youโ€™ve ever used Google Maps or similar, it uses a mixture of both of these algorithms to find your route!)

Because these are very abstract, generalized applications, the only cost they see are based on distance, or time, it would take to get from the start to the finish. Letโ€™s go back to thinking about your path from home to school - there are probably many routes you could take, each with its own cost that may not have to do with distance. What are some costs that may make you prefer one route over another? Encourage students to think as outside the box as possible, and think of things that could be real or imagined to their particular conversation!

There are lots of things that may be more or less important to you as an individual, and your preferences may change over time. The world around us also changes and throws in new obstacles, some technology-driven, that we may want to be aware of when discussing cost. Letโ€™s take, for example, facial scanning: this surveillance technology is used by police departments in and outside of New York City. Letโ€™s take a moment to learn about it here.

This comes direct from Amnesty International, and it may be worthwhile to do a lateral reading activity on them to ensure students understand what sort of source they are engaging with!

Have students read through the page and take a peek at some routes where facial scanning is prevalent. Ask:

  • How do we feel about facial scanning, generally?

  • Why might one want to avoid facial scanning, or view it as having a higher cost?

  • Are there any instances where facial scanning might not affect the cost of a route?

Allow students to drive this conversation - some students may not feel that having their face scanned is a big deal if it does not immediately change their walk, and some may struggle to emphasize or consider situations where facial scanning could be harmful. Be prepared to offer examples to help them imagine some negative scenarios.

Collaborative Activity: Rewriting an Algorithm

Letโ€™s take the pseudocode for the A* Algorithm (either from the Wikipedia, or the plain-English breakdown created earlier in the lesson). We are going to figure out and complete the following with our partners/groups (teacherโ€™s choice!):

  1. What input would we need from an individual to help determine the factors that change the cost of their path?

  2. How can we rewrite this algorithm to include those costs? Is there a way that we could create pseudocode to help avoid certain high-cost factors?

  3. Based on what you have learned and the Amnesty International Tool, what guidance would you want to give New York City to create more safe and efficient routes for everyone?

Ask students to take these answers and create a brief (~5 slide) presentation that they will share with the class.

Wrap Up

Allow students time to share their algorithm proposals and ideas, either as a gallery walk, or as quick, 3-minute presentations. Use your best judgement to determine which will be most effective for your learners!

Extensions

This can be a great opportunity to jump off into why surveillance technology has gotten to this point and also how NYPD became accidentally reliant (and in many cases, run by) algorithms. As either homework or future class time, consider jumping into these Reply All podcast episodes:

Last updated