Skip to content

Commit

Permalink
LIS
Browse files Browse the repository at this point in the history
  • Loading branch information
idf committed Nov 22, 2016
1 parent 0597b45 commit c5d219a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions chapterSearch.tex
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,22 @@ \subsection{Extreme-value problems}\label{extremeValueProblem}
def LIS(self, A):
n = len(A)
MIN = [-1 for _ in xrange(n+1)]

l = 1
for i in xrange(1, n):
if A[i] > A[MIN[l]]:
l += 1
MIN[l] = i
else:
j = self.bin_search(MIN, A, A[i], 1, l+1)
MIN[j] = i

return l
k = 1
MIN[k] = A[0] # store value
for v in A[1:]:
idx = bisect.bisect_left(MIN, v, 1, k+1)
MIN[idx] = v
k += 1 if idx == k+1 else 0

return k
\end{python}
If need to return the LIS itself.
\begin{python}
n = len(A)
MIN = [-1 for _ in xrange(n+1)]
RET = [-1 for _ in xrange(n)]
l = 1
MIN[l] = 0 # store index
for i in xrange(1, n):
if A[i] > A[MIN[l]]:
l += 1
Expand Down
2 changes: 1 addition & 1 deletion chapterTree.tex
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ \subsection{Basic Operations}

Rightmost node can be similarly found.

\runinhead{Diameter of a tree.} The diameter of a tree $\equiv$ longest path in the tree.
\runinhead{Diameter of a tree (graph).} The diameter of a tree $\equiv$ longest path in the tree.

Core clues:
\begin{enumerate}
Expand Down

0 comments on commit c5d219a

Please sign in to comment.