-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcode_3.py
40 lines (31 loc) · 918 Bytes
/
code_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
main.py
Algorithm
Created by Mohd Shoaib Rayeen on 31/07/18.
Copyright © 2018 Shoaib Rayeen. All rights reserved.
"""
def CeilIndex(A, l, r, key):
while (r - l > 1):
m = l + (r - l)//2
if (A[m] >= key):
r = m
else:
l = m
return r
def LongestIncreasingSubsequenceLength(A, size):
tailTable = [0 for i in range(size+1)]
len=0
tailTable[0] = A[0]
len = 1
for i in range(1, size):
if (A[i] < tailTable[0]):
tailTable[0] = A[i]
elif (A[i] > tailTable[len-1]):
tailTable[len] = A[i]
len+=1
else:
tailTable[CeilIndex(tailTable, -1, len-1, A[i])] = A[i]
return len
A = [ 2, 5, 3, 7, 11, 8, 10, 13, 6 ]
n =len(A)
print("Length of Longest Increasing Subsequence is ", LongestIncreasingSubsequenceLength(A, n))