Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 016ae88

Browse files
committed
FEAT Implemented recursive method that returns floor of lg(N)
1 parent 469ae57 commit 016ae88

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎src/PracticeAlgorithms.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ public static int[][] matrixTransposition(int[][] theMatrix) {
7171
return transposedMatrix;
7272
}
7373

74+
/**
75+
* recursive method that returns the greatest integer not greater than log(N)
76+
* to base two
77+
* */
78+
public static int lg(int N) {
79+
if (N <= 1) return 0;
80+
81+
return 1 + lg(N / 2);
82+
}
83+
7484
public static void main(String[] args) {
7585
Random generator = new Random();
7686

@@ -107,5 +117,7 @@ public static void main(String[] args) {
107117
System.out.println("- Transposed");
108118
printTwoDmIntArray(matrixTransposition(testIntMatrix));
109119
System.out.println();
120+
121+
System.out.println(lg(32));
110122
}
111123
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /