I'm having a bit of difficulty trying to implement the longest increasing subsequence algorithm. I found a <<crapware site>> online that looks helpful, but I'm having trouble translating the pseudocode into code.
I'm using Python, and I've written the following function:
Code:
def longest_increasing_subsequence(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] + 1 :
lis[i] = lis[j]+1
maximum = 0
for i in range(n):
maximum = max(maximum, lis[i])
return maximum
When I try to run the code, I get the following error:
Code:
NameError: name 'arr' is not defined
I'm not sure what I'm doing wrong. Any help would be appreciated!
Thank you.