On Tue, Mar 28, 2017 at 03:56:16PM +0100, Elo Okonkwo wrote:
> Can someone pls explain this Merge Sort Algorithm, especially the Recursive
> bit of it.
Take a pack of cards and shuffle them. Now you want to sort the cards.
Put the cards down in a pile in front of you and think about sorting it.
On 28/03/17 15:56, Elo Okonkwo wrote:
> Can someone pls explain this Merge Sort Algorithm,
You can try reading this generic explanation.
It's not Python but the explanation seems fairly clear.
http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Sorting/mergeSort.htm
HTH
--
Alan G
Au
On 28/03/17 17:45, Rafael Knuth wrote:
> Question: When should I use functions?
> When should I use classes?
Thee is no definitive answer but here are some
guidelines:
1) Many instances -> class
2) Many methods sharing the same data -> class
3) An algorithm that has no side effects -> a function
This is the Result of that of the Merge Sort Function:
I have never been more confused!!, practically spent the whole day on
this piece of code:
Splitting [54, 26, 93, 17, 77, 31, 44, 55, 20]
Splitting [54, 26, 93, 17]
Splitting [54, 26]
Splitting [54]
Merging [54]
Splitting [26]
Merging [2
This is the Result form that piece of code:
Splitting [54, 26, 93, 17, 77, 31, 44, 55, 20]
Splitting [54, 26, 93, 17]
Splitting [54, 26]
Splitting [54]
Merging [54]
Splitting [26]
Merging [26]
Merging [26, 54]
Splitting [93, 17]
Splitting [93]
Merging [93]
Splitting [17]
Merging [17]
Can someone pls explain this Merge Sort Algorithm, especially the Recursive
bit of it.
def mergeSort(alist):
print("Splitting ",alist)
if len(alist)>1:
mid = len(alist)//2
lefthalf = alist[:mid]
righthalf = alist[mid:]
mergeSort(lefthalf)
mergeSort(
Question: When should I use functions?
When should I use classes?
I wrote my program twice: as a function and as a class (I did so for
educational purposes, to better understand both concepts).
Both programs do exactly the same, and the work neatly. Can you advise
when I should use functions and