From 15fee9228be1bbf9cc8c08062f071d851de5cc56 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:22:24 -0800 Subject: [PATCH 01/17] question 1 done together --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 036c766..f84d27f 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,7 +6,7 @@ public class Main { // The time complexity is: - // YOUR ANSWER HERE + // n^2 public static void timesTable(int x) { for(int i = 1; i <= x; i++) { for(int j = 1; j <= x; j++) { From 9a3ab2d8cca93f989d68647bf322969f83bfaa80 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:23:15 -0800 Subject: [PATCH 02/17] Question 2 done together --- src/Main.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Main.java b/src/Main.java index f84d27f..709a57d 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,7 +6,7 @@ public class Main { // The time complexity is: - // n^2 + // o(n^2) public static void timesTable(int x) { for(int i = 1; i <= x; i++) { for(int j = 1; j <= x; j++) { @@ -17,7 +17,7 @@ public static void timesTable(int x) { } // The time complexity is: - // YOUR ANSWER HERE + // o(n) public static void printLetters(String word) { char[] letters = word.toCharArray(); From b70971e9b42cfac3701912f6e997d472a7e03d82 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:23:40 -0800 Subject: [PATCH 03/17] question 3 done together --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 709a57d..5a845e4 100644 --- a/src/Main.java +++ b/src/Main.java @@ -27,7 +27,7 @@ public static void printLetters(String word) { } // The time complexity is: - // YOUR ANSWER HERE + // o(n) public static boolean isBanned(String password) { String[] bannedPasswords = {"password", "hello", "qwerty"}; boolean banned = false; From 6708ccf39bd9006d787ef0e40b9476043ed681a1 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:24:16 -0800 Subject: [PATCH 04/17] question 4 done together --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 5a845e4..0b17da3 100644 --- a/src/Main.java +++ b/src/Main.java @@ -41,7 +41,7 @@ public static boolean isBanned(String password) { // The time complexity is: - // YOUR ANSWER HERE + // o(n) public static int computeProduct(int[] nums) { int total = 1; for(int num : nums) { From 68f601139fd0e316a7cef0b272613a1928733bde Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:24:38 -0800 Subject: [PATCH 05/17] question 5 done together --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 0b17da3..278a8a2 100644 --- a/src/Main.java +++ b/src/Main.java @@ -51,7 +51,7 @@ public static int computeProduct(int[] nums) { } // The time complexity is: - // YOUR ANSWER HERE + // o(1) public static void describeProduct(int[] nums) { System.out.println("About to compute the product of the array..."); int product = computeProduct(nums); From 7f663c94dd81e634365a9d2fd8595071aeb2b8c5 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:25:10 -0800 Subject: [PATCH 06/17] question 6 donr together --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 278a8a2..9c7a855 100644 --- a/src/Main.java +++ b/src/Main.java @@ -60,7 +60,7 @@ public static void describeProduct(int[] nums) { // The time complexity is: - // YOUR ANSWER HERE + // o(n) public static int computeFactorial(int n) { int result = 1; for(int i = 1; i <= n; i++) { From 81d13988c84b8511c045fbbb2d8b447aa14d4894 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:29:19 -0800 Subject: [PATCH 07/17] question 7 done together --- src/Main.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Main.java b/src/Main.java index 9c7a855..b8fb2eb 100644 --- a/src/Main.java +++ b/src/Main.java @@ -51,7 +51,7 @@ public static int computeProduct(int[] nums) { } // The time complexity is: - // o(1) + // o(n) public static void describeProduct(int[] nums) { System.out.println("About to compute the product of the array..."); int product = computeProduct(nums); @@ -71,6 +71,7 @@ public static int computeFactorial(int n) { // Assume that the largest number is no bigger than the length // of the array + //The time complexity is o(n^2) public static void computeAllFactorials(int[] nums) { for(int num : nums) { int result = computeFactorial(num); @@ -81,7 +82,7 @@ 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) public static void checkIfContainedArrayList(ArrayList arr, String target) { if (arr.contains(target)) { System.out.println(target + " is present in the list"); From 579f93364366602cf37c9c251976e479bc8dd698 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:30:03 -0800 Subject: [PATCH 08/17] question 8 done together --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index b8fb2eb..ecb18db 100644 --- a/src/Main.java +++ b/src/Main.java @@ -95,7 +95,7 @@ public static void checkIfContainedArrayList(ArrayList arr, String targe // assume n = wordsA.length = wordsB.length // assume that each String is bounded by a constant length // The time complexity is: - // YOUR ANSWER HERE + // o(n^2) public static boolean containsOverlap(String[] wordsA, String[] wordsB) { for(String wordA : wordsA) { for(String wordB : wordsB) { From e524c66a01ff8a1b2fbf7d282297b75f93a1973b Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:30:41 -0800 Subject: [PATCH 09/17] question 9 done together --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index ecb18db..da30be9 100644 --- a/src/Main.java +++ b/src/Main.java @@ -109,7 +109,7 @@ 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) public static boolean containsOverlap2(String[] wordsA, String[] wordsB) { Set wordsSet = new HashSet<>(); for(String word : wordsA) { From b4adad92e5e5e0c0d9a13e548f82c0e61769e43d Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:31:32 -0800 Subject: [PATCH 10/17] question 10 done togehter --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index da30be9..e435866 100644 --- a/src/Main.java +++ b/src/Main.java @@ -126,7 +126,7 @@ public static boolean containsOverlap2(String[] wordsA, String[] wordsB) { } // The time complexity is: - // YOUR ANSWER HERE + // o(n) public static void printCharacters(char[] chars) { for (int i = 0; i < chars.length; i++) { char character = chars[i]; From 53dc7db1e6acd168f6b2296439bdb044e0c72323 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:31:54 -0800 Subject: [PATCH 11/17] question 11 done --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index e435866..e16e580 100644 --- a/src/Main.java +++ b/src/Main.java @@ -134,7 +134,7 @@ public static void printCharacters(char[] chars) { } } // The time complexity is: - // YOUR ANSWER HERE + // o(1) public static double computeAverage(double a, double b) { return (a + b) / 2.0; } From 60a4756c17d7e209ea2ddba0f48a83f28154f583 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:32:48 -0800 Subject: [PATCH 12/17] question 12 done together --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index e16e580..40471eb 100644 --- a/src/Main.java +++ b/src/Main.java @@ -141,7 +141,7 @@ 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) public static void checkIfContainedHashSet(HashSet set, String target) { if (set.contains(target)) { From dd7aff9abd5b1239fb87962d8adbd1c2429150f5 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:33:56 -0800 Subject: [PATCH 13/17] question 13 done togther --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 40471eb..79c92f7 100644 --- a/src/Main.java +++ b/src/Main.java @@ -157,7 +157,7 @@ public static void checkIfContainedHashSet(HashSet set, String target) // Otherwise, it returns "Person not found" // assume that each String is bounded by a constant length // What is the time complexity of this method? - // YOUR ANSWER HERE + // o(n) public static String emailLookup(String[] names, String[] emails, String queryName) { for(int i = 0; i < names.length; i++) { if (names[i].equals(queryName)) { From b21d04decfd0067e38eed8c56708e94bf32fdbc5 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:39:25 -0800 Subject: [PATCH 14/17] Question 14 done together --- src/Main.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Main.java b/src/Main.java index 79c92f7..21471f4 100644 --- a/src/Main.java +++ b/src/Main.java @@ -173,9 +173,14 @@ public static String emailLookup(String[] names, String[] emails, String queryNa // Write this method to efficiently return the corresponding email or "Person not found" if appropriate // assume that each String is bounded by a constant length // What is the time complexity of your solution? - // YOUR ANSWER HERE + // o(n) public static String emailLookupEfficient(HashMap namesToEmails, String queryName) { - return null; + for(String name: namesToEmails.keySet()){ + if(name.equals(queryName)){ + return namesToEmails.get(name); + } + } + return "Person not found"; } // What is the time complexity of this method? From 25d36151662b1a5deee33f67e3c774a2291ed669 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:40:29 -0800 Subject: [PATCH 15/17] question 15 done together --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 21471f4..c3c661d 100644 --- a/src/Main.java +++ b/src/Main.java @@ -186,7 +186,7 @@ public static String emailLookupEfficient(HashMap namesToEmails, // What is the time complexity of this method? // 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) public static boolean hasCommon(HashSet wordSet, ArrayList wordList) { for(String word : wordSet) { if(wordList.contains(word)) { From 6338c0f561b572b54273d6cfa420da83d9fc9737 Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:42:12 -0800 Subject: [PATCH 16/17] question 16 done together --- src/Main.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Main.java b/src/Main.java index c3c661d..2bc43bc 100644 --- a/src/Main.java +++ b/src/Main.java @@ -199,10 +199,17 @@ public static boolean hasCommon(HashSet wordSet, ArrayList wordL // Do not change the datatype of wordSet or wordList. // assume that each String is bounded by a constant length // What is the time complexity of your new solution? - // YOUR ANSWER HERE + // o(n) public static boolean hasCommonEfficient(HashSet wordSet, ArrayList wordList) { + + for(String word : wordList) { + if(wordSet.contains(word)) { + return true; + } + } return false; - } + } + // Suppose you are building a dashboard that displays real-time stock prices. // You want to keep track of the current price of each stock, with the stock's ticker symbol as the key. From d09dffe8aa7024ee845f165cf8ef9f40c5f2fa0d Mon Sep 17 00:00:00 2001 From: EmilyM <155667566+EmilyMenken@user.noreply.github.com> Date: Thu, 6 Feb 2025 11:46:05 -0800 Subject: [PATCH 17/17] Completity-Practice complete togethergit add .! --- src/Main.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Main.java b/src/Main.java index 2bc43bc..b4cd0bb 100644 --- a/src/Main.java +++ b/src/Main.java @@ -216,14 +216,14 @@ public static boolean hasCommonEfficient(HashSet wordSet, ArrayList wordSet, ArrayList