r out i ng pr ot oc ol . Rout i ng pr ot oc ol s use r out i ng al gor i t hms. J ob of a r out i ng al gor i t hm: Gi ven a set of r out er s w i t h l i nk s c onnec t i ng t he r out er s, f i nd a good pat h f r om t he sour c e t o t he dest i nat i on. Model i ng a Net w or k A net w or k c an be model ed by a gr aph. - Rout er s/sw i t c hes ar e r epr esent ed by nodes. - Physi c al l i nk s bet w een r out er s/sw i t c hes ar e r epr esent ed by edges. - At t ac hed c omput er s ar e i gnor ed. - Eac h edge i s assi gned a w ei ght r epr esent i ng t he c ost of sendi ng a pac k et ac r oss t hat l i nk . The t ot al c ost of a pat h i s t he sum of t he c ost s of t he edges. The pr obl em i s t o f i nd t he l east -c ost pat h. Rout i ng Al gor i t hms Rout i ng al gor i t hms t hat sol ve a r out i ng pr obl em ar e based on shor t est -pat h al gor i t hms. Tw o c ommon shor t est -pat h al gor i t hms ar e Di j k st r as Al gor i t hm and t he Bel l man-For d Al gor i t hm. Rout i ng al gor i t hms f al l i nt o t w o gener al c at egor i es. Li nk -St at e Al gor i t hms The net w or k t opol ogy and al l l i nk c ost s ar e k now n. Ex ampl e: Di j k st r as Al gor i t hm. Mor e c ompl ex of t he t w o t ypes. Nodes per f or m i ndependent c omput at i ons. Used i n Open Shor t est Pat h Fi r st (OSPF) pr ot oc ol , a pr ot oc ol i nt ended t o r epl ac e RI P. Di st anc e-Vec t or Al gor i t hms Nodes r ec ei ve i nf or mat i on f r om t hei r di r ec t l y at t ac hed nei ghbor s. Ex ampl e: Bel l man-For d Al gor i t hm. Si mpl er of t he t w o t ypes. May have c onver genc e pr obl ems. Used i n Rout i ng I nf or mat i on Pr ot oc ol (RI P). Di j k st r as Al gor i t hm Named af t er E. W. Di j k st r a. Fai r l y ef f i c i ent . I t er at i ve al gor i t hm. At t he f i r st i t er at i on, t he al gor i t hm f i nds t he c l osest node f r om t he sour c e node w hi c h must be a nei ghbor of t he sour c e node. At t he sec ond i t er at i on, t he al gor i t hm f i nds t he sec ond-c l osest node f r om t he sour c e node. Thi s node must be a nei ghbor of ei t her t he sour c e node or t he c l osest node f ound i n t he f i r st i t er at i on. Di j k st r as Al gor i t hm At t he t hi r d i t er at i on, t he al gor i t hm f i nds t he t hi r d-c l osest node f r om t he sour c e node. Thi s node must be a nei ghbor of ei t her t he sour c e node or one of t he f i r st t w o c l osest nodes. The pr oc ess c ont i nues. At t he k t h i t er at i on, t he al gor i t hm f i nds t he f i r st k c l osest nodes f r om t he sour c e node. Ex ampl e The sour c e node i s s = 1. Ex ampl e The bot t om ent r y i n eac h D-c ol umn i s t he mi ni mum c ost t o go f r om t he st ar t node 1 t o t hat node. Quest i on: How c an you det er mi ne t he pat h w hi c h gi ves t he mi ni mum c ost t o a dest i nat i on node? Answ er : The t abl e not onl y gi ves t he mi ni mum c ost s. I t al so gi ves t he pr edec essor node of eac h node al ong a l east -c ost pat h f r om t he sour c e node. By k eepi ng t r ac k of t he pr edec essor nodes, w e c an c onst r uc t a l east -c ost pat h. Least -Cost Pat h Tr ee Rout i ng Tabl e f or Sour c e Node 1 Compl ex i t y of Di j k st r as Al gor i t hm Suppose t her e ar e n nodes not c ount i ng t he sour c e node. I n t he f i r st i t er at i on, w e need t o sear c h t hr ough n nodes t o det er mi ne t he node not i n N w i t h mi ni mum c ost . I n t he sec ond i t er at i on, w e need t o c hec k n1 nodes. I n t he t hi r d i t er at i on, n2 nodes. And so on. Compl ex i t y of Di j k st r as Al gor i t hm The t ot al number of nodes w e need t o ex ami ne i s 1 + 2 + 3 + + n = n(n+1)/2 Thus, Di j k st r as Al gor i t hm as pr esent ed i s O(n 2 ) A mor e sophi st i c at ed i mpl ement at i on of t he sec ond st ep usi ng a heap w oul d f i nd t he mi ni mum i n l ogar i t hmi c i nst ead of l i near t i me. Thi s i mpr oves t he per f or manc e t o O(n l og n)