# Q5(c) · Longest-prefix matching

Subject: Computer Networks

Exam: TEE

Reader: https://deep-learning-study-room.vercel.app/cn/#tee/papers/paper-2024-ai-final/q5c

Canonical: https://deep-learning-study-room.vercel.app/read/cn/tee/papers/paper-2024-ai-final--q5c/

Exact historical variant. Current-syllabus questions solved; excluded topics and source limitations stated.

### Q5(c). An 8-bit forwarding table maps prefixes 01→interface1, 10→2, 011→3, 100→4, 001→5, otherwise→6. Determine interfaces for destinations (1)00111101, (2)01010101, (3)11001001 using longest-prefix matching. [5 marks]

### Answer

### Given

Prefixes01→1,10→2,011→3,100→4,001→5,default→6.

### To find

Output interface for each destination.

### Formula and why

Among matching prefixes choose the one with the most bits; use default only when none match.

The leading bits must match from the first bit; a substring appearing later does not count.

### Solution

### Step 1. Compare each destination from the left

| Destination | Matching prefixes | Longest | Interface |
| --- | --- | --- | --- |
| 00111101 | 001 | 001 | 5 |
| 01010101 | 01 (but not011) | 01 | 1 |
| 11001001 | None | Default | 6 |

### Step 2. Write final order

**5, 1, 6.**
