Sitemap
Alekhya Mandava

Alekhya Mandava

13 min readJul 21, 2026

--

DSA in the real world

Behind the Route: The Engineering of Digital Navigation

Press enter or click to view image in full size

You’re driving home, half-listening to a podcast, when your map app suddenly reroutes you down a side street a full two minutes before you’d have hit a jam you never even saw. It feels almost psychic. It isn’t. It’s the end result of satellites, millions of strangers’ phones, and a search algorithm that’s smart enough not to waste its own time. Here’s the real story of what’s happening behind that little blue dot.

The World, Reduced to Dots and Lines

Left to its own instincts, your brain wants to plot the shortest path a straight line from where you are to where you’re headed. That instinct only holds up if you’re a bird. Short of piloting a helicopter, you can’t cut across a bay, fly over a mountain range, or pass straight through someone’s kitchen. You’re stuck with whatever roads actually exist, and every rule and obstacle that comes with them.

The gap between “as the crow flies” and “as you actually drove it” is bigger than most people expect. Plug two far-apart coordinates into a straight-line distance tool like Free Map Tools’ distance calculator, then compare that number to what your odometer racks up making the real drive with a coastline, mountain range, or river in the way, the difference can be dramatic. That gap is exactly why turning the world into a graph of dots and lines isn’t just a convenient simplification for engineers it’s the only way the problem makes sense at all.

Before any of the “smart” stuff can happen, the entire physical world has to get flattened into something a computer can actually reason about. The trick engineers use is surprisingly simple: treat every intersection, dead end, and highway ramp as a dot, and every road connecting two dots as a line.

Each line also carries an invisible price tag not just how long the road is, but a constantly-updating blend of expected travel time, current traffic, and general “hassle.” Once the whole world is turned into dots, lines, and prices like this, a completely different question emerges: instead of “how do I get from my house to the grocery store,” the computer is really solving “what’s the cheapest path through this giant, priced maze?” That reframing is the entire foundation everything else is built on.

Press enter or click to view image in full size

Redrawing the World in Real Time

Here’s a question worth sitting with for a second: how does a map company possibly keep up with every new road, closed street, and renamed avenue on Earth? The answer is that the map isn’t drawn once it’s more like a document that’s being quietly rewritten, one paragraph at a time, forever.

It starts from above. Satellites and aircraft sweep over the planet capturing fresh top-down imagery, while camera-equipped vehicles drive the actual streets, capturing what things look like from eye level. Between the two, the same stretch of road gets photographed from the sky and from the sidewalk.

Software then does the first pass of detective work. Rather than making a human scroll through millions of photos, computer vision compares the new images against the existing map and flags anything that looks different a new building outline here, a road that wasn’t there last year over there. It’s the digital equivalent of a proofreader who only marks the sentences that changed between two drafts, instead of rereading the whole book from page one.

Press enter or click to view image in full size

But software alone isn’t trusted to make the final call. Human map editors step in to verify what got flagged, fill in details machines can’t infer like which direction traffic flows on a brand-new road and review corrections submitted by everyday users who spot something wrong. On top of that, cities and transportation departments often hand over official records directly: permits, construction plans, updated speed limits. That’s a far more reliable shortcut than waiting for a satellite to eventually notice a sign changed.

Not everything moves at the same speed, either. A major new highway is usually mapped before it even opens, based on official planning documents. A renamed side street might take days or weeks to show up, once it’s reported or re imaged. But a pothole or a temporary lane closure? That doesn’t even wait for the “official” map it lives in a much faster-moving layer, which brings us to traffic.

Millions of Silent Reporters

Here’s the part that surprises most people: nobody at a map company is personally watching your commute. The traffic data comes from an enormous, anonymous crowd made up of the exact phones already sitting in people’s pockets, including yours.

While the app is running, your phone occasionally sends back a tiny, anonymous signal: roughly where you are, and how fast you’re moving. On its own, one signal means almost nothing. But when a few hundred phones on the same stretch of highway all report the same sudden drop from 60 mph to a crawl, that’s not a coincidence anymore that’s a jam, confirmed in near real time by the crowd itself.

Based on those clustered signals, each road segment gets colored, roughly, as flowing freely, sluggish, or jammed the green, yellow, and red you’re used to seeing.

But live pings only tell you what’s happening right now. That’s where a second, quieter system kicks in: years of historical driving patterns, studied to predict slowdowns before they even start. The system already “knows,” for instance, that a certain intersection turns into a parking lot every weekday around 5:15 p.m. the same way you’d know a popular restaurant gets packed every Friday night, even before you’ve walked in and seen the line. Layer official incident reports and accident feeds on top of both of those, and you get a live traffic picture that’s part sensor network, part fortune teller.

Not Just Distance: How Stop Signs and No-Left-Turns Sneak Into the Math

Press enter or click to view image in full size

Here’s a detail almost nobody thinks about: the “price tag” on a road isn’t just about how long or how busy it is the actual rules of the road get baked directly into the math.

A left turn across oncoming traffic is riskier and slower than a right turn, so it quietly costs a bit more in the routing engine’s eyes. A stretch of road riddled with stoplights costs more than a similar stretch with none, because the system factors in the average time you’ll sit there waiting. One-way streets and time-based restrictions like “no left turn between 4 and 6 p.m.” aren’t just lines drawn for your benefit on the screen; they actually block or restrict specific connections in the underlying graph, sometimes only during certain hours of the day. In other words, traffic law isn’t a separate layer bolted on top of the map it’s baked directly into the price of every single road the algorithm considers.

Picture it concretely. At an intersection with no traffic light, a right turn just means merging into traffic one glance, go. A left turn means waiting for a gap in oncoming traffic before crossing their lane, and that waiting time is real, so the engine tacks a few extra seconds onto any route that includes an unprotected left. That’s exactly why your app sometimes routes you through three right turns instead of one left turn the three rights can genuinely be cheaper in time, even though it looks like the longer way on the screen.

Stoplights work the same way. A two-mile stretch with eight signals realistically takes longer than a two-mile stretch with none, even at identical speed limits, because you’ll be sitting still at some of those lights. The system doesn’t know whether you’ll personally catch a red or green but it knows the average wait, and folds that average straight into the cost.

Get Alekhya Mandava’s stories in your inbox

Join Medium for free to get updates from this writer.

One-way streets are the cleanest way to picture this whole idea. Instead of imagining the graph as dots connected by plain lines, picture them connected by arrows a one-way street is simply an arrow that only points in one direction, so the algorithm literally cannot route you backward through it, the same way you physically can’t drive backward through it. A “no left turn 4–6 p.m.” rule is an even more specific version of the same trick: that particular connection between two roads only exists in the graph outside those hours. During the restricted window, the engine treats that connection as if it isn’t there at all like a bridge that only appears at certain times of day.

Two Rival Explorers: Dijkstra vs. A*

So how does the system actually search through this enormous, priced maze to find the cheapest way through? This is where two classic ideas one older, one a clever twist on it come into play.

The first, Dijkstra’s Algorithm, is the “honest but exhausting” explorer. It spreads outward from your starting point equally in every direction, like water flooding flat across a floor, always expanding whichever nearby road currently looks cheapest even if that road is heading completely away from where you actually want to go. It’s guaranteed to eventually find the truly cheapest path. It just doesn’t care how much wasted effort it takes to get there.

A* (said “A-star”) fixes exactly that flaw with one elegant addition: a hunch. Alongside the real cost racked up so far, A* also estimates the rough straight-line distance remaining to the destination, and uses that estimate to lean its search toward the goal like swapping a floodlight lighting up an entire room for a flashlight beam aimed forward. It still double-checks its work carefully enough to guarantee the right answer, but it gets there by exploring a fraction of the roads Dijkstra would have bothered with. Real-world routing systems push this even further, pre-building long-distance “highway shortcuts” across entire regions but the core insight, search with a sense of direction instead of blindly, traces straight back to this one twist.

Press enter or click to view image in full size
Press enter or click to view image in full size

To make this concrete, I built a small open-source simulation using Spring Boot that runs both algorithms side by side on the same tiny road network Home, Main St, North Ave, Hill Rd, Summit Dr, and a handful of side streets, all the way out to a Hospital node to the northeast. Both algorithms are fed the identical graph and identical weights; the only thing that changes is whether the search has a sense of direction. You can clone it and run it yourself here: https://github.com/Alekhya-Mandava it’s intentionally small enough to step through the exploration order node by node, which is a lot more convincing than just reading about it.

From Tap to Turn-by-Turn: The Milliseconds Behind “Directions”

All of this comes together the instant you type in a destination and hit go and it happens as a tight, practiced relay, not one giant calculation.

First, your typed text “the coffee shop on 5th” gets translated into precise coordinates, a process called geocoding. Your actual GPS position then gets “snapped” onto the nearest point on the road graph, since real-world GPS is rarely sitting exactly on a mapped line. From there, the routing engine powered by that A*-style directional search hunts through the live traffic layer, the base map, and all those rule-based costs to surface a handful of genuinely promising routes, which then get scored and ranked against whatever you care about: fastest, shortest, or avoiding tolls.

Here’s a detail that quietly matters: the server doesn’t send your phone a picture of a map. Instead, it sends lightweight drawing instructions and the route’s exact geometry which is exactly why the map can smoothly rotate and zoom as you move, all rendered locally on your own device instead of constantly downloading new images. Once you’re moving, the loop simply continues: your phone keeps whispering anonymous speed and location data back into the traffic system, and periodically checks whether a faster route has opened up ahead which is the real secret behind that eerily well-timed reroute.

The Map You See Isn’t a Photo — It’s a Drawing, Redrawn Live

Here’s something that might surprise you: in the normal map view, you are almost never looking at a photograph. What’s on your screen is closer to a live drawing than a picture.

Instead of an image, your phone receives vector data small mathematical instructions like “draw a gray line from point A to point B, four pixels wide” or “fill this shape green, it’s a park.” Your phone’s own graphics processor reads those instructions and draws them on the spot, the same way a video game renders a 3D scene from raw geometry instead of playing back a video clip.

Why bother with instructions instead of just sending a picture? Because a photo-like image would need to be re-downloaded every single time you scrolled, tilted, or zoomed even slightly slow, and heavy on data. Vector instructions, by contrast, are tiny, and once your phone has them, it can spin, tilt, and zoom the map instantly by simply redrawing those same shapes from a new angle, with nothing new to download. That’s the real reason the map feels buttery-smooth when you rotate it with two fingers.

To keep this fast at a planetary scale, the whole world’s map data is chopped into a grid of small square tiles. As you move, your phone only requests the handful of tiles near you plus a small buffer around the edges and quietly pre-fetches tiles just ahead of where you’re heading, so new areas are ready before you actually reach them.

Satellite view is the one exception to all this. Switch over to it, and you are looking at real, stitched-together photography the same satellite and aircraft imagery used to keep the base map updated which is exactly why satellite view can’t rotate and redraw quite as instantly or cleanly as the standard view; it’s genuinely a photo mosaic, not a live drawing. Even 3D buildings follow the “drawing, not photo” rule: your phone receives simplified 3D shape data like a low-detail digital sculpture of each building and its graphics processor renders that shape with lighting and shadow locally, so it can tilt and rotate smoothly instead of needing a fresh image for every possible angle.

Routing and rendering, in other words, are two entirely separate subsystems doing two separate jobs one figures out which path is cheapest, the other decides what it looks like once you’re on it. They only meet at the very last moment, when the chosen route’s shape gets handed off to the renderer to draw on top of everything else.

Wait, Roads Curve — So How Does a Straight-Line Graph Handle That?

If you’ve followed along this far, a good question probably occurred to you: if every road is just a straight line between two dots, how does the map draw an actual curve?

The trick is that a road secretly carries two separate kinds of data, doing two separate jobs. The routing data is just the road’s two endpoints and its cost that’s the only thing the pathfinding algorithm ever looks at while it’s searching. Completely separately, the shape data is a much denser trail of extra latitude/longitude points strung tightly along the road’s real curve, used purely to draw it accurately on your screen like a dot-to-dot puzzle with dozens of extra dots packed close together along the bend.

Press enter or click to view image in full size

The pathfinding algorithm never has to think about the curve at all. It gets pulled in only at the very end, purely so your screen shows a smooth, realistic road instead of a straight line slicing across a bend. Splitting “how do I calculate the fastest path” from “how do I draw this accurately” is exactly what keeps the search lightning-fast, even though real roads are almost never straight.

The Big Picture

None of these systems work alone.

The base map tells the engine what physically exists; the traffic layer tells it how those roads are actually behaving right now, and how they usually behave at this exact moment on this exact day; the rules of the road quietly reshape the price of every path; and a search algorithm with a sense of direction stitches it all together into a route that keeps updating itself as the world around you changes. It feels effortless and instant but underneath, it’s satellites, strangers’ phones, human editors, decades-old algorithms with a clever twist, and a constant stream of tiny anonymous pings, all working in concert just so you can make the right turn at the right moment, without ever thinking about any of it.

This kicks off a series I’m calling DSA in Real Life taking the classic computer science ideas most of us learned once and forgot, and showing where they’re actually running, quietly, inside the apps we use every day. This is just the first stop.

I put this together from my own understanding, not as someone who’s actually built routing infrastructure for a living. So there’s a real chance something here is simplified more than it should be, a little outdated, or flat-out off somewhere. If you catch something like that, tell me it genuinely makes the next one better.

And if you know an edge case, a wrinkle, or a “yeah but actually…” that I glossed over, I want to hear it. Find me on LinkedIn always up for talking this stuff through.

--

--