I need to get the largest number in an array recursively
I was trying to find the largest in array of doubles but, the hard part is that you have to divide the array in two slices which I did, but after that you need to compute the largest values of the 2 sub slices and return the largest of the 2 values, and it needs to be using recursion.
Can you give me a tip in how to start please.
public static double getLargest(double a, int low, int high)
{
int c = (low+high)/2;
double slice1 = Arrays.copyOfRange(a, low,c + 1 );
double slice2 = Arrays.copyOfRange(a,c , high+1);
if(low > high || high > a.length-1 ||low < 0 )
throw new IllegalArgumentException();
if(low == high )
return a[low];
else{
}
}
}
java arrays
|
show 2 more comments
I was trying to find the largest in array of doubles but, the hard part is that you have to divide the array in two slices which I did, but after that you need to compute the largest values of the 2 sub slices and return the largest of the 2 values, and it needs to be using recursion.
Can you give me a tip in how to start please.
public static double getLargest(double a, int low, int high)
{
int c = (low+high)/2;
double slice1 = Arrays.copyOfRange(a, low,c + 1 );
double slice2 = Arrays.copyOfRange(a,c , high+1);
if(low > high || high > a.length-1 ||low < 0 )
throw new IllegalArgumentException();
if(low == high )
return a[low];
else{
}
}
}
java arrays
i dont have any idea how to begin, i been the whole day trying to solve this problem
– Omar Gonzalez
Nov 3 '15 at 1:45
3
I don't see any recursion in the posted code.
– JimN
Nov 3 '15 at 1:56
This is conceptually very close to this, maybe you can get inspiration: stackoverflow.com/questions/28932314/…
– Thilo
Nov 3 '15 at 1:57
3
I would suggest that you don't copy the array. Instead just pass the bounds as indices to the method.
– ChiefTwoPencils
Nov 3 '15 at 2:02
@Thilo Yes both questions are conspicuously similar, with identical variable names and similar whitespace peculiarities. Both users are of the same ethnicity too. Two students from the same high school asking homework questions? :)
– Joe Coder
Nov 3 '15 at 2:54
|
show 2 more comments
I was trying to find the largest in array of doubles but, the hard part is that you have to divide the array in two slices which I did, but after that you need to compute the largest values of the 2 sub slices and return the largest of the 2 values, and it needs to be using recursion.
Can you give me a tip in how to start please.
public static double getLargest(double a, int low, int high)
{
int c = (low+high)/2;
double slice1 = Arrays.copyOfRange(a, low,c + 1 );
double slice2 = Arrays.copyOfRange(a,c , high+1);
if(low > high || high > a.length-1 ||low < 0 )
throw new IllegalArgumentException();
if(low == high )
return a[low];
else{
}
}
}
java arrays
I was trying to find the largest in array of doubles but, the hard part is that you have to divide the array in two slices which I did, but after that you need to compute the largest values of the 2 sub slices and return the largest of the 2 values, and it needs to be using recursion.
Can you give me a tip in how to start please.
public static double getLargest(double a, int low, int high)
{
int c = (low+high)/2;
double slice1 = Arrays.copyOfRange(a, low,c + 1 );
double slice2 = Arrays.copyOfRange(a,c , high+1);
if(low > high || high > a.length-1 ||low < 0 )
throw new IllegalArgumentException();
if(low == high )
return a[low];
else{
}
}
}
java arrays
java arrays
edited Nov 22 '18 at 3:52
Cœur
18.2k9108148
18.2k9108148
asked Nov 3 '15 at 1:44
Omar GonzalezOmar Gonzalez
112
112
i dont have any idea how to begin, i been the whole day trying to solve this problem
– Omar Gonzalez
Nov 3 '15 at 1:45
3
I don't see any recursion in the posted code.
– JimN
Nov 3 '15 at 1:56
This is conceptually very close to this, maybe you can get inspiration: stackoverflow.com/questions/28932314/…
– Thilo
Nov 3 '15 at 1:57
3
I would suggest that you don't copy the array. Instead just pass the bounds as indices to the method.
– ChiefTwoPencils
Nov 3 '15 at 2:02
@Thilo Yes both questions are conspicuously similar, with identical variable names and similar whitespace peculiarities. Both users are of the same ethnicity too. Two students from the same high school asking homework questions? :)
– Joe Coder
Nov 3 '15 at 2:54
|
show 2 more comments
i dont have any idea how to begin, i been the whole day trying to solve this problem
– Omar Gonzalez
Nov 3 '15 at 1:45
3
I don't see any recursion in the posted code.
– JimN
Nov 3 '15 at 1:56
This is conceptually very close to this, maybe you can get inspiration: stackoverflow.com/questions/28932314/…
– Thilo
Nov 3 '15 at 1:57
3
I would suggest that you don't copy the array. Instead just pass the bounds as indices to the method.
– ChiefTwoPencils
Nov 3 '15 at 2:02
@Thilo Yes both questions are conspicuously similar, with identical variable names and similar whitespace peculiarities. Both users are of the same ethnicity too. Two students from the same high school asking homework questions? :)
– Joe Coder
Nov 3 '15 at 2:54
i dont have any idea how to begin, i been the whole day trying to solve this problem
– Omar Gonzalez
Nov 3 '15 at 1:45
i dont have any idea how to begin, i been the whole day trying to solve this problem
– Omar Gonzalez
Nov 3 '15 at 1:45
3
3
I don't see any recursion in the posted code.
– JimN
Nov 3 '15 at 1:56
I don't see any recursion in the posted code.
– JimN
Nov 3 '15 at 1:56
This is conceptually very close to this, maybe you can get inspiration: stackoverflow.com/questions/28932314/…
– Thilo
Nov 3 '15 at 1:57
This is conceptually very close to this, maybe you can get inspiration: stackoverflow.com/questions/28932314/…
– Thilo
Nov 3 '15 at 1:57
3
3
I would suggest that you don't copy the array. Instead just pass the bounds as indices to the method.
– ChiefTwoPencils
Nov 3 '15 at 2:02
I would suggest that you don't copy the array. Instead just pass the bounds as indices to the method.
– ChiefTwoPencils
Nov 3 '15 at 2:02
@Thilo Yes both questions are conspicuously similar, with identical variable names and similar whitespace peculiarities. Both users are of the same ethnicity too. Two students from the same high school asking homework questions? :)
– Joe Coder
Nov 3 '15 at 2:54
@Thilo Yes both questions are conspicuously similar, with identical variable names and similar whitespace peculiarities. Both users are of the same ethnicity too. Two students from the same high school asking homework questions? :)
– Joe Coder
Nov 3 '15 at 2:54
|
show 2 more comments
1 Answer
1
active
oldest
votes
You have to ask yourself what to do in that else
part.
You are now faced with an array of two or more elements.
You could say:
- find the maximum of the first half of that array (by calling the same method again, i.e. recursion, but with a "shorter" input array)
- find the maximum of the second half of that array
- return the bigger of these two results
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33490081%2fi-need-to-get-the-largest-number-in-an-array-recursively%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have to ask yourself what to do in that else
part.
You are now faced with an array of two or more elements.
You could say:
- find the maximum of the first half of that array (by calling the same method again, i.e. recursion, but with a "shorter" input array)
- find the maximum of the second half of that array
- return the bigger of these two results
add a comment |
You have to ask yourself what to do in that else
part.
You are now faced with an array of two or more elements.
You could say:
- find the maximum of the first half of that array (by calling the same method again, i.e. recursion, but with a "shorter" input array)
- find the maximum of the second half of that array
- return the bigger of these two results
add a comment |
You have to ask yourself what to do in that else
part.
You are now faced with an array of two or more elements.
You could say:
- find the maximum of the first half of that array (by calling the same method again, i.e. recursion, but with a "shorter" input array)
- find the maximum of the second half of that array
- return the bigger of these two results
You have to ask yourself what to do in that else
part.
You are now faced with an array of two or more elements.
You could say:
- find the maximum of the first half of that array (by calling the same method again, i.e. recursion, but with a "shorter" input array)
- find the maximum of the second half of that array
- return the bigger of these two results
answered Nov 3 '15 at 3:00
ThiloThilo
195k78420575
195k78420575
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33490081%2fi-need-to-get-the-largest-number-in-an-array-recursively%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
i dont have any idea how to begin, i been the whole day trying to solve this problem
– Omar Gonzalez
Nov 3 '15 at 1:45
3
I don't see any recursion in the posted code.
– JimN
Nov 3 '15 at 1:56
This is conceptually very close to this, maybe you can get inspiration: stackoverflow.com/questions/28932314/…
– Thilo
Nov 3 '15 at 1:57
3
I would suggest that you don't copy the array. Instead just pass the bounds as indices to the method.
– ChiefTwoPencils
Nov 3 '15 at 2:02
@Thilo Yes both questions are conspicuously similar, with identical variable names and similar whitespace peculiarities. Both users are of the same ethnicity too. Two students from the same high school asking homework questions? :)
– Joe Coder
Nov 3 '15 at 2:54