Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \KwIn{A matrix $A$ of size $n \times m$}
- \KwOut{A column index $i$ representing the location of the tallest building.}
- \tcc{Initialize location variable.}
- $tallestLocation \gets 0$
- $tallestHeight \gets 0$
- \For{$i \in \{0,\ldots,m-1\}$}{
- \tcc{Use binary search to get the height of the column and compare it to the current tallest height}
- \tcc{Now choose an index p to partition around}
- $p \gets \lfloor n/2 \rfloor$
- \While{$p \leq n-1$ \text{and} $p \geq 0$} {
- \If {$A[i, p] = 0$} {
- \tcc{Height found}
- \If {the number above = 1 OR $p = n-1$ OR $p=0$} {
- \If {$p \geq tallestHeight$} {
- $tallestHeight \gets j$
- $tallestLocation \gets i$
- }
- break out of while loop
- }
- \Else {
- \tcc{Set new partition point}
- $p \gets midpoint of $
- }
- }
- }
- }
- \caption{\textsc{findTallest1} returns the location of the tallest building.}\label{alg:alg2}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement