Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46449

Re: Can anyone please help me in understanding the following python code

From Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Subject Re: Can anyone please help me in understanding the following python code
Date 2013-05-30 10:17 +0000
References <921173f3-21e7-46b4-a7b1-86660a3ebc72@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2400.1369909052.3114.python-list@python.org> (permalink)

Show all headers | View raw


 <bhk755 <at> gmail.com> writes:
>
> 
> Function mergeSort is called only once, but it is getting recursively
executed after the printing the last
> statement "print("Merging ",alist)". But don't recursion taking place
except at these places
> "mergeSort(lefthalf), mergeSort(righthalf)"
> 
> Sometimes the function execution directly starts from i=0,j=0,k=0 . Not
sure how.

Maybe you should tell us first what output you would have expected.
It's not really clear from your question what confuses you. Doesn't the
algorithm do what it's supposed to do? When does the function start from
i=0, j=0, k=0 ? What exactly is the output then ?
Maybe you are confused by the fact that the algorithm is recursive twice. It
first goes through the lefthand branch, then only on its way out it works on
the righthand branch. So the recursion through mergeSort is not started only
once as you say, but twice (after finishing the recursion through
mergeSort(lefthand), another recursion is kicked off by calling
mergeSort(righthand).
Best,
Wolfgang

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Can anyone please help me in understanding the following python code bhk755@gmail.com - 2013-05-30 02:48 -0700
  Re: Can anyone please help me in understanding the following python code Chris Angelico <rosuav@gmail.com> - 2013-05-30 20:01 +1000
  Re: Can anyone please help me in understanding the following python code Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-05-30 10:17 +0000
  Re: Can anyone please help me in understanding the following python code bhk755@gmail.com - 2013-05-30 03:19 -0700
    Re: Can anyone please help me in understanding the following python	code Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-05-30 10:43 +0000
    Re: Can anyone please help me in understanding the following python code Chris Angelico <rosuav@gmail.com> - 2013-05-30 20:47 +1000
    Re: Can anyone please help me in understanding the following python code Joshua Landau <joshua.landau.ws@gmail.com> - 2013-05-30 12:11 +0100
  Re: Can anyone please help me in understanding the following python code Joshua Landau <joshua.landau.ws@gmail.com> - 2013-05-30 12:03 +0100
  Re: Can anyone please help me in understanding the following python code bhk755@gmail.com - 2013-05-30 05:39 -0700
    Re: Can anyone please help me in understanding the following python code bhk755@gmail.com - 2013-05-30 05:42 -0700
      Re: Can anyone please help me in understanding the following python code Dave Angel <davea@davea.name> - 2013-05-30 09:29 -0400
    Re: Can anyone please help me in understanding the following python code bhk755@gmail.com - 2013-05-30 05:42 -0700
    Re: Can anyone please help me in understanding the following python code Chris Angelico <rosuav@gmail.com> - 2013-05-30 22:55 +1000
  Re: Can anyone please help me in understanding the following python code bhk755@gmail.com - 2013-05-30 06:01 -0700
  Re: Can anyone please help me in understanding the following python code bhk755@gmail.com - 2013-05-30 21:53 -0700
  Re: Can anyone please help me in understanding the following python code bhk755@gmail.com - 2013-05-30 21:54 -0700
    Re: Can anyone please help me in understanding the following python code Cameron Simpson <cs@zip.com.au> - 2013-05-31 15:43 +1000
    Re: Can anyone please help me in understanding the following python code Chris Angelico <rosuav@gmail.com> - 2013-05-31 17:13 +1000
  Re: Can anyone please help me in understanding the following python code rusi <rustompmody@gmail.com> - 2013-06-01 10:43 -0700

csiph-web