next up previous
Next: Up: Previous:

Pseudocode



List-Rank(L)
$\;\;\;\;\;$foreach processor i, in parallel $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; O(1)
$\;\;\;\;\;$ $\;\;\;\;\;$if next(i) = NIL
$\;\;\;\;\;$ $\;\;\;\;\;$then d(i) = 0
$\;\;\;\;\;$ $\;\;\;\;\;$else d(i) = 1
$\;\;\;\;\;$while next(i) $\neq$ NIL for some i $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; test
$\;\;\;\;\;$ $\;\;\;\;\;$foreach processor i, in parallel $\;\;\;\;\;$ $\;\;\;\;\;$; O(1)
$\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$if next(i) $\neq$ NIL $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; synchronize
$\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$then d(i) = d(i) + d(next(i))
$\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$next(i) = next(next(i))

Click mouse to advance to next frame.

List-Rank halves the lengths of the lists each time, thus O(lg n) times through while loop.

The algorithm has run time performance of \(\Theta(\lg n)\).


next up previous
Next: Up: Previous: