Click here to Skip to main content
15,436,489 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
C#
void partition(int arr[],int low,int high){

    int mid;

    if(low<high){>
         mid=(low+high)/2;
         partition(arr,low,mid);    
         partition(arr,mid+1,high);
         
    }
}

in the above program is the first recursion will occur twice for the second recursion ? deduce me this two recursion process.

Any help is appreciated.
Thanks mahbub.
Posted
Updated 31-Dec-13 21:45pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Jan-14 3:55am     CRLF
What do you mean "how"? Exactly how it is written. You can deduce everything mentally or using the debugger. Otherwise, you approach is counter-productive. If this is not your code, this is even more counter-productive; then solve problems and write code by yourself, it will be millions times more useful. —SA
mahbubur rahman 1-Jan-14 4:02am     CRLF
i exactly mean if i use low=0;high=6; then how the steps works ?
Sergey Alexandrovich Kryukov 1-Jan-14 4:08am     CRLF
I just gave you an advice, please use it. —SA
Amarnath S 1-Jan-14 8:59am    
Can you not debug and check?

1 solution

We can't help you with this: we don't have access to your data which controls exactly what happens.

So you will have to do this yourself.
Start by putting a breakpoint on the first line in the function, and running your application. When it hits the breakpoint, write down what is in arr, low and high and single step through the code, watching what happens to the various variables.

However, in your example, pretty much nothing will happen, since all you do is recursively call the method with progressively smaller intervals until integer division means low and high work out the same...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900