Floyd’s algorithm finds shortest path between all pairs.
push(1), push(2), pop, push(1), push(2), pop, pop, pop, push(2), pop.
The sequence of popped out values are:
Start: []
push(1) → [1]
push(2) → [1,2]
pop → 2 → [1]
push(1) → [1,1]
push(2) → [1,1,2]
pop → 2 → [1,1]
pop → 1 → [1]
pop → 1 → []
push(2) → [2]
pop → 2 → []
Popped sequence: 2,2,1,1,2
Minimum nodes follow Fibonacci relation:
$N(h)=N(h-1)+N(h-2)+1$
$N(6)=20$
Online Test Series, Information About Examination,
Syllabus, Notification
and More.
Online Test Series, Information About Examination,
Syllabus, Notification
and More.