Click here to Skip to main content
15,893,923 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Vehicle routing problem for large graph Pin
harold aptroot7-Mar-20 13:35
harold aptroot7-Mar-20 13:35 
GeneralRe: Vehicle routing problem for large graph Pin
Member 147325528-Mar-20 0:51
Member 147325528-Mar-20 0:51 
GeneralRe: Vehicle routing problem for large graph Pin
harold aptroot8-Mar-20 4:28
harold aptroot8-Mar-20 4:28 
GeneralRe: Vehicle routing problem for large graph Pin
Member 147325528-Mar-20 6:41
Member 147325528-Mar-20 6:41 
GeneralRe: Vehicle routing problem for large graph Pin
harold aptroot8-Mar-20 7:48
harold aptroot8-Mar-20 7:48 
GeneralRe: Vehicle routing problem for large graph Pin
Member 147325528-Mar-20 8:07
Member 147325528-Mar-20 8:07 
AnswerRe: Vehicle routing problem for large graph Pin
Hailu Worku Obsse17-Mar-20 20:15
professionalHailu Worku Obsse17-Mar-20 20:15 
QuestionRecursion Pin
Member 1475643326-Feb-20 10:10
Member 1475643326-Feb-20 10:10 
I'm confused about recursion in mergesort. I've tried putting comments in the code that track the variables so its easier to understand what's going on, but I'm still struggling.
For an array of size 4, I understand the initial process -
mergesort(o,3).
0 is less than 3, so we find the middle value = 1. Low = 0, Middle,1 and High = 3
mergesort(0,1)
0 is less than 1, so we find the middle value = 0. Low = 0, Middle = 0, High 1
0 is not < 0, so the function is called again but with (middle +1 and high) as its parameters.
1 is not < 1, so the function merge is called with the parameters (0,0,1).
So far so good ! Laugh | :laugh:
But when the recursive function kicks in again, this time it has the values (0,2,3) which has been passed to the second recursive function (middle +1, high) Confused | :confused: Confused | :confused: Confused | :confused: How did this happen ?? Is it because the second recursive function is using the same parameters as the first function on its second iteration? (0,1,3).
I've been looking all over for this, and lots of people just seem to skim over this step. I'm new, so would really appreciate any advice anyone has to give. I've tried experimenting with recursive functions, like finding the nth term in fib series, and sum of triangular numbers, which I can do now, but it doesnt seem to be helping in solving this problem.
Big thanks


	public void mergesort (int low, int high) {
		
		sum ++;
		
System.out.println("Round " + sum + ". Parameters being passed in = " + low + " " + middle + " " +high);
		if (low<high) {
			
			int middle = low + (high - low)/2;
			
			System.out.println("Checking left ---- if " + low + " is < " + high);
			System.out.println("Current value of high = " + high);
			System.out.println("Current value of mid = " + middle);
			System.out.println("low, mid and high =" + low + "" + middle + "" + high);
			System.out.println();
			
			mergesort(low,middle);
		
			System.out.println("low, mid and high =" + low + "" + middle + "" + high);
			
	
			mergesort(middle +1,high);
			System.out.println("Checking right ---- if " + (middle +1) + " is < " + high);
			System.out.println("low, mid and high =" + low + "" + middle + "" + high);
			merge(low,middle,high);
		}

AnswerRe: Recursion Pin
Daniel Pfeffer26-Feb-20 21:22
professionalDaniel Pfeffer26-Feb-20 21:22 
GeneralRe: Recursion Pin
Member 1475643326-Feb-20 22:39
Member 1475643326-Feb-20 22:39 
GeneralRe: Recursion Pin
Daniel Pfeffer26-Feb-20 23:25
professionalDaniel Pfeffer26-Feb-20 23:25 
GeneralRe: Recursion Pin
Member 1475643326-Feb-20 23:33
Member 1475643326-Feb-20 23:33 
QuestionNegating a number Pin
Nand3219-Feb-20 2:53
Nand3219-Feb-20 2:53 
AnswerRe: Negating a number PinPopular
Richard MacCutchan19-Feb-20 3:04
mveRichard MacCutchan19-Feb-20 3:04 
GeneralRe: Negating a number Pin
Nand3219-Feb-20 3:08
Nand3219-Feb-20 3:08 
GeneralRe: Negating a number Pin
Richard MacCutchan19-Feb-20 3:47
mveRichard MacCutchan19-Feb-20 3:47 
AnswerRe: Negating a number Pin
Richard Deeming19-Feb-20 3:23
mveRichard Deeming19-Feb-20 3:23 
GeneralRe: Negating a number Pin
Nand3219-Feb-20 3:32
Nand3219-Feb-20 3:32 
QuestionLALR vs LR parsing Pin
honey the codewitch13-Feb-20 3:53
mvahoney the codewitch13-Feb-20 3:53 
AnswerRe: LALR vs LR parsing Pin
Member 1298255823-Feb-20 6:45
Member 1298255823-Feb-20 6:45 
GeneralRe: LALR vs LR parsing Pin
honey the codewitch23-Feb-20 7:29
mvahoney the codewitch23-Feb-20 7:29 
QuestionRouting algorithm Pin
Rocks10028-Jan-20 8:23
Rocks10028-Jan-20 8:23 
AnswerRe: Routing algorithm Pin
Richard Deeming28-Jan-20 9:43
mveRichard Deeming28-Jan-20 9:43 
GeneralRe: Routing algorithm Pin
Rocks10028-Jan-20 10:11
Rocks10028-Jan-20 10:11 
GeneralRe: Routing algorithm Pin
Rocks10028-Jan-20 11:36
Rocks10028-Jan-20 11:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.