Skip to content

Commit

Permalink
Adding time and space complexities
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak-malik committed Feb 14, 2017
1 parent 439f8fd commit 9bb2a99
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/com/deepak/ctci/Ch01_Arrays_And_Strings/Problem_01.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class Problem_01 {
* if it doesn't appear then set the flag to true.
* If it appears, return false.
*
* Time Complexity : O(n) - Because if there are n characters, we will loop n times
* Space Complexity : O(n)
* Time Complexity : O(n)
* Space Complexity : O(1)
*
* @param iWord
* @return {@link boolean}
Expand Down
6 changes: 6 additions & 0 deletions src/com/deepak/ctci/Ch01_Arrays_And_Strings/Problem_02.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class Problem_02 {
* Method to check if two given strings are valid
* case sensitive permutations
*
* Time Complexity : O(n)
* Space Complexity : O(1)
*
* @param string1
* @param string2
* @return {@link boolean}
Expand Down Expand Up @@ -56,6 +59,9 @@ public static boolean isValidPermutation_CaseSensitive(String string1, String st
* Method to check if two given strings are valid
* case insensitive permutations
*
* Time Complexity : O(n)
* Space Complexity : O(n)
*
* @param string1
* @param string2
* @return {@link boolean}
Expand Down
3 changes: 3 additions & 0 deletions src/com/deepak/ctci/Ch01_Arrays_And_Strings/Problem_03.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class Problem_03 {
* Method to replace spaces in a string with special character's (Already given)
* True length is also passed in the method
*
* Time Complexity : O(n)
* Space Complexity : O(n)
*
* @param input
* @param trueLength
* @return {@link String}
Expand Down
3 changes: 3 additions & 0 deletions src/com/deepak/ctci/Ch01_Arrays_And_Strings/Problem_04.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class Problem_04 {
* - A string will be considered as a palindrome permutation,
* if it does not have more then one odd character count
*
* Time Complexity : O(n)
* Space Complexity : O(n)
*
* @param input
* @return {@link boolean}
*/
Expand Down
3 changes: 3 additions & 0 deletions src/com/deepak/ctci/Ch01_Arrays_And_Strings/Problem_05.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class Problem_05 {
/**
* Method to check if two strings are one edit away
*
* Time Complexity : O(n)
* Space Complexity : O(1)
*
* @param input1
* @param input2
* @return {@link boolean}
Expand Down
3 changes: 3 additions & 0 deletions src/com/deepak/ctci/Ch01_Arrays_And_Strings/Problem_06.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class Problem_06 {
/**
* Method to compress a string
*
* Time Complexity : O(n)
* Space Complexity : O(n)
*
* @param input
* @return {@link String}
*/
Expand Down
6 changes: 6 additions & 0 deletions src/com/deepak/ctci/Ch01_Arrays_And_Strings/Problem_07.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class Problem_07 {
/**
* Method to rotate a matrix by 90 degrees
*
* Time Complexity : O(n^2)
* Space Complexity : O(n)
*
* @param matrix
* @return {@link int[][]}
*/
Expand Down Expand Up @@ -47,6 +50,9 @@ public static int[][] rotateMatrix(int[][] matrix) {
/**
* Method to rotate a matrix in place
*
* Time Complexity : O(n^2)
* Space Complexity : O(1)
*
* @param matrix
* @return {@link int[][]}
*/
Expand Down
3 changes: 3 additions & 0 deletions src/com/deepak/ctci/Ch01_Arrays_And_Strings/Problem_08.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class Problem_08 {
/**
* Method to set zeros in rows and columns if one entry is zero
*
* Time Complexity : O(n^2)
* Space Complexity : O(n)
*
* @param matrix
* @return {@link int[][]}
*/
Expand Down
6 changes: 5 additions & 1 deletion src/com/deepak/ctci/Ch01_Arrays_And_Strings/Problem_09.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class Problem_09 {
/**
* Method to check if one string is a rotation of another
*
* Time Complexity : O(1)
* Space Complexity : O(1)
*
* @param str1
* @param str2
* @return {@link boolean}
Expand Down Expand Up @@ -51,7 +54,8 @@ public static boolean isRotation(String str1, String str2) {
* @return {@link boolean}
*/
private static boolean isSubString(String big, String small) {
if (big.toLowerCase().indexOf(small.toLowerCase()) >= 0) { /* We can use big.contains(small) as well here */
if (big.toLowerCase().indexOf(small.toLowerCase()) >= 0) {
/* We can use big.contains(small) as well here */
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class Problem_01 {
* Method to count number of ways to climb stairs
* Note : This is a brute force method
*
* Time Complexity = O(3^n) since each call results in 3 more calls
*
* @param n
* @return {@link int}
*/
Expand Down

0 comments on commit 9bb2a99

Please sign in to comment.