[Chicago] Not exactly a solution, but....
Lewit, Douglas
d-lewit at neiu.edu
Mon Jun 15 13:31:38 CEST 2015
Brad,
You're a genius! That last email helped me fix my original program.
Hooray!!! In this version I included a million comments because I'm going
to email this to a professor who really doesn't know Python that well. So
the comments may help him to interpret the code a little better. The only
"problem" is that my mergeSort program doesn't change the array "in
place". Not a big deal really. To permanently change the array you would
just do this:
array = [randint(0, 100) for i in range(20)] #### for example
array = mergeSort(array)
And presto! It works!
The searching and sorting stuff is very cool and challenging, but I still
wish that CS professors would also teach some practical stuff, such as web
development and internet security, etc, etc. I've noticed that if you're a
CS major they make you struggle through about 2 years of purely academic
and theoretical stuff before they start teaching the skills needed for
employment as a computer professional. I mean the Merge Sort algorithm is
interesting, and I can see its value, but it would be nice if my professors
at the university would teach me how to test a website for security
weaknesses and practical stuff like that. Oh well. Maybe next semester,
right?
Again Brad, I really appreciate your help. I love you guys at ChiPy!
Take care and have a great week.
Best,
Douglas.
P.S. Regarding merge*S*ort vs. merge*s*ort, after three semesters of Java
programming at Northeastern it's the naming style that I've gotten used
to. Probably not really a big deal, right? It's just a matter of personal
preference.
On Mon, Jun 15, 2015 at 6:08 AM, Brad Martsberger <bradley.marts at gmail.com>
wrote:
> In fact, the algorithm that you implemented in this code is insertion
> sort. On each iteration you are "merging" a single element with a sorted
> list of your previously merged elements. That is, you insert a single
> element into your growing sorted list. This algorithm has time complexity
> O(n^2), mergesort will have time complexity O(n log n).
>
> Brad
>
> On Mon, Jun 15, 2015 at 2:29 AM, Lewit, Douglas <d-lewit at neiu.edu> wrote:
>
>> I sort of got my mergeSort program to work, but the problem is that the
>> algorithm isn't really mergeSort at all! It uses merge, but my algorithm
>> is iterative rather than recursive, so it's not really a mergeSort. It's a
>> merge-something, but not true mergeSort. Oh well. Any suggestions?
>> Thanks!
>>
>> Best,
>>
>> Douglas.
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> https://mail.python.org/mailman/listinfo/chicago
>>
>>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20150615/f7852f24/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MergeSort.py
Type: text/x-python-script
Size: 1562 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/chicago/attachments/20150615/f7852f24/attachment.bin>
More information about the Chicago
mailing list