Structural Graph Coverage · Week 2

Tour, Sidetrip & Detour

Ek test path kisi sub-path ko "tour" kaise karta hai — seedhe, ghoom ke (sidetrip), ya raasta badalke (detour). Isi question ka poora breakdown.

GRAPH Jis graph pe kaam kar rahe hain

1 2 3 4 5 6 7

Nodes & edges

N = {1,2,3,4,5,6,7} · start 1 · final 7 (double circle).

1→21→72→3 2→43→24→5 4→65→66→1

Loops: chhota loop 2⇄3, aur bada loop 1→2→4→6→1. Isliye graph cyclic hai.

Buttons dabao — graph pe sidetrip aur detour highlight ho jayenge.

IDEA Teen tarah ka "tour"

Maano hume ek sub-path q ko test path p ke andar "cover" (tour) karna hai. 3 tareeke:

1 · Direct tour

p me q hu-ba-hu, lagataar (contiguous) aata ho. Beech me koi ghumaav nahi.

Rule: q, p ka seedha subpath ho. Sabse strict.

2 · Tour with sidetrip

p, q ke beech se ghoom ke wapas usi node pe aa sakta hai, phir aage badhta hai. Ghumaav = sidetrip.

Rule: q ki har EDGE p me same order me maujood ho. Sidetrip usi node pe return karta hai jahan se nikla.

3 · Tour with detour

p, q ke ek node se nikal ke agle node pe (dusre raaste se) pahunch jaye — beech wali edge chhod ke. Ghumaav = detour.

Rule: q ke har NODE p me same order me maujood ho. Detour agle node pe return karta hai (ek edge skip). Sabse lenient.

🔑 Asli farak — return kahan hota hai:

Sidetrip → node X se nikla, wapas X pe (same node). q ki saari edges bachi rehti hain

Detour → node X se nikla, wapas agle node Y pe. Edge X→Y skip ho jaati hai ✗

VS Sidetrip vs Detour — ek nazar me

CheezSidetripDetour
Kya match hona chahiyeq ki har edgeq ka har node
Ghumaav kahan return kartaUsi node pe (same)Agle node pe (next)
q ki edges bachti hain?Haan, saari ✓Nahi, ek edge skip ✗
Kitna strictZyada strictZyada lenient

Order of strength: Direct (strictest) ⊃ SidetripDetour (loosest). Jo sidetrip se tour hota hai wo detour se bhi hota hai — ulta zaroori nahi.

PATHS Do test paths

P = 1232461245617
Q = 1245617

Dono valid paths hain (har jodi ek real edge hai). Ab options check karte hain.

SOLVE Har option ka faisla

A ✓ Correct

Claim: P tours sub-path [3,2,4,5,6] with the sidetrip [4,6,1,2,4].

P: 12 324 6124 56 17
spine = q ki edges (3→2→4 … 5→6) sidetrip (node 4 se nikla, node 4 pe wapas)

q ki edges 3→2, 2→4, 4→5, 5→6 saari P me order me hain. Bas node 4 pe pahunch ke P ek chakkar lagata hai 4→6→1→2→4 aur wapas usi node 4 pe aa jaata hai — yahi valid sidetrip hai. ✓

B ✗ Wrong

Claim: P tours [3,2,4,5,6] with the sidetrip [4,5,6,1,2].

Sidetrip ko usi node pe wapas aana zaroori hai. [4,5,6,1,2] node 4 se shuru hoke node 2 pe khatam hota hai — same node nahi! Isliye ye sidetrip ho hi nahi sakta. (Sahi sidetrip [4,6,1,2,4] tha.) ✗

C ✗ Wrong

Claim: Q tours [1,2,4,6,1,7] with the detour [3,2,4,6].

Q = [1,2,4,5,6,1,7] — isme node 3 aata hi nahi. Toh [3,2,4,6] wala detour Q me exist hi nahi karta. Impossible. ✗

D ✓ Correct

Claim: Q tours sub-path [1,2,4,6,1,7] with the detour [4,5,6].

Q: 124 5 617
spine = q ke nodes (1,2,4,6,1,7) detour (node 4 se nikla, agle node 6 pe wapas)

q chahta hai edge 4→6, par Q direct 4→6 kabhi nahi jaata — wo 4→5→6 se pahunchta hai. Yani node 4 se nikal ke agle node 6 pe (ek edge skip karke) aa gaya. Yahi detour [4,5,6] hai. q ke saare nodes order me hain, isliye tour valid. ✓

Ye sidetrip kyun nahi? Kyunki edge 4→6 Q me hai hi nahi — yani "saari edges present" wali sidetrip-condition fail hoti hai. Sirf nodes present hain → detour.

RECAP 20-second cheat sheet

Direct tour — q seedha p ke andar (contiguous). Strictest.

Sidetrip — har EDGE of q present · ghumaav same node pe return · [4,6,1,2,4] (4 se 4).

Detour — har NODE of q present · ghumaav agle node pe return, ek edge skip · [4,5,6] (4 se 6).

Test trick: pehle dekho ghumaav kahan return karta hai — same node → sidetrip, next node → detour.

Final answer: A aur D sahi hain.

Structural graph coverage · tour / sidetrip / detour · self-study explainer