<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 -- http://mail.python.org/mailman/listinfo/python-list