By the end of this chapter you'll be able to…

  • 1Distinguish routing from forwarding by timescale and scope
  • 2Trace Dijkstra's algorithm step by step and state its complexity with an array and with a heap
  • 3Explain why flooding always finds the shortest path and how its duplication is controlled
  • 4Apply the Bellman-Ford update in a distance vector exchange over several rounds
  • 5Explain count-to-infinity in terms of missing path information
  • 6State what split horizon and poison reverse fix and the loop size at which they fail
  • 7Describe link state operation and why it has no counting problem
  • 8Compare the two families on knowledge, message content, convergence, memory and computation
  • 9Compute the table size reduction from hierarchical routing
  • 10Explain why BGP carries paths rather than distances
💡
Why this chapter matters in GATE
A routing algorithm is defined by what a router knows and when it learns it, and count-to-infinity, convergence speed and memory cost all follow from that one distinction. GATE tests Dijkstra traces, distance vector table evolution over rounds, the split horizon limitation, and the comparison table between the two families.

Before you start — revise these

🔗
Graphs with weighted edges, and the notion of a shortest path
🔗
IP forwarding and longest prefix match
🔗
Basic asymptotic notation

Routing Protocols

Routing is the process of deciding paths; forwarding is the act of moving a packet according to that decision.

The organising fact is that a routing algorithm is defined by what a router knows and when it learns it.

A distance vector router knows only what its neighbours tell it, which is a summary of their distances with no explanation. A link state router knows the entire topology and computes paths itself.

Every behavioural difference follows from that single distinction. Count-to-infinity happens because a distance vector router cannot tell whether a neighbour's advertised route passes through itself. A link state router cannot make that mistake, because it can see the whole path.

The second organising fact is that routing tables must be kept small enough to search and to store, which is why hierarchy exists. Without it, every router would need an entry for every network on the internet.

The third is that between organisations, the cheapest path is not the wanted path. Interdomain routing is decided by policy and business relationships, which is why BGP carries paths rather than distances.

1. Routing and Forwarding

Forwarding is a local, per-packet action: look up the destination and move the packet to an output port, in nanoseconds.

Routing is a global, ongoing computation that fills the table forwarding consults, running on a timescale of seconds.

Static routing uses manually configured entries, which is fine for small or stub networks and does not adapt to failure.

Dynamic routing computes entries from exchanged information and adapts, at the cost of protocol traffic and convergence delay.

A routing metric assigns a cost to each link. Hop count is simplest; bandwidth, delay and administrative preference are common alternatives, and OSPF conventionally uses inverse bandwidth.

2. Shortest Path and Flooding

Dijkstra's algorithm computes shortest paths from one source to all destinations when all link costs are non-negative.

It maintains a set of finalised nodes and repeatedly moves the nearest unfinalised node into it, relaxing the edges out of that node.

Its complexity is with a simple array and with a binary heap.

Flooding sends an incoming packet out on every link except the one it arrived on.

It needs no routing information at all and always finds the shortest path, because some copy of the packet travels it.

Its cost is enormous duplication, controlled by a hop counter, by sequence numbers so a node discards packets it has already seen, or by selective flooding along roughly correct directions.

Flooding is used where robustness matters more than efficiency, notably to distribute link state advertisements, and its guarantee of reaching every node is exactly what that job needs.

3. Distance Vector Routing

Each router maintains a vector of distances to every destination and periodically sends it to its neighbours.

On receiving a neighbour's vector, a router updates its own using the Bellman-Ford relation: the distance to a destination through a neighbour is the cost to that neighbour plus the neighbour's advertised distance.

Good news travels fast. A newly available shorter route propagates one hop per exchange round.

Bad news travels slowly, and this is the algorithm's defining flaw.

Count-to-infinity occurs when a link fails. A router loses its route, but a neighbour still advertises a distance to that destination, a distance that was computed through the very router now asking. Each accepts the other's stale advertisement, and the distances climb one step at a time.

Setting infinity to a small number, 16 in RIP, bounds the damage by declaring a destination unreachable once the count reaches it.

Split horizon does not advertise a route back to the neighbour it was learned from, which fixes the two-node loop.

Poison reverse advertises such a route with infinite cost instead of omitting it, which propagates the bad news actively rather than passively.

Neither fixes loops of three or more routers, where the stale information circulates around the cycle rather than bouncing between two nodes, and this limitation is a favourite examination point.

Each router discovers its neighbours and the cost to each, then floods that information to every other router.

The advertisement is small, listing only the router's own links, but every router receives every advertisement.

Once a router holds all advertisements, it has the complete topology and runs Dijkstra locally to compute its own shortest path tree.

Convergence is fast and loops are transient, because every router computes from the same map rather than from second-hand summaries.

Sequence numbers and ages on advertisements prevent old information from overwriting new, and are the fiddly part of any real implementation.

PropertyDistance vectorLink state
KnowledgeNeighbours' distances onlyFull topology
Message contentDistances to all destinationsOwn links only
Message scopeTo neighbours onlyFlooded to everyone
ComputationDistributed, iterativeLocal, Dijkstra
ConvergenceSlow, count-to-infinity possibleFast, no counting problem
MemoryProportional to destinationsProportional to topology
ExampleRIPOSPF

5. Hierarchy and Interdomain Routing

Hierarchical routing groups routers into regions or areas. A router keeps detailed entries for its own area and a single summary entry for each other area.

The table shrinks dramatically and the paths get slightly worse, since a summary cannot express which specific router inside a distant area is nearest.

OSPF implements this with areas connected through a backbone area, and all inter-area traffic passes through the backbone.

An autonomous system is a network under one administration, and routing splits into interior and exterior protocols.

Interior gateway protocols such as RIP and OSPF optimise a technical metric.

The exterior protocol, BGP, optimises policy instead. An operator may prefer a longer path over a customer link to a shorter path over an expensive transit link, and no cost metric can express that.

BGP is a path vector protocol: an advertisement carries the full sequence of autonomous systems the route traverses.

Carrying the path serves two purposes. It permits loop detection, since a router discards any advertisement already containing its own number, and it permits policy decisions based on who is on the path.

RIP and OSPF in Practice

RIP is the classic distance vector protocol. Its metric is hop count, its infinity is 16, and it broadcasts its whole table every 30 seconds, declaring a neighbour dead after 180 seconds of silence.

Those timers are the reason RIP converges slowly, quite apart from count-to-infinity, and they cap the usable network diameter at 15 hops.

OSPF is the standard link state protocol. It uses inverse bandwidth as its metric, floods advertisements only when something changes, and supports areas, authentication and equal-cost multipath.

Equal-cost multipath is worth noting, since it lets a router split traffic across several paths of identical cost, which distance vector protocols cannot express.

Multicast Routing

Unicast delivers to one destination and broadcast to all; multicast delivers to a group whose membership changes over time.

The routing problem becomes building a delivery tree rather than a path, so that each link carries at most one copy of a packet.

A source-based tree is built per sender, giving short paths and much router state. A shared tree uses one tree per group rooted at a rendezvous point, giving less state and longer paths.

Reverse path forwarding is the standard trick: a router accepts a multicast packet only if it arrived on the interface it would use to send unicast traffic back to the source, which prunes duplicates cheaply.

6. Worked Examples

Example 1. Run Dijkstra from node A on this graph: edges A-B cost 4, A-C cost 2, B-C cost 1, B-D cost 5, C-D cost 8, C-E cost 10, D-E cost 2.

Initialise. Distance to A is 0; all others are infinite. The finalised set is empty.

Step 1. The nearest unfinalised node is A at 0. Finalise A and relax its edges: B becomes 4, C becomes 2.

Step 2. The nearest unfinalised node is C at 2. Finalise C and relax: B via C is , which improves on 4, so B becomes 3. D via C is . E via C is .

Step 3. The nearest is B at 3. Finalise B and relax: D via B is , improving on 10, so D becomes 8.

Step 4. The nearest is D at 8. Finalise D and relax: E via D is , improving on 12, so E becomes 10.

Step 5. Finalise E at 10.

Final distances from A: B is 3, C is 2, D is 8, E is 10.

The shortest path to E is A, C, B, D, E, which is worth tracing, since it uses four hops where a two-hop path A-C-E exists at cost 12.

That is the point of a cost metric. Hop count would have chosen A-C-E; the cost metric chose the longer path because it is genuinely cheaper.

Example 2. Three routers A, B and C in a line, with A-B and B-C each cost 1. Show count-to-infinity when the link from C to a destination network fails.

Before the failure, C reaches the network at cost 1, B at cost 2 through C, and A at cost 3 through B.

The link fails. C now has no route and sets its distance to infinity.

But before C can tell anyone, B advertises its own table, which still says it can reach the network at cost 2.

C accepts this. It reasons that B claims distance 2, so C can reach the network at through B.

C does not know that B's route goes through C itself, because a distance vector advertisement carries no path information. This is the entire cause of the problem.

Now C advertises 3. B updates its own route through C to .

B advertises 4, C goes to 5, and the count climbs.

It stops only when the distance reaches the protocol's infinity, which RIP sets at 16, after which the destination is declared unreachable.

Split horizon fixes this two-node case. B would not advertise the route back to C, since it learned it from C, so C would never adopt the bogus path.

But split horizon fails on a three-node loop. Suppose A, B and C are mutually connected and the destination lies beyond C.

When C's link fails, A can learn a stale route from B, and B can learn one from A, so the obsolete information circulates around the triangle rather than bouncing between two nodes.

Neither split horizon nor poison reverse prevents this, because in each individual exchange the route is being advertised to a router other than the one it was learned from, which is precisely what the rules permit.

Link state routing has no analogue of this failure, because every router computes from the full topology and can see that the failed link is gone.

Example 3. Compare the message complexity of distance vector and link state routing on a network of routers and links.

In link state routing, each router originates one advertisement listing its own links.

That advertisement is flooded, traversing every link, so one advertisement costs transmissions.

With routers each originating one, the total is per full round of flooding.

In distance vector routing, each router sends its whole vector to each neighbour.

A vector has entries, and the number of neighbour pairs is , so one round costs as well.

The totals match, which is why the choice is not made on message volume.

The real differences lie elsewhere.

Convergence time favours link state, since flooding plus a local computation completes in roughly the network diameter, while distance vector needs many rounds and can count to infinity.

Memory favours distance vector, which stores one number per destination, against link state's full topology database.

Computation favours distance vector, whose per-update work is trivial, against Dijkstra's .

Robustness to bad data differs sharply. A distance vector router that advertises wrong distances corrupts its neighbours silently; a link state router advertising a wrong topology is at least advertising something every router can inspect.

Example 4. A network has 900 routers. Compare table sizes under flat routing and under a two-level hierarchy of 30 regions of 30 routers each.

Under flat routing, every router needs an entry for every other router, so each table has 899 entries.

Under the hierarchy, a router keeps detailed entries for the 29 other routers in its own region.

It also keeps one summary entry per other region, which is 29 more.

Total is entries, against 899.

The reduction is more than fifteen-fold, and it grows with network size, which is why hierarchy is not optional at internet scale.

The cost is path quality. A summary entry names one way into a distant region, and packets for any router in that region follow it, even when a different entry point would have been closer.

The optimal number of levels for routers is , with entries per router, a classical result worth knowing though rarely applied literally.

With 900 routers that suggests about 7 levels, which no real network uses, because each level adds administrative complexity and further degrades path quality.

Example 5. Why is BGP a path vector protocol rather than a distance vector protocol?

Two reasons, and both matter.

First, loop detection. In distance vector routing, a router cannot tell whether an advertised route passes through itself, which is exactly what causes count-to-infinity.

Carrying the full autonomous system path makes the check trivial: a router discards any advertisement whose path already contains its own number.

At internet scale this matters more than in a small network, since convergence delays measured in minutes would be intolerable and the count-to-infinity bound cannot simply be set to 16.

Second, and more fundamentally, policy cannot be expressed as a distance.

An operator may prefer a five-hop path through a customer to a two-hop path through an expensive transit provider, because the first earns revenue and the second costs money.

No scalar metric can encode that preference, since the decision depends on who is on the path, not on how long it is.

The path vector makes the decision expressible. A router can apply rules referring to specific autonomous systems on the advertised path, preferring, avoiding or refusing routes by identity.

A consequence worth noting: BGP does not compute shortest paths at all. It selects among advertised paths by a sequence of policy rules, with path length appearing only as a tie-breaker some way down the list.

That is why the internet's routes are frequently not the shortest ones available, and why the phrase routing policy describes real commercial relationships rather than a technical optimisation.

Summary

A routing algorithm is defined by what a router knows and when it learns it, and every behavioural difference follows from that.

Routing computes tables on a timescale of seconds; forwarding consults them per packet in nanoseconds.

Dijkstra needs non-negative costs and runs in with an array or with a heap. Flooding needs no information at all, always finds the shortest path, and is controlled by hop counts or sequence numbers, which is why it distributes link state advertisements.

Distance vector routers exchange whole vectors with neighbours and apply Bellman-Ford. Good news travels one hop per round; bad news causes count-to-infinity, because an advertisement carries no path. Bounded infinity limits the damage, split horizon fixes two-node loops, poison reverse announces them actively, and neither fixes loops of three or more.

Link state routers flood their own link costs and run Dijkstra on the complete map, converging in about the network diameter with only transient loops.

Message complexity is for both, so the choice turns on convergence speed, memory and computation instead.

Hierarchy cuts a 900-router table from 899 entries to 58 with two levels, at the cost of path quality, with the theoretical optimum at levels.

BGP is a path vector protocol because carrying the full autonomous system path gives trivial loop detection and, more importantly, allows decisions based on who is on the path, which no scalar metric can express. BGP does not compute shortest paths; it applies policy.

RIP uses hop count with infinity 16 and broadcasts every 30 seconds, which caps its diameter at 15 hops. OSPF uses inverse bandwidth, floods only on change, and supports areas and equal-cost multipath.

Multicast routing builds a delivery tree rather than a path, choosing between per-source trees with more state and shorter paths and shared trees with less state and longer ones, with reverse path forwarding used to suppress duplicates.

Key formulas & results

Everything to memorise for the exam hall, in one card. Screenshot this for revision.

The organising principle
a routing algorithm is defined by what a router knows and when it learns it
Distance vector routers know neighbours' summaries; link state routers know the whole map. Every behavioural difference follows.
Bellman-Ford update
distance to D through neighbour N = cost to N plus N's advertised distance to D
The router takes the minimum over all neighbours. Nothing in the advertisement says which path N uses, which is the cause of count-to-infinity.
Dijkstra complexity
O(n squared) with an array, O(E log n) with a binary heap; requires non-negative costs
Each iteration finalises the nearest unfinalised node and relaxes its outgoing edges.
Count-to-infinity cause
a distance vector advertisement carries no path, so a router cannot tell whether a route passes through itself
Bounded infinity, 16 in RIP, limits the damage rather than preventing the problem.
Split horizon and its limit
do not advertise a route back to the neighbour it was learned from; fails for loops of three or more
In a triangle the stale route is advertised to a different neighbour each time, which the rule permits.
Message complexity
both families cost O(nE) per round
Link state floods n small advertisements over E links; distance vector sends n-entry vectors across E adjacencies. The choice turns on convergence, memory and computation instead.
Hierarchical table size
with k regions of m routers each, a table holds (m minus 1) plus (k minus 1) entries
900 routers in 30 regions of 30 gives 58 entries instead of 899, at the cost of path quality.
Optimal hierarchy depth
ln n levels with e times ln n entries per router
A classical result rarely applied literally, since each level adds administrative complexity and degrades paths further.
RIP parameters
hop count metric, infinity 16, full table broadcast every 30 seconds, neighbour dead after 180
The timers cap usable diameter at 15 hops and are a separate cause of slow convergence from count-to-infinity.
Path vector rationale
carrying the AS path gives loop detection by inspection and lets policy refer to who is on the path
BGP does not compute shortest paths at all; path length is a late tie-breaker among policy rules.
⚠️

Traps GATE sets — and how to dodge them

These are the exact option-traps and misreads that cost marks under negative marking.

WATCH OUT
Running Dijkstra on a graph with negative edge costs
Dijkstra requires non-negative costs, because finalising the nearest node assumes no later edge can reduce its distance. Bellman-Ford handles negatives.
Why it happens: The algorithm is presented as the shortest path algorithm without its condition being emphasised.
WATCH OUT
Claiming split horizon eliminates count-to-infinity
It fails for loops of three or more routers, where each advertisement goes to a neighbour other than the one it was learned from, which the rule allows.
Why it happens: It genuinely fixes the two-node example that is always used to introduce the problem.
WATCH OUT
Saying link state sends more messages than distance vector
Both are O(nE) per round. Link state floods many small advertisements; distance vector sends few large vectors. The real differences are convergence, memory and computation.
Why it happens: Flooding sounds expensive and the word suggests waste.
WATCH OUT
Describing a link state advertisement as containing routes to all destinations
An advertisement lists only the originating router's own links and their costs. Every router assembles the map from many such advertisements.
Why it happens: The router ends up knowing all destinations, so its advertisement seems to carry them.
WATCH OUT
Assuming hierarchical routing preserves optimal paths
A summary names one entry point into a region, so packets bound for a router near a different entry point take a longer path. That loss is the price of the smaller table.
Why it happens: Summarisation looks like a purely representational change.
WATCH OUT
Treating BGP as a shortest path protocol with AS hops as the metric
BGP applies a sequence of policy rules; AS path length is one tie-breaker some way down the list. Routes chosen are frequently not the shortest available.
Why it happens: The AS path is visible and its length looks like a metric.
WATCH OUT
Confusing routing with forwarding in a complexity question
Forwarding is per packet in nanoseconds and consults the table; routing is a background computation in seconds that fills it.
Why it happens: Both involve the routing table and the words are used loosely in ordinary speech.
WATCH OUT
Believing flooding is never used because it is wasteful
Flooding is exactly how link state advertisements are distributed, because reaching every router reliably is precisely what that task needs.
Why it happens: The duplication is enormous and the algorithm is introduced as a naive baseline.

Exam-pattern practice

PYQ-style questions with full solutions. Work through them as a readiness check — mark yourself honestly and get your gap report at the end.

Readiness check

Are you exam-ready for Routing Protocols: Shortest Path, Flooding, Distance Vector & Link State?

10 problems from this chapter. Try each one, reveal the worked solution, mark yourself honestly — get your gap report at the end.

10 questions~7 min

5-minute revision

The whole chapter, distilled. Read this the night before the exam.

  • A routing algorithm is defined by what a router knows and when
  • Forwarding is per packet in nanoseconds; routing is background computation in seconds
  • Dijkstra needs non-negative costs; O(n squared) with an array, O(E log n) with a heap
  • Flooding needs no information, always finds the shortest path, and is controlled by hop counts or sequence numbers
  • Flooding is how link state advertisements are actually distributed
  • Distance vector applies Bellman-Ford to neighbours' advertised distances
  • Good news travels one hop per round; bad news causes count-to-infinity
  • The cause is that an advertisement carries no path information
  • RIP sets infinity to 16, capping the diameter at 15 hops
  • Split horizon fixes two-node loops; poison reverse announces them actively
  • Neither fixes loops of three or more routers
  • Link state floods own-link advertisements and runs Dijkstra locally
  • Link state converges in about the network diameter with only transient loops
  • Both families cost O(nE) messages per round
  • Hierarchy cuts 899 entries to 58 for 900 routers in 30 regions, at the cost of path quality
  • Optimal depth is ln n levels with e ln n entries per router
  • OSPF uses inverse bandwidth, areas, a backbone, and equal-cost multipath
  • BGP is path vector: loop detection by inspection and policy by identity, not shortest path
  • Multicast builds trees; reverse path forwarding suppresses duplicates

GATE question blueprint

How this topic is asked, tier by tier — so you can prep to the pattern.

Typical weightage: 5

Question styleMarks eachTypical countWhat it tests
Shortest path21
Distance vector11
Link state11
Hierarchical routing11
Interdomain routing11

Exam-hall strategy

Battle-tested tips from mentors and toppers for this topic under the sectional clock.

  1. For Dijkstra questions, write a table with one column per node and one row per iteration, and record which node is finalised at each step, because partial credit follows the working. For distance vector questions, do one full round at a time across all routers rather than following a single router forward, since the marks are usually for the table state after a stated number of rounds. When asked about count-to-infinity, name the missing path information as the cause rather than describing the symptom. Comparison questions want the table axes: knowledge, message content, message scope, convergence, memory, computation. If a question mentions policy or business relationships, the answer involves BGP and path vectors, never a metric.

Beyond the exam

Where this skill shows up in the job you're competing for — and in life.

OSPF runs inside almost every enterprise and carrier network

OSPF runs inside almost every enterprise and carrier network, and its area design directly reflects the hierarchical table-size argument in this chapter

BGP misconfigurations have taken large parts of the inter…

BGP misconfigurations have taken large parts of the internet offline, because a single wrongly advertised prefix is accepted on policy grounds by whoever does not filter it

Route flap damping exists because the convergence behavio…

Route flap damping exists because the convergence behaviour analysed here becomes destructive when a link oscillates

Data centre fabrics increasingly run BGP internally rathe…

Data centre fabrics increasingly run BGP internally rather than an interior protocol, using its policy machinery to control traffic within one building

Software-defined networking removes distributed routing e…

Software-defined networking removes distributed routing entirely, computing paths centrally, which is a direct response to the convergence and policy complexity described here

Where else this topic is tested

Prepare once, score in every exam that asks it.

GATE CS
GATE DA
UGC NET Computer Science
ISRO Scientist SC
BARC Computer Science

Questions aspirants ask

Pulled from the Q&A community and mentor sessions.

Because it is simple to implement and cheap per update, which suits small networks and low-powered devices. Modern variants such as EIGRP add a loop-freedom condition that eliminates counting to infinity while keeping the low memory footprint, so the family survives where full topology databases would be excessive.

It does not try to. OSPF runs inside one autonomous system and uses areas within it, so an advertisement floods only within its area and appears elsewhere as a summary. Between autonomous systems, BGP takes over, and no link state information crosses that boundary at all.

Because a large network's convergence is limited by detection and by damping rather than by the algorithm. Detecting a failure takes as long as the hello timers allow, and operators deliberately delay reacting to flapping links, since recomputing constantly is worse than briefly using a suboptimal path.

Not always, but it can never make them better. When a region has a single natural entry point, the summary loses nothing. When it has several, packets bound for routers near an unused entry point travel further, and the loss grows with the size and connectivity of the region.

Because a withdrawn route triggers each autonomous system to explore alternative paths it has stored, advertising each in turn before concluding the destination is unreachable. This path exploration produces a burst of transient advertisements, and damping timers intended to limit that burst also delay the final answer.

No, and largely for policy rather than technical reasons. Multicast requires routers along the path to hold per-group state and requires providers to cooperate on a service that is hard to bill for. It is common inside single administrative domains, such as financial market data feeds and IPTV within one provider's network.
Header Logo