The material that was covered this week was alright. The proofs for finding whether some function is in the big O of another function seemed straight forward. It actually took me a while to understand big O or Omega because of my lack of focus during lectures. It doesn't seem that hard when professor Heap is doing the proofs, but when it comes down to me doing the proof it might feel different and possibly confusing. I wasn't quite sure how I did on the quiz this week. I'm hoping for a 2/2 since I haven't got that in a while. As well, I was quite satisfied with my test mark and my assignment mark. I just need to ace the next two quizzes to make up for my poorly done quizzes.
For my mathematical problem, I have written some python code to solve this. So the way I thought of this was to make a while loop inside a for loop. And this would generate a whole bunch of lists. Each list would contain only one element from L and so when the while loop executes it will append values to the list that are greater than the previously appended value. Afterwards, I made a for loop that would find the list with the longest length and that list would be the greatest non-decreasing sub-sequence. Something I could change is if there are multiple lists with the same length. I guess I could take the list with the greatest length and greatest sum.
So here is my code to solving the greatest non-decreasing sub-sequence:
def longest(L):
size = 0
_list = []
list_all = []
for x in range(len(L)):
_list.append(L[x])
temp = L[x]
ind = x
while ind + 1 != len(L):
if L[ind + 1] > temp:
temp = L[ind + 1]
_list.append(L[ind + 1])
ind += 1
list_all.append(_list)
_list = []
for i in list_all:
if size < len(i):
size = len(i)
long = i
return long
No comments:
Post a Comment