MCPcopy Create free account
hub / github.com/apna-college/Alpha / optimizedPower

Method optimizedPower

7_RecursionBasics/RecursionBasics.java:95–105  ·  view source on GitHub ↗
(int x, int n)

Source from the content-addressed store, hash-verified

93 }
94
95 public static int optimizedPower(int x, int n) {
96 if(n == 0) {
97 return 1;
98 }
99
100 if(n % 2 == 0) { //even
101 return optimizedPower(x, n/2) * optimizedPower(x, n/2);
102 } else { //odd
103 return x * optimizedPower(x, n/2) * optimizedPower(x, n/2);
104 }
105 }
106
107 public static int tilingProblem(int n) { // 2 x n (floor size)
108 //base case

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected