SHARE
TWEET

Longest decreasing Subsequence

a guest Apr 20th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def LongestDecreasing(lista_in):
  2.     lista_out = []
  3.     c = 0
  4.     for element in lista_in:
  5.         if element < lista_out[-1]:
  6.             lista_out.append(element)
  7.         else:
  8.             binarySearch(lista_out,element)
  9.             lista_out[]
  10.  
  11.  
  12.  
  13.  
  14. def binarySearch(alist, item):
  15.     first = 0
  16.     last = len(alist)-1
  17.     found = False
  18.     while first<=last and not found:
  19.         midpoint = (first + last)//2
  20.         if alist[midpoint] == item:
  21.             found = True
  22.         else:
  23.             if item < alist[midpoint]:
  24.                 last = midpoint-1
  25.             else:
  26.                 first = midpoint+1
  27.  
  28.     return found
  29.  
  30. testlist = [0, 1, 2, 8, 13, 17, 19, 32, 42,]
  31. print(binarySearch(testlist, 3))
  32. print(binarySearch(testlist, 21))
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