SHARE
TWEET

Untitled

a guest Jan 14th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. \KwIn{A matrix $A$ of size $n \times m$}
  2.     \KwOut{A column index $i$ representing the location of the tallest building.}
  3.     \tcc{Initialize location variable.}
  4.     $tallestLocation \gets 0$
  5.    
  6.     $tallestHeight \gets 0$
  7.    
  8.     \For{$i \in \{0,\ldots,m-1\}$}{
  9.         \tcc{Use binary search to get the height of the column and compare it to the current tallest height}
  10.         \tcc{Now choose an index p to partition around}
  11.         $p \gets  \lfloor n/2 \rfloor$
  12.        
  13.         \While{$p \leq n-1$ \text{and} $p \geq 0$} {
  14.             \If {$A[i, p] = 0$} {
  15.                 \tcc{Height found}
  16.                 \If {the number above = 1 OR $p = n-1$ OR $p=0$} {
  17.                     \If {$p \geq tallestHeight$} {
  18.                         $tallestHeight \gets j$
  19.                        
  20.                         $tallestLocation \gets i$
  21.                     }
  22.                     break out of while loop
  23.                 }
  24.                 \Else {
  25.                     \tcc{Set new partition point}
  26.                     $p \gets midpoint of $
  27.                 }
  28.             }
  29.         }
  30.     }
  31.     \caption{\textsc{findTallest1} returns the location of the tallest building.}\label{alg:alg2}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top