From 18e13c94e41236a5a9bbe3533e70c8d261658928 Mon Sep 17 00:00:00 2001 From: tim Date: Thu, 6 Feb 2025 11:27:02 -0800 Subject: [PATCH 01/12] First problem --- src/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Main.java b/src/Main.java index 036c766..6625992 100644 --- a/src/Main.java +++ b/src/Main.java @@ -7,6 +7,7 @@ public class Main { // The time complexity is: // YOUR ANSWER HERE + // O(x^2) public static void timesTable(int x) { for(int i = 1; i <= x; i++) { for(int j = 1; j <= x; j++) { From cddce8323858fcbf2fcd6bd6c430bc649bede1ba Mon Sep 17 00:00:00 2001 From: tim Date: Thu, 6 Feb 2025 11:29:14 -0800 Subject: [PATCH 02/12] added descrip --- src/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Main.java b/src/Main.java index 6625992..373f54a 100644 --- a/src/Main.java +++ b/src/Main.java @@ -8,6 +8,7 @@ public class Main { // The time complexity is: // YOUR ANSWER HERE // O(x^2) + // X = Size of the integer x public static void timesTable(int x) { for(int i = 1; i <= x; i++) { for(int j = 1; j <= x; j++) { From ca9e78120c6ba4d538bf9cdc58802ac10ea93794 Mon Sep 17 00:00:00 2001 From: Bolshialex <145608606+Bolshialex@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:28:30 -0800 Subject: [PATCH 03/12] Answering time complexity --- src/Main.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Main.java b/src/Main.java index 373f54a..0f32cf4 100644 --- a/src/Main.java +++ b/src/Main.java @@ -20,6 +20,8 @@ public static void timesTable(int x) { // The time complexity is: // YOUR ANSWER HERE + // O(n) + // n is the length of the string public static void printLetters(String word) { char[] letters = word.toCharArray(); From 9b0a621a9f2ba48cd06cbdaab931e25199de4e3a Mon Sep 17 00:00:00 2001 From: tim Date: Thu, 6 Feb 2025 11:38:14 -0800 Subject: [PATCH 04/12] finished question 3 --- src/Main.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Main.java b/src/Main.java index 0f32cf4..d1b50be 100644 --- a/src/Main.java +++ b/src/Main.java @@ -32,6 +32,8 @@ public static void printLetters(String word) { // The time complexity is: // YOUR ANSWER HERE + //O(n) + // n is the fixed elements within the banned passwords array public static boolean isBanned(String password) { String[] bannedPasswords = {"password", "hello", "qwerty"}; boolean banned = false; From 3e886d6781032284abc524b59c863b7a414f5849 Mon Sep 17 00:00:00 2001 From: Bolshialex <145608606+Bolshialex@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:40:25 -0800 Subject: [PATCH 05/12] Answering time complexity --- src/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Main.java b/src/Main.java index d1b50be..62ad830 100644 --- a/src/Main.java +++ b/src/Main.java @@ -48,6 +48,8 @@ public static boolean isBanned(String password) { // The time complexity is: // YOUR ANSWER HERE + // O(n) + // Where n equals the length of nums public static int computeProduct(int[] nums) { int total = 1; for(int num : nums) { @@ -67,6 +69,8 @@ public static void describeProduct(int[] nums) { // The time complexity is: // YOUR ANSWER HERE + // O(n) + // Where n is the length public static int computeFactorial(int n) { int result = 1; for(int i = 1; i <= n; i++) { From 0da4e3cf9404fbaddbcbd0c74dd8e92e62c2b2f0 Mon Sep 17 00:00:00 2001 From: tim Date: Thu, 6 Feb 2025 11:42:49 -0800 Subject: [PATCH 06/12] finished more questions --- src/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Main.java b/src/Main.java index d1b50be..e23e241 100644 --- a/src/Main.java +++ b/src/Main.java @@ -58,6 +58,8 @@ public static int computeProduct(int[] nums) { // The time complexity is: // YOUR ANSWER HERE + //O(n) + // n is the length of nums public static void describeProduct(int[] nums) { System.out.println("About to compute the product of the array..."); int product = computeProduct(nums); @@ -77,6 +79,8 @@ public static int computeFactorial(int n) { // Assume that the largest number is no bigger than the length // of the array + //O(n) + // n is the length and values of nums public static void computeAllFactorials(int[] nums) { for(int num : nums) { int result = computeFactorial(num); From 0f6f5e328e2bfcd274ea7b0fc0583a2754ef7cd6 Mon Sep 17 00:00:00 2001 From: Bolshialex <145608606+Bolshialex@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:50:16 -0800 Subject: [PATCH 07/12] Adding complexity answers --- src/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Main.java b/src/Main.java index a5bce1d..be475fe 100644 --- a/src/Main.java +++ b/src/Main.java @@ -109,6 +109,8 @@ public static void checkIfContainedArrayList(ArrayList arr, String targe // assume that each String is bounded by a constant length // The time complexity is: // YOUR ANSWER HERE + // O(n^2) + // Where n is the length of arr words public static boolean containsOverlap(String[] wordsA, String[] wordsB) { for(String wordA : wordsA) { for(String wordB : wordsB) { @@ -140,6 +142,8 @@ public static boolean containsOverlap2(String[] wordsA, String[] wordsB) { // The time complexity is: // YOUR ANSWER HERE + // O(n) + // Where n is length of chars public static void printCharacters(char[] chars) { for (int i = 0; i < chars.length; i++) { char character = chars[i]; From 93766d05d82a343c5aaddea1055cbd5eac943455 Mon Sep 17 00:00:00 2001 From: tim Date: Thu, 6 Feb 2025 11:51:52 -0800 Subject: [PATCH 08/12] finished more --- src/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Main.java b/src/Main.java index a5bce1d..61a49bf 100644 --- a/src/Main.java +++ b/src/Main.java @@ -96,6 +96,8 @@ public static void computeAllFactorials(int[] nums) { // assume that each String is bounded by a constant length // The time complexity is: // YOUR ANSWER HERE + //O(n) + // contains is o(n) time complexity public static void checkIfContainedArrayList(ArrayList arr, String target) { if (arr.contains(target)) { System.out.println(target + " is present in the list"); @@ -123,6 +125,8 @@ public static boolean containsOverlap(String[] wordsA, String[] wordsB) { // assume that each String is bounded by a constant length // The time complexity is: // YOUR ANSWER HERE + //O(N) + // .add is O(1) .contains is O(N) public static boolean containsOverlap2(String[] wordsA, String[] wordsB) { Set wordsSet = new HashSet<>(); for(String word : wordsA) { From c06b0052c75bde591247f1d844d5c3dcf528ee4a Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 10 Feb 2025 10:15:38 -0800 Subject: [PATCH 09/12] 3 left --- src/Main.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Main.java b/src/Main.java index 28849dd..5555fc9 100644 --- a/src/Main.java +++ b/src/Main.java @@ -156,6 +156,8 @@ public static void printCharacters(char[] chars) { } // The time complexity is: // YOUR ANSWER HERE + //O(1) + //Returns the same time complexity value everytime, because (a) and (b) will always be a constant value. public static double computeAverage(double a, double b) { return (a + b) / 2.0; } @@ -163,6 +165,8 @@ public static double computeAverage(double a, double b) { // assume that each String is bounded by a constant length // The time complexity is: // YOUR ANSWER HERE + //O(1) + //Because (.contains) returns a time complexity of O(1) and the target will always be a constant value, also a O(1) complexity public static void checkIfContainedHashSet(HashSet set, String target) { if (set.contains(target)) { @@ -179,6 +183,8 @@ public static void checkIfContainedHashSet(HashSet set, String target) // assume that each String is bounded by a constant length // What is the time complexity of this method? // YOUR ANSWER HERE + //O(n) + //Because the size of how many names and emails can differ, causing the code to check each and every element, making it scale in size. public static String emailLookup(String[] names, String[] emails, String queryName) { for(int i = 0; i < names.length; i++) { if (names[i].equals(queryName)) { @@ -196,6 +202,9 @@ public static String emailLookup(String[] names, String[] emails, String queryNa // What is the time complexity of your solution? // YOUR ANSWER HERE public static String emailLookupEfficient(HashMap namesToEmails, String queryName) { + + + return null; } From 098c495be78012235619499a5832292cce32e9fe Mon Sep 17 00:00:00 2001 From: BolshiAlex <145608606+Bolshialex@users.noreply.github.com> Date: Mon, 10 Feb 2025 10:42:25 -0800 Subject: [PATCH 10/12] Methods left --- src/Main.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Main.java b/src/Main.java index 5555fc9..aada56b 100644 --- a/src/Main.java +++ b/src/Main.java @@ -156,8 +156,8 @@ public static void printCharacters(char[] chars) { } // The time complexity is: // YOUR ANSWER HERE - //O(1) - //Returns the same time complexity value everytime, because (a) and (b) will always be a constant value. + //O(1) + //Returns the same time complexity value everytime, because (a) and (b) will always be a constant value. public static double computeAverage(double a, double b) { return (a + b) / 2.0; } @@ -165,8 +165,8 @@ public static double computeAverage(double a, double b) { // assume that each String is bounded by a constant length // The time complexity is: // YOUR ANSWER HERE - //O(1) - //Because (.contains) returns a time complexity of O(1) and the target will always be a constant value, also a O(1) complexity + //O(1) + //Because (.contains) returns a time complexity of O(1) and the target will always be a constant value, also a O(1) complexity public static void checkIfContainedHashSet(HashSet set, String target) { if (set.contains(target)) { @@ -184,7 +184,7 @@ public static void checkIfContainedHashSet(HashSet set, String target) // What is the time complexity of this method? // YOUR ANSWER HERE //O(n) - //Because the size of how many names and emails can differ, causing the code to check each and every element, making it scale in size. +//Because the size of how many names and emails can differ, causing the code to check each and every element, making it scale in size. public static String emailLookup(String[] names, String[] emails, String queryName) { for(int i = 0; i < names.length; i++) { if (names[i].equals(queryName)) { @@ -202,10 +202,13 @@ public static String emailLookup(String[] names, String[] emails, String queryNa // What is the time complexity of your solution? // YOUR ANSWER HERE public static String emailLookupEfficient(HashMap namesToEmails, String queryName) { - - + String result = namesToEmails.get(queryName); - return null; + if(result == null){ + result = "Person not found."; + } + + return result; } // What is the time complexity of this method? From 9cf74d06073168ad2c306b4a53385ec9e3a4f7d7 Mon Sep 17 00:00:00 2001 From: BolshiAlex <145608606+Bolshialex@users.noreply.github.com> Date: Mon, 10 Feb 2025 10:42:52 -0800 Subject: [PATCH 11/12] Methods left --- src/Main.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Main.java b/src/Main.java index aada56b..ed17e52 100644 --- a/src/Main.java +++ b/src/Main.java @@ -201,6 +201,8 @@ public static String emailLookup(String[] names, String[] emails, String queryNa // assume that each String is bounded by a constant length // What is the time complexity of your solution? // YOUR ANSWER HERE + // O(1) + // get is an o(1) time complexity. public static String emailLookupEfficient(HashMap namesToEmails, String queryName) { String result = namesToEmails.get(queryName); @@ -215,6 +217,8 @@ public static String emailLookupEfficient(HashMap namesToEmails, // assume that each String is bounded by a constant length // (assume the set and list have the same number of elements) // YOUR ANSWER HERE + // O(n^2) + // because wordSet and wordList are the same size the act as n * n public static boolean hasCommon(HashSet wordSet, ArrayList wordList) { for(String word : wordSet) { if(wordList.contains(word)) { @@ -228,7 +232,14 @@ public static boolean hasCommon(HashSet wordSet, ArrayList wordL // assume that each String is bounded by a constant length // What is the time complexity of your new solution? // YOUR ANSWER HERE + // O(n) + // swap operations now .contains is O(1) and the total is O public static boolean hasCommonEfficient(HashSet wordSet, ArrayList wordList) { + for (String word : wordList) { + if (wordSet.contains(word)) { + return true; + } + } return false; } From f53896956d21d06a8584eccc70a12222a7df96b4 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 10 Feb 2025 10:51:03 -0800 Subject: [PATCH 12/12] finished --- src/Main.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Main.java b/src/Main.java index ed17e52..e420049 100644 --- a/src/Main.java +++ b/src/Main.java @@ -250,6 +250,9 @@ public static boolean hasCommonEfficient(HashSet wordSet, ArrayList wordSet, ArrayList wordSet, ArrayList