[Chicago] Problems with Merge Sort???

Lewit, Douglas d-lewit at neiu.edu
Mon Jun 15 17:02:08 CEST 2015


Hey Aziz,

I'm not taking an online Python course right now.  I'm taking CS-404
(Analysis of Algorithms) at Northeastern Illinois University Professor
Kimmel.  The course is mostly math, but requires a little Java programming
on the side.  I asked Dr. Kimmel if I could implement some of the
algorithms in Python.  He said I could, but since he doesn't know Python he
won't be able to provide much guidance in that direction.

Here's my Merge Sort program.  It's attached to my email.  The sorted array
is returned, but the array is not sorted "in place".  If you want to save
the sorted array, that's easy enough to do.  Just override the original
array variable or create a new one.

Gotta run but thanks for the reply.  I hope you find my code helpful.  It
took me a lot of time to figure it out!  The merge method wasn't really
that hard for me.  But getting merge sort to work properly was definitely a
challenge.

Best,

Douglas.


On Mon, Jun 15, 2015 at 7:10 AM, Aziz Harrington <azizharrington at gmail.com>
wrote:

> Hi Douglas, I just worked through this problem myself over the weekend.
> are you doing this course by chance?
> http://interactivepython.org/runestone/static/pythonds/index.html
>
> Anyway, could you share a link to your code? Hard to make suggestions
> without seeing it.
>
> -Aziz
> Send Chicago mailing list submissions to
>         chicago at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/chicago
> or, via email, send a message with subject or body 'help' to
>         chicago-request at python.org
>
> You can reach the person managing the list at
>         chicago-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Chicago digest..."
>
>
> Today's Topics:
>
>    1. Re: Question about using Sympy. (Joshua Herman)
>    2. Problems with Merge Sort??? (Lewit, Douglas)
>    3. Not exactly a solution, but.... (Lewit, Douglas)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sun, 14 Jun 2015 19:38:03 -0500
> From: Joshua Herman <zitterbewegung at gmail.com>
> To: The Chicago Python Users Group <chicago at python.org>
> Subject: Re: [Chicago] Question about using Sympy.
> Message-ID:
>         <
> CAB3V1zmkq_Lj_nitb1PkZk+m6PtrH0Dq824zBVPBgWf7NbszxQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> >From the documentation
>
> http://docs.sympy.org/dev/modules/solvers/solvers.html#module-sympy.solvers.recurr
>
> On Thu, Jun 11, 2015 at 10:45 PM, Lewit, Douglas <d-lewit at neiu.edu> wrote:
>
> > Hi there Chipy Folks,
> >
> > Just wondering if the sympy module has a builtin routine for solving
> > recurrence relations.  If you know, please enlighten me.  I know that
> Maple
> > and Mathematica have such routines--and they are pretty impressive.  Just
> > wondering if the sympy module has something equivalent.
> >
> > Thanks and I hope everyone in the group has a fun weekend.  I'm looking
> > forward to Wednesday evening's meeting at Pumping Station One.  I'll be
> > arriving right after my second Algorithms exam, so there's a chance I
> won't
> > be in a very happy mood!  That course is just brutal.  The prof got his
> > undergrad degree at Harvard and his PhD. at the University of Chicago.  A
> > real genius.... and also extremely demanding!  So wish me luck on that
> > exam!   :-)
> >
> > Warm regards,
> >
> > Douglas.
> >
> > _______________________________________________
> > 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/20150614/bc7b713b/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Sun, 14 Jun 2015 23:31:24 -0500
> From: "Lewit, Douglas" <d-lewit at neiu.edu>
> To: The Chicago Python Users Group <chicago at python.org>
> Subject: [Chicago] Problems with Merge Sort???
> Message-ID:
>         <
> CAPdZZGz+U4FMwQZsvDbyWwmLp-t-pzWEK4GJwgO8q6aUsqD_xQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hey guys,
>
> I'm trying to master the merge sort algorithm and definitely experiencing
> some failure.  My merge program works great.  It takes two arrays, and
> assuming that they are already sorted, the two sorted arrays get merged
> together into one unified sorted array.  So that's not the problem.
>
> The problem is my mergeSort program.  I inserted a couple of print
> statements to print out the intermediate results of the recursion, and it
> appears that all my program does is break the array down into pieces and
> then rebuilds the pieces.... into the original array!  (Could be worse I
> guess.  No error messages!  But the output is totally useless.)  I'm
> honestly at a loss.  I know I'm really close to the right solution, but
> there is something that I'm missing and I can't figure it out.  I've been
> struggling with this for a couple days now, and I'm ready to give up.  Can
> someone please enlighten me?
>
> Thanks!!!
>
> Best,
>
> Douglas.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/chicago/attachments/20150614/c21eafaf/attachment-0001.html
> >
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: Merge.py
> Type: text/x-python-script
> Size: 1293 bytes
> Desc: not available
> URL: <
> http://mail.python.org/pipermail/chicago/attachments/20150614/c21eafaf/attachment-0001.bin
> >
>
> ------------------------------
>
> Message: 3
> Date: Mon, 15 Jun 2015 02:29:32 -0500
> From: "Lewit, Douglas" <d-lewit at neiu.edu>
> To: The Chicago Python Users Group <chicago at python.org>
> Subject: [Chicago] Not exactly a solution, but....
> Message-ID:
>         <
> CAPdZZGw4CTKHdZYAuoL-dii9_Y4UExKsV1jYhO_st3Gm7xW_0Q at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> 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.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/chicago/attachments/20150615/3ad294b5/attachment-0001.html
> >
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: Merge.py
> Type: text/x-python-script
> Size: 1287 bytes
> Desc: not available
> URL: <
> http://mail.python.org/pipermail/chicago/attachments/20150615/3ad294b5/attachment-0001.bin
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
> ------------------------------
>
> End of Chicago Digest, Vol 118, Issue 11
> ****************************************
>
> _______________________________________________
> 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/7d82cb81/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/7d82cb81/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MergeSort2.java
Type: application/octet-stream
Size: 3498 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/chicago/attachments/20150615/7d82cb81/attachment.obj>


More information about the Chicago mailing list