This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am anasaboreeda on github. | |
* I am aboureada (https://keybase.io/aboureada) on keybase. | |
* I have a public key ASAHGpIoHJh5EECgSV2kjRYGTj0S7QoX8xjRO3kF29CV_Qo | |
To claim this, I am signing this object: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Permutation { | |
void permutation(String str) { | |
permutation(str, ""); | |
} | |
void permutation(String str, String prefix) { | |
if (str.length() == 0) { | |
System.out.println(prefix); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int factorial(int n) { | |
if (n < 0) { | |
return -1; | |
} else if (n | |
return 1; | |
} else { | |
return n * factorial(n - 1); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int f(int n) { | |
if (n <= 1) { | |
return 1; | |
} | |
return f(n - 1) + f(n - 1); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NestedLoop { | |
public static void main(String[] args) { | |
int n = 10; // O(1) | |
int sum = 0; // O(1) | |
int j = 1; // O(1) | |
double pie = 3.14; // O(1) | |
for (int var = 0; var < n; var++) { // 0(n) | |
System.out.println("Pie: " + pie); // 0(n) | |
while(j < var) { // 0(n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NestedLoop { | |
public static void main(String[] args) { | |
int n = 10; | |
int sum = 0; | |
int j = 1; | |
double pie = 3.14; | |
for (int var = 1; var < n; var += 3) { // O(n/3) | |
System.out.println("Pie: " + pie); // O(n/3) | |
j = 1; // O(n/3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NestedLoop { | |
public static void main(String[] args) { | |
int n = 10; // O(time complexity of the called function) | |
int sum = 0; //O(1) | |
double pie = 3.14; //O(1) | |
int var = 1; | |
while(var < n) { // O(log3 n) | |
System.out.println("Pie: " + pie); // O(log3 n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NestedLoop { | |
public static void main(String[] args) { | |
int n = 10; // O(time complexity of the called function) | |
int sum = 0; //O(1) | |
double pie = 3.14; //O(1) | |
int var = 1; | |
while(var < n) { // O(log n) | |
System.out.println("Pie: " + pie); // O(log n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NestedLoop { | |
public static void main(String[] args) { | |
int n = 10; // O(time complexity of the called function) | |
int sum = 0; //O(1) | |
double pie = 3.14; //O(1) | |
for (int var = n; var >= 1; var = var - 3) { // O(n/3) | |
System.out.println("Pie: " + pie); // O(n/3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NestedLoop { | |
public static void main(String[] args) { | |
int n = 10; // 1 step --> Note: n can be anything. This is just an example | |
int sum = 0; // 1 step | |
double pie = 3.14; // 1 step | |
for (int var = 0; var < n; var = var + 3) { // n/3 steps | |
System.out.println("Pie: " + pie); // n/3 steps | |
for (int j = 0; j < n; j = j + 2) { // (n/3 * n/2) steps | |
sum++; // (n/3 * n/2) steps |
NewerOlder