FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/Maths/FindMinRecursion.java at master · java66liu/Java · GitHub
java66liu
/
Java
Public
forked from
TheAlgorithms/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
Maths
/
FindMinRecursion.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (26 loc) · 928 Bytes
Breadcrumbs
Java
/
Maths
/
FindMinRecursion.java
Copy path
File metadata and controls
32 lines (26 loc) · 928 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package
Maths
;
public
class
FindMinRecursion
{
public
static
void
main
(
String
[]
args
) {
int
[]
array
= {
2
,
4
,
9
,
7
,
19
,
94
,
5
};
int
low
=
0
;
int
high
=
array
.
length
-
1
;
System
.
out
.
println
(
"min value is "
+
min
(
array
,
low
,
high
));
}
/**
* Get min of array using divide and conquer algorithm
*
* @param array contains elements
* @param low the index of the first element
* @param high the index of the last element
* @return min of {@code array}
*/
public
static
int
min
(
int
[]
array
,
int
low
,
int
high
) {
if
(
low
==
high
) {
return
array
[
low
];
//or array[high]
}
int
mid
= (
low
+
high
) >>>
1
;
int
leftMin
=
min
(
array
,
low
,
mid
);
//get min in [low, mid]
int
rightMin
=
min
(
array
,
mid
+
1
,
high
);
//get min in [mid+1, high]
return
leftMin
<=
rightMin
?
leftMin
:
rightMin
;
}
}
Back
|
FazBrowse Home
|
New Git URL