Skip to content

Commit

Permalink
Merge pull request TheAlgorithms#62 from dhruvsaini/patch-4
Browse files Browse the repository at this point in the history
Create longest_increasing_subsequence.py
  • Loading branch information
harshildarji authored Jan 3, 2017
2 parents bdde826 + 436edf3 commit 6f9d65f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dynamic_programming/longest_increasing_subsequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order. For example, the length of LIS for {10, 22, 9, 33, 21, 50, 41, 60, 80} is 6
"""
def LIS(arr):
n= len(arr)
lis = [1]*n

for i in range(1, n):
for j in range(0, i):
if arr[i] > arr[j] and lis[i] <= lis[j]:
lis[i] = lis[j] + 1
return max(lis)

0 comments on commit 6f9d65f

Please sign in to comment.