Routing Algorithms for NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

Routing-algorithm questions give you a small network with link costs and ask for a shortest path, a distance-vector update, the order Dijkstra settles nodes, or what happens after a link fails. Others ask which protocol (RIP, OSPF or BGP) fits a situation. This page works each type in full, going deeper than the routing section of the Network Layer topic page.

Computer Networks and Cloud Computing carries 10% of the NSCT, according to HEC's Areas of Competencies. Candidates averaged 39.6% accuracy in the area in 2026, per the HEC NSCT report and APP. Shortest-path traces are slow the first time and fast after a few practice runs.

The method, step by step

  1. Draw the graph from the cost list before doing anything else.
  2. Link state (Dijkstra): set the source to 0 and everything else to infinity. Repeatedly make the closest tentative node permanent and relax its neighbours (lower their cost if the new route is cheaper).
  3. Distance vector (Bellman-Ford): for each neighbour v, add the link cost c(x,v) to v's reported distance, then take the minimum.
  4. After a failure: remove the link and recompute. In distance vector, check whether a neighbour's stale route runs back through you (count-to-infinity).
  5. Protocol questions: RIP = hop count, max 15. OSPF = cost from bandwidth, Dijkstra. BGP = path vector between autonomous systems (AS), shortest AS_PATH after policy.
Distance vector Link state
Each router knows Distances its neighbours report Full map of the area
Sends Its whole distance table to neighbours Its own links to every router (flooding)
Algorithm Bellman-Ford Dijkstra
Convergence Slow; may count to infinity Fast after flooding
Examples RIP (RIPv2 is classless) OSPF, IS-IS

Worked example. Links: A-B 2, A-C 5, B-C 1, B-D 4, C-D 1, C-E 6, D-E 2, D-F 7, E-F 1. Find shortest paths from A. Each row shows the tentative costs after making that node permanent.

Step Made permanent B C D E F
1 A (0) 2 5 ∞ ∞ ∞
2 B (2) – 3 (via B) 6 (via B) ∞ ∞
3 C (3) – – 4 (via C) 9 (via C) ∞
4 D (4) – – – 6 (via D) 11 (via D)
5 E (6) – – – – 7 (via E)
6 F (7) – – – – –

Final routing table at A:

Destination Cost Path Next hop
B 2 A-B B
C 3 A-B-C B
D 4 A-B-C-D B
E 6 A-B-C-D-E B
F 7 A-B-C-D-E-F B

Note that the direct link A-C (5) loses to A-B-C (3). The routing table stores only the next hop, which is B for every destination here.

Network of routers A to F with link costs; Dijkstra from A gives costs B 2, C 3, D 4, E 6, F 7, and the shortest-path tree A-B-C-D-E-F is highlighted.
The page's link-state example. Highlighted links form the shortest-path tree from A; every route leaves A via B.

Bellman-Ford (distance vector)

Worked example: one update. Router X has links to A (cost 2), B (cost 7) and C (cost 3). They report distances to Y of 9, 2 and 5.

Via c(X, v) D_v(Y) Total
A 2 9 11
B 7 2 9
C 3 5 8

X installs Y at cost 8 via C. B has the best reported distance but the most expensive link.

Worked example: convergence in rounds. Links: W-X 1, X-Y 2, W-Y 7, Y-Z 1. Routers start knowing only their own links and exchange vectors in synchronous rounds. W's table:

Round To X To Y To Z
0 (own links) 1 7 ∞
1 1 3 (via X) 8 (via Y)
2 1 3 4 (via X)
3 1 3 4 (no change: converged)

News travels one hop per round, so W needs two rounds to learn the best route to Z, which is three hops away.

Count-to-infinity and its fixes

Worked example. Routers form a line A-B-C, each link cost 1, with no split horizon. A reaches C at 2 via B. The B-C link fails, and B then hears A's stale advertisement of distance 2.

Update B's distance to C A's distance to C
Before failure 1 2
B hears A's 2 3 2
A hears B's 3 3 4
B hears A's 4 5 4
… … …
A hears B's 15 15 16
B hears A's 16 16 16

The two routers bounce the route back and forth, adding 1 each time, until both reach RIP's infinity of 16: 15 updates in all. With RIP's 30-second updates this can take minutes.

Fixes: - Split horizon: do not advertise a route back out of the interface it came from. - Poison reverse: advertise it back with metric 16 (infinity). Both fix two-router loops but not loops of three or more. - Triggered updates and hold-down timers speed up or damp the bad news.

RIP, OSPF and BGP

RIP OSPF BGP
Type Distance vector Link state Path vector
Scope Inside one AS (IGP) Inside one AS (IGP) Between ASes (EGP)
Metric Hop count (16 = unreachable) Cost = reference bandwidth / link bandwidth Policy, then AS_PATH length and other attributes
Carried by UDP port 520 IP protocol 89 TCP port 179
Updates Every 30 seconds On change, plus periodic refresh Incremental, on change

Worked example: OSPF cost. With the default reference bandwidth of 100 Mbps, a 10 Mbps link costs 10, a 100 Mbps link costs 1, and a 1 Gbps link also costs 1, because cost cannot go below 1. That is why networks with gigabit links raise the reference bandwidth. With a 1 Gbps reference:

Link Cost
10 Mbps 100
100 Mbps 10
1 Gbps 1

Worked example: BGP path choice. A router in AS 100 learns a prefix through two neighbours with equal local preference. One AS_PATH is 200 300 400 and the other is 500 400. BGP prefers 500 400 because it crosses fewer autonomous systems. A route arriving with AS_PATH 300 100 400 is rejected outright, because 100 is the router's own AS: accepting it would create a loop.

Speed tricks

Common mistakes

Practice set

These are different from the quiz questions below.

  1. A router's link costs to three neighbours are 4, 2 and 5. They report 3, 6 and 1 to a destination. What is the router's cost?
  2. What is the largest hop count RIP can still use?
  3. With the 100 Mbps default reference, what OSPF cost does a 1 Gbps link get?
  4. Which transport protocol and port does BGP use?
  5. Links X-Y 2, Y-Z 2 and X-Z 5. What is X's shortest distance to Z?
  6. A router in AS 65001 receives a route with AS_PATH 65010 65001 65020. What does it do?
  7. Which algorithm does OSPF run on its link-state database?
  8. In the A-B-C count-to-infinity example, what metric does B advertise right after hearing A's 4?
Show answers
  1. 6: totals 7, 8 and 6; the minimum is via the third neighbour.
  2. 15: 16 means unreachable.
  3. 1: 100 / 1,000 rounds up to the minimum of 1.
  4. TCP, port 179.
  5. 4: via Y (2 + 2) beats the direct 5.
  6. Rejects it: its own AS number is already in the path.
  7. Dijkstra's shortest-path-first algorithm.
  8. 5: 1 + 4.

Practise

The quiz below has 20 routing questions, mostly traces and calculations, which you can filter by tier and difficulty. Every shortest path and update was checked by running Dijkstra and Bellman-Ford in Python.

Practise: 20 questions

Interactive quiz loading. The first 10 questions are shown below.

  1. Which equation does a distance-vector router use to update its cost D_x(y) to destination y?

    1. D_x(y) = min over neighbours v of { c(x,v) + D_v(y) }
    2. D_x(y) = max over neighbours v of { c(x,v) + D_v(y) }
    3. D_x(y) = min over neighbours v of { D_v(y) }
    4. D_x(y) = sum over neighbours v of { c(x,v) }
    Show answer

    Answer: A. D_x(y) = min over neighbours v of { c(x,v) + D_v(y) }

    This is the Bellman-Ford equation. Router x adds the cost of the link to each neighbour v to the distance v reports to y, then keeps the smallest total. Leaving out c(x,v) is the classic mistake.

  2. What metric does RIP use to choose routes?

    1. Link bandwidth
    2. Delay in milliseconds
    3. Hop count
    4. AS-path length
    Show answer

    Answer: C. Hop count

    RIP counts routers crossed, up to a maximum of 15; 16 means unreachable. It ignores bandwidth, so it may prefer a slow two-hop path over a fast three-hop one.

  3. How does BGP, a path-vector protocol, prevent routing loops between autonomous systems?

    1. It limits every route to 15 AS hops
    2. A router rejects any route whose AS_PATH already contains its own AS number
    3. It floods link-state advertisements and runs Dijkstra
    4. It uses split horizon with a 30-second timer
    Show answer

    Answer: B. A router rejects any route whose AS_PATH already contains its own AS number

    Each BGP route carries the list of autonomous systems it has passed through. If an AS sees its own number in that list, accepting the route would create a loop, so it is discarded.

  4. What does split horizon do in a distance-vector protocol?

    1. It splits the network into areas to reduce flooding
    2. It sends half of the routing table in each update
    3. It advertises learned routes back with metric 0
    4. A router does not advertise a route back out of the interface it learned that route from
    Show answer

    Answer: D. A router does not advertise a route back out of the interface it learned that route from

    If B reaches C through A, B does not tell A about C. That stops A from later using B's stale route back through itself. Poison reverse is a variant: B advertises the route back to A with an infinite metric.

  5. In a link-state protocol such as OSPF, what does each router flood to the other routers in its area?

    1. Its complete routing table, with distances to every destination
    2. Only the routes that changed since the last update
    3. Its AS_PATH attribute
    4. Link-state advertisements describing its own links and their costs
    Show answer

    Answer: D. Link-state advertisements describing its own links and their costs

    Each router describes only its directly connected links. Flooding these advertisements gives every router the same map of the area, and each then runs Dijkstra itself. Sending whole distance tables to neighbours is the distance-vector approach.

  6. Which pair are both interior gateway protocols (used inside one autonomous system)?

    1. OSPF and BGP
    2. RIP and OSPF
    3. RIP and BGP
    4. BGP and eBGP
    Show answer

    Answer: B. RIP and OSPF

    RIP (distance vector) and OSPF (link state) both route inside one organisation's network. BGP is the exterior gateway protocol that connects autonomous systems; eBGP is simply BGP between different ASes.

  7. Router X has link costs A = 3, B = 1 and C = 5 to its neighbours. They report distances to destination Y of A = 4, B = 7 and C = 1. What does X install for Y?

    1. Cost 6 via C
    2. Cost 8 via B
    3. Cost 1 via C
    4. Cost 7 via A
    Show answer

    Answer: A. Cost 6 via C

    Add each link cost to the neighbour's distance: via A 3 + 4 = 7, via B 1 + 7 = 8, via C 5 + 1 = 6. The minimum is 6, through C. Choosing B for its cheap link, or C's reported 1 alone, both skip a term.

  8. Using Dijkstra's algorithm from P, what is the least-cost distance to U? Links and costs: P-Q 3, P-R 1, R-Q 1, Q-S 2, R-S 6, R-T 5, S-T 1, S-U 5, T-U 3.

    1. 9
    2. 10
    3. 8
    4. 7
    Show answer

    Answer: C. 8

    Dijkstra finalises P (0), R (1), Q (2, via R), S (4, via Q), T (5, via S) and U. U is reached from T at 5 + 3 = 8, which beats S + 5 = 9. Path: P-R-Q-S-T-U.

  9. Run Dijkstra's algorithm from P on the network below. In what order are the nodes made permanent? Links and costs: P-Q 3, P-R 1, R-Q 1, Q-S 2, R-S 6, R-T 5, S-T 1, S-U 5, T-U 3.

    1. P, R, Q, T, S, U
    2. P, Q, R, S, T, U
    3. P, R, Q, S, T, U
    4. P, R, T, Q, S, U
    Show answer

    Answer: C. P, R, Q, S, T, U

    Each step makes permanent the closest tentative node: P 0, R 1, Q 2 (through R, beating the direct 3), S 4 (Q + 2), T 5 (S + 1, beating R + 5 = 6), and finally U 8.

  10. With OSPF's default reference bandwidth of 100 Mbps, a path uses two 100 Mbps links and another uses one 10 Mbps link. What are their costs?

    1. 2 and 10
    2. 200 and 10
    3. 1 and 10
    4. 2 and 1
    Show answer

    Answer: A. 2 and 10

    OSPF cost = reference bandwidth / link bandwidth. A 100 Mbps link costs 100 / 100 = 1, so two of them cost 2. A 10 Mbps link costs 100 / 10 = 10. OSPF picks the two-link path; RIP would pick the one-hop path.

FAQs

Is Dijkstra or Bellman-Ford better?

Neither is better in every case. Dijkstra is faster on a full map but needs non-negative costs, which routing always has. Bellman-Ford works with only neighbour information, which makes it natural for distance-vector routing, but convergence across a network is slower.

Why does RIP stop at 15 hops?

A small infinity (16) limits how long count-to-infinity can run. The price is that RIP cannot route across networks wider than 15 hops, which is one reason large networks use OSPF.

Is BGP a distance-vector protocol?

It is usually called a path-vector protocol. Like distance vector, it exchanges routes with neighbours, but each route carries the full list of autonomous systems it has crossed. That list prevents loops and lets operators apply policy.

Next step

Practise the addressing that routing tables use in subnetting practice, revise the Network Layer MCQs, return to the Networks & Cloud hub, or try a timed NSCT mock test.