Skip to content

Conversation

yesIamHasi
Copy link
Contributor

Thank you very much for pointing that out. I am really sorry I accidentally uploaded the wrong file last time. The changes you made didn't worked for some inputs. This one works fine.

@harshildarji
Copy link
Member

Hello @yesIamHasi, It would be really helpful if you could you please let use know about the inputs for which current code is not working as expected?

# Basic Test
LIST = [0,5,2,4,3,9,1,7,6,8]
print ('Unordered list {}'.format(LIST))
print ('Merge sorted list {}'.format(merge_sort(LIST)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we store the merge_sort(LIST) into some variable and then use it at multiple places?

Copy link
Member

@AnshulMalik AnshulMalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the current implementation is of merge sort.
Merge sort runs in O(nlogn) time, whereas current implementation will require O(n2).

finding min and max element and removing it is a really costly process.

'''
# These modules are required for testing only.
import random, copy
import matplotlib.pyplot as plt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, it's nice to see the output as graph, it really helps in visualising the data. But I think it's not required here. We can just test for the output.

Copy link

@christianbender christianbender Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnshulMalik
good point! The function min and max have O(n). And this runtime is dominant.
The graphic output is nice feature I would retain it.

Copy link

@christianbender christianbender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Work! I have a suggestion.

'''
Plots unsorted and sorted data.
'''
plt.plot(LIST)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the code like this:

figure1 = plt.figure(1) plt.plot(LIST) plt.xlabel('Random Data') figure1.show() figure2 = plt.figure(2) plt.plot(SORTED_LIST) plt.xlabel('Merge Sorted Data') figure2.show() raw_input() # keeps the figures alive

With the code above it show up two figures parallel at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 participants