From 8a967cc5d682ac2a936f075f11c501d8243b1543 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Thu, 3 Oct 2024 10:24:12 +0530 Subject: [PATCH 01/16] Enhance readability, add comments & function documentation to SkylineProblem.java --- .../thealgorithms/others/SkylineProblem.java | 82 +++++++++++++++++-- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/thealgorithms/others/SkylineProblem.java b/src/main/java/com/thealgorithms/others/SkylineProblem.java index ece398e70405..513cacb39380 100644 --- a/src/main/java/com/thealgorithms/others/SkylineProblem.java +++ b/src/main/java/com/thealgorithms/others/SkylineProblem.java @@ -4,34 +4,61 @@ import java.util.Iterator; import java.util.Scanner; +/** + * The {@code SkylineProblem} class is used to solve the skyline problem using a + * divide-and-conquer approach. + * It reads input for building data, processes it to find the skyline, and + * prints the skyline. + */ public class SkylineProblem { Building[] building; int count; + /** + * Main function that reads input for the number of buildings and their + * dimensions, + * computes the skyline using divide-and-conquer, and prints the result. + */ public void run() { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); this.building = new Building[num]; + // Read the building details and add them to the list of buildings for (int i = 0; i < num; i++) { String input = sc.next(); String[] data = input.split(","); this.add(Integer.parseInt(data[0]), Integer.parseInt(data[1]), Integer.parseInt(data[2])); } + this.print(this.findSkyline(0, num - 1)); sc.close(); } + /** + * Adds a building with the given left, height, and right values to the + * buildings list. + * + * @param left The left x-coordinate of the building. + * @param height The height of the building. + * @param right The right x-coordinate of the building. + */ public void add(int left, int height, int right) { building[count++] = new Building(left, height, right); } + /** + * Prints the skyline as a sequence of coordinates and heights. + * + * @param skyline The list of {@link Skyline} objects representing the skyline. + */ public void print(ArrayList skyline) { Iterator it = skyline.iterator(); + // Print each coordinate and height from the skyline list while (it.hasNext()) { Skyline temp = it.next(); System.out.print(temp.coordinates + "," + temp.height); @@ -41,29 +68,44 @@ public void print(ArrayList skyline) { } } + /** + * Computes the skyline for a range of buildings using the divide-and-conquer + * approach. + * + * @param start The starting index of the buildings to process. + * @param end The ending index of the buildings to process. + * @return A list of {@link Skyline} objects representing the computed skyline. + */ public ArrayList findSkyline(int start, int end) { + // Base case: only one building, return its skyline. if (start == end) { ArrayList list = new ArrayList<>(); list.add(new Skyline(building[start].left, building[start].height)); - list.add(new Skyline(building[end].right, 0)); - + list.add(new Skyline(building[end].right, 0)); // Add the end of the building return list; } int mid = (start + end) / 2; - ArrayList sky1 = this.findSkyline(start, mid); - ArrayList sky2 = this.findSkyline(mid + 1, end); - - return this.mergeSkyline(sky1, sky2); + ArrayList sky1 = this.findSkyline(start, mid); // Find the skyline of the left half + ArrayList sky2 = this.findSkyline(mid + 1, end); // Find the skyline of the right half + return this.mergeSkyline(sky1, sky2); // Merge the two skylines } + /** + * Merges two skylines (sky1 and sky2) into one combined skyline. + * + * @param sky1 The first skyline list. + * @param sky2 The second skyline list. + * @return A list of {@link Skyline} objects representing the merged skyline. + */ public ArrayList mergeSkyline(ArrayList sky1, ArrayList sky2) { int currentH1 = 0; int currentH2 = 0; ArrayList skyline = new ArrayList<>(); int maxH = 0; + // Merge the two skylines while (!sky1.isEmpty() && !sky2.isEmpty()) { if (sky1.get(0).coordinates < sky2.get(0).coordinates) { int currentX = sky1.get(0).coordinates; @@ -96,6 +138,7 @@ public ArrayList mergeSkyline(ArrayList sky1, ArrayList mergeSkyline(ArrayList sky1, ArrayList Date: Thu, 3 Oct 2024 10:26:22 +0530 Subject: [PATCH 02/16] Remove trailing whitespaces --- .../com/thealgorithms/others/SkylineProblem.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/thealgorithms/others/SkylineProblem.java b/src/main/java/com/thealgorithms/others/SkylineProblem.java index 513cacb39380..fd9953310ec5 100644 --- a/src/main/java/com/thealgorithms/others/SkylineProblem.java +++ b/src/main/java/com/thealgorithms/others/SkylineProblem.java @@ -41,7 +41,7 @@ public void run() { /** * Adds a building with the given left, height, and right values to the * buildings list. - * + * * @param left The left x-coordinate of the building. * @param height The height of the building. * @param right The right x-coordinate of the building. @@ -52,7 +52,7 @@ public void add(int left, int height, int right) { /** * Prints the skyline as a sequence of coordinates and heights. - * + * * @param skyline The list of {@link Skyline} objects representing the skyline. */ public void print(ArrayList skyline) { @@ -71,7 +71,7 @@ public void print(ArrayList skyline) { /** * Computes the skyline for a range of buildings using the divide-and-conquer * approach. - * + * * @param start The starting index of the buildings to process. * @param end The ending index of the buildings to process. * @return A list of {@link Skyline} objects representing the computed skyline. @@ -94,7 +94,7 @@ public ArrayList findSkyline(int start, int end) { /** * Merges two skylines (sky1 and sky2) into one combined skyline. - * + * * @param sky1 The first skyline list. * @param sky2 The second skyline list. * @return A list of {@link Skyline} objects representing the merged skyline. @@ -161,7 +161,7 @@ public class Skyline { /** * Constructor for the {@code Skyline} class. - * + * * @param coordinates The x-coordinate of the skyline point. * @param height The height of the skyline at the given coordinate. */ @@ -182,7 +182,7 @@ public class Building { /** * Constructor for the {@code Building} class. - * + * * @param left The left x-coordinate of the building. * @param height The height of the building. * @param right The right x-coordinate of the building. @@ -196,7 +196,7 @@ public Building(int left, int height, int right) { /** * The main method that runs the skyline problem solution. - * + * * @param args Command-line arguments (not used). */ public static void main(String[] args) { From 1d0b764581601d6640f455d0d77feeb50f0a27c0 Mon Sep 17 00:00:00 2001 From: Hardvan Date: Thu, 3 Oct 2024 04:58:08 +0000 Subject: [PATCH 03/16] Update directory --- DIRECTORY.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 6f63a88b085a..9766c2f83589 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -451,6 +451,8 @@ * [TowerOfHanoi](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/TowerOfHanoi.java) * [TwoPointers](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/TwoPointers.java) * [Verhoeff](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Verhoeff.java) + * Recursion + * [GenerateSubsets](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/Recursion/GenerateSubsets.java) * scheduling * [FCFSScheduling](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/scheduling/FCFSScheduling.java) * [PreemptivePriorityScheduling](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/scheduling/PreemptivePriorityScheduling.java) @@ -893,6 +895,8 @@ * [TestPrintMatrixInSpiralOrder](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java) * [TwoPointersTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TwoPointersTest.java) * [WorstFitCPUTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/WorstFitCPUTest.java) + * Recursion + * [GenerateSubsetsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/Recursion/GenerateSubsetsTest.java) * scheduling * [FCFSSchedulingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/scheduling/FCFSSchedulingTest.java) * [PreemptivePrioritySchedulingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/scheduling/PreemptivePrioritySchedulingTest.java) From 796f1325955295422d2cb26ee7970108033d09a6 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Thu, 3 Oct 2024 10:29:16 +0530 Subject: [PATCH 04/16] Fix comment --- src/main/java/com/thealgorithms/others/SkylineProblem.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/thealgorithms/others/SkylineProblem.java b/src/main/java/com/thealgorithms/others/SkylineProblem.java index fd9953310ec5..613a6b1085e4 100644 --- a/src/main/java/com/thealgorithms/others/SkylineProblem.java +++ b/src/main/java/com/thealgorithms/others/SkylineProblem.java @@ -17,8 +17,8 @@ public class SkylineProblem { /** * Main function that reads input for the number of buildings and their - * dimensions, - * computes the skyline using divide-and-conquer, and prints the result. + * dimensions, computes the skyline using divide-and-conquer, + * and prints the result. */ public void run() { Scanner sc = new Scanner(System.in); From 6a7292f2b104690c5ec3aaa7e3b7e1ada64dcb26 Mon Sep 17 00:00:00 2001 From: Hardvan Date: Fri, 4 Oct 2024 14:59:03 +0000 Subject: [PATCH 05/16] Update directory --- DIRECTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 24cd22f67d07..af5905d00747 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -238,6 +238,7 @@ * [KnapsackMemoization](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackMemoization.java) * [LevenshteinDistance](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LevenshteinDistance.java) * [LongestAlternatingSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequence.java) + * [LongestArithmeticSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java) * [LongestCommonSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java) * [LongestIncreasingSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequence.java) * [LongestPalindromicSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubsequence.java) @@ -733,6 +734,7 @@ * [KnapsackTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/KnapsackTest.java) * [LevenshteinDistanceTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LevenshteinDistanceTests.java) * [LongestAlternatingSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequenceTest.java) + * [LongestArithmeticSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequenceTest.java) * [LongestIncreasingSubsequenceTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequenceTests.java) * [LongestPalindromicSubstringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstringTest.java) * [LongestValidParenthesesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestValidParenthesesTest.java) From 8ffc502ad363f83b557c6f21437d8efd07f2bb98 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Fri, 4 Oct 2024 20:33:50 +0530 Subject: [PATCH 06/16] Fix comments --- .../divideandconquer/SkylineAlgorithm.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/thealgorithms/divideandconquer/SkylineAlgorithm.java b/src/main/java/com/thealgorithms/divideandconquer/SkylineAlgorithm.java index 610b1b78a36a..ab49c79aa9a2 100644 --- a/src/main/java/com/thealgorithms/divideandconquer/SkylineAlgorithm.java +++ b/src/main/java/com/thealgorithms/divideandconquer/SkylineAlgorithm.java @@ -29,11 +29,12 @@ public ArrayList getPoints() { } /** - * The main divide and conquer, and also recursive algorithm. It gets an - * ArrayList full of points as an argument. If the size of that ArrayList is - * 1 or 2, the ArrayList is returned as it is, or with one less point (if - * the initial size is 2 and one of it's points, is dominated by the other - * one). On the other hand, if the ArrayList's size is bigger than 2, the + * The main divide and conquer, and also recursive algorithm. + * It gets an ArrayList full of points as an argument. + * If the size of that ArrayList is 1 or 2, the ArrayList is + * returned as it is, or with one less point (if the initial size is 2 + * and one of it's points, is dominated by the other one). + * On the other hand, if the ArrayList's size is bigger than 2, the * function is called again, twice, with arguments the corresponding half of * the initial ArrayList each time. Once the flashback has ended, the * function produceFinalSkyLine gets called, in order to produce the final From 59b201bf4a0b69e9a582c77df7e0e4169c2eb2c9 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Sat, 5 Oct 2024 19:22:22 +0530 Subject: [PATCH 07/16] Remove print and main method --- .../thealgorithms/others/SkylineProblem.java | 51 ------------------- 1 file changed, 51 deletions(-) diff --git a/src/main/java/com/thealgorithms/others/SkylineProblem.java b/src/main/java/com/thealgorithms/others/SkylineProblem.java index 613a6b1085e4..37e7183040f3 100644 --- a/src/main/java/com/thealgorithms/others/SkylineProblem.java +++ b/src/main/java/com/thealgorithms/others/SkylineProblem.java @@ -15,29 +15,6 @@ public class SkylineProblem { Building[] building; int count; - /** - * Main function that reads input for the number of buildings and their - * dimensions, computes the skyline using divide-and-conquer, - * and prints the result. - */ - public void run() { - Scanner sc = new Scanner(System.in); - - int num = sc.nextInt(); - this.building = new Building[num]; - - // Read the building details and add them to the list of buildings - for (int i = 0; i < num; i++) { - String input = sc.next(); - String[] data = input.split(","); - this.add(Integer.parseInt(data[0]), Integer.parseInt(data[1]), Integer.parseInt(data[2])); - } - - this.print(this.findSkyline(0, num - 1)); - - sc.close(); - } - /** * Adds a building with the given left, height, and right values to the * buildings list. @@ -50,24 +27,6 @@ public void add(int left, int height, int right) { building[count++] = new Building(left, height, right); } - /** - * Prints the skyline as a sequence of coordinates and heights. - * - * @param skyline The list of {@link Skyline} objects representing the skyline. - */ - public void print(ArrayList skyline) { - Iterator it = skyline.iterator(); - - // Print each coordinate and height from the skyline list - while (it.hasNext()) { - Skyline temp = it.next(); - System.out.print(temp.coordinates + "," + temp.height); - if (it.hasNext()) { - System.out.print(","); - } - } - } - /** * Computes the skyline for a range of buildings using the divide-and-conquer * approach. @@ -193,14 +152,4 @@ public Building(int left, int height, int right) { this.right = right; } } - - /** - * The main method that runs the skyline problem solution. - * - * @param args Command-line arguments (not used). - */ - public static void main(String[] args) { - SkylineProblem skylineProblem = new SkylineProblem(); - skylineProblem.run(); - } } From b70e575c61290f661fedb24e3f280ef1cd5199e8 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Sat, 5 Oct 2024 19:22:41 +0530 Subject: [PATCH 08/16] Remove unused imports --- src/main/java/com/thealgorithms/others/SkylineProblem.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/thealgorithms/others/SkylineProblem.java b/src/main/java/com/thealgorithms/others/SkylineProblem.java index 37e7183040f3..99f1843cab08 100644 --- a/src/main/java/com/thealgorithms/others/SkylineProblem.java +++ b/src/main/java/com/thealgorithms/others/SkylineProblem.java @@ -1,8 +1,6 @@ package com.thealgorithms.others; import java.util.ArrayList; -import java.util.Iterator; -import java.util.Scanner; /** * The {@code SkylineProblem} class is used to solve the skyline problem using a From dcee322ff1441bd77ca6f5a1d0106ea8d4a6a796 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Sat, 5 Oct 2024 19:23:51 +0530 Subject: [PATCH 09/16] Fix --- .../divideandconquer/SkylineAlgorithm.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/thealgorithms/divideandconquer/SkylineAlgorithm.java b/src/main/java/com/thealgorithms/divideandconquer/SkylineAlgorithm.java index ab49c79aa9a2..610b1b78a36a 100644 --- a/src/main/java/com/thealgorithms/divideandconquer/SkylineAlgorithm.java +++ b/src/main/java/com/thealgorithms/divideandconquer/SkylineAlgorithm.java @@ -29,12 +29,11 @@ public ArrayList getPoints() { } /** - * The main divide and conquer, and also recursive algorithm. - * It gets an ArrayList full of points as an argument. - * If the size of that ArrayList is 1 or 2, the ArrayList is - * returned as it is, or with one less point (if the initial size is 2 - * and one of it's points, is dominated by the other one). - * On the other hand, if the ArrayList's size is bigger than 2, the + * The main divide and conquer, and also recursive algorithm. It gets an + * ArrayList full of points as an argument. If the size of that ArrayList is + * 1 or 2, the ArrayList is returned as it is, or with one less point (if + * the initial size is 2 and one of it's points, is dominated by the other + * one). On the other hand, if the ArrayList's size is bigger than 2, the * function is called again, twice, with arguments the corresponding half of * the initial ArrayList each time. Once the flashback has ended, the * function produceFinalSkyLine gets called, in order to produce the final From 1d199e766c39c0c16d4e5e10bdf84cd1736bf082 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Sat, 5 Oct 2024 19:24:22 +0530 Subject: [PATCH 10/16] Add tests --- .../others/SkylineProblemTest.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/test/java/com/thealgorithms/others/SkylineProblemTest.java diff --git a/src/test/java/com/thealgorithms/others/SkylineProblemTest.java b/src/test/java/com/thealgorithms/others/SkylineProblemTest.java new file mode 100644 index 000000000000..bc2f46f928c3 --- /dev/null +++ b/src/test/java/com/thealgorithms/others/SkylineProblemTest.java @@ -0,0 +1,87 @@ +package com.thealgorithms.others; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; +import org.junit.jupiter.api.Test; + +public class SkylineProblemTest { + + @Test + public void testSingleBuildingSkyline() { + SkylineProblem skylineProblem = new SkylineProblem(); + skylineProblem.building = new SkylineProblem.Building[1]; + skylineProblem.add(2, 10, 9); + + ArrayList result = skylineProblem.findSkyline(0, 0); + + assertEquals(2, result.get(0).coordinates); + assertEquals(10, result.get(0).height); + assertEquals(9, result.get(1).coordinates); + assertEquals(0, result.get(1).height); + } + + @Test + public void testTwoBuildingsSkyline() { + SkylineProblem skylineProblem = new SkylineProblem(); + skylineProblem.building = new SkylineProblem.Building[2]; + skylineProblem.add(1, 11, 5); + skylineProblem.add(2, 6, 7); + + ArrayList result = skylineProblem.findSkyline(0, 1); + + // Expected skyline points: (1, 11), (5, 6), (7, 0) + assertEquals(1, result.get(0).coordinates); + assertEquals(11, result.get(0).height); + assertEquals(5, result.get(1).coordinates); + assertEquals(6, result.get(1).height); + assertEquals(7, result.get(2).coordinates); + assertEquals(0, result.get(2).height); + } + + @Test + public void testMergeSkyline() { + SkylineProblem skylineProblem = new SkylineProblem(); + ArrayList sky1 = new ArrayList<>(); + ArrayList sky2 = new ArrayList<>(); + + sky1.add(skylineProblem.new Skyline(2, 10)); + sky1.add(skylineProblem.new Skyline(9, 0)); + + sky2.add(skylineProblem.new Skyline(3, 15)); + sky2.add(skylineProblem.new Skyline(7, 0)); + + ArrayList result = skylineProblem.mergeSkyline(sky1, sky2); + + // Expected merged skyline: (2, 10), (3, 15), (7, 10), (9, 0) + assertEquals(2, result.get(0).coordinates); + assertEquals(10, result.get(0).height); + assertEquals(3, result.get(1).coordinates); + assertEquals(15, result.get(1).height); + assertEquals(7, result.get(2).coordinates); + assertEquals(10, result.get(2).height); + assertEquals(9, result.get(3).coordinates); + assertEquals(0, result.get(3).height); + } + + @Test + public void testMultipleBuildingsSkyline() { + SkylineProblem skylineProblem = new SkylineProblem(); + skylineProblem.building = new SkylineProblem.Building[3]; + skylineProblem.add(1, 10, 5); + skylineProblem.add(2, 15, 7); + skylineProblem.add(3, 12, 9); + + ArrayList result = skylineProblem.findSkyline(0, 2); + + // Expected skyline points: (1, 10), (2, 15), (7, 12), (9, 0) + assertEquals(1, result.get(0).coordinates); + assertEquals(10, result.get(0).height); + assertEquals(2, result.get(1).coordinates); + assertEquals(15, result.get(1).height); + assertEquals(7, result.get(2).coordinates); + assertEquals(12, result.get(2).height); + assertEquals(9, result.get(3).coordinates); + assertEquals(0, result.get(3).height); + } +} From 2bb0c2cc2cc59eaed2c0af64922dedfc8dd4197d Mon Sep 17 00:00:00 2001 From: Hardvan Date: Sat, 5 Oct 2024 13:54:37 +0000 Subject: [PATCH 11/16] Update directory --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index af5905d00747..713b8289f62d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -895,6 +895,7 @@ * [RemoveDuplicateFromStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/RemoveDuplicateFromStringTest.java) * [ReturnSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ReturnSubsequenceTest.java) * [ReverseStackUsingRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ReverseStackUsingRecursionTest.java) + * [SkylineProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/SkylineProblemTest.java) * [StringMatchFiniteAutomataTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/StringMatchFiniteAutomataTest.java) * [TestPrintMatrixInSpiralOrder](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java) * [TwoPointersTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TwoPointersTest.java) From 919e5752f8e426943d0612fe491d4b58a4d4175a Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Sat, 5 Oct 2024 19:30:05 +0530 Subject: [PATCH 12/16] Fix --- src/test/java/com/thealgorithms/others/SkylineProblemTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/thealgorithms/others/SkylineProblemTest.java b/src/test/java/com/thealgorithms/others/SkylineProblemTest.java index bc2f46f928c3..c89d98354134 100644 --- a/src/test/java/com/thealgorithms/others/SkylineProblemTest.java +++ b/src/test/java/com/thealgorithms/others/SkylineProblemTest.java @@ -74,7 +74,6 @@ public void testMultipleBuildingsSkyline() { ArrayList result = skylineProblem.findSkyline(0, 2); - // Expected skyline points: (1, 10), (2, 15), (7, 12), (9, 0) assertEquals(1, result.get(0).coordinates); assertEquals(10, result.get(0).height); assertEquals(2, result.get(1).coordinates); From 8f82404442fced269d4ff0d87d3e3086178f4afc Mon Sep 17 00:00:00 2001 From: Hardvan Date: Sat, 5 Oct 2024 14:03:57 +0000 Subject: [PATCH 13/16] Update directory --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 63bf3672306b..728c23cf1849 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -747,6 +747,7 @@ * [LevenshteinDistanceTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LevenshteinDistanceTests.java) * [LongestAlternatingSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequenceTest.java) * [LongestArithmeticSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequenceTest.java) + * [LongestCommonSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequenceTest.java) * [LongestIncreasingSubsequenceTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequenceTests.java) * [LongestPalindromicSubstringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstringTest.java) * [LongestValidParenthesesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestValidParenthesesTest.java) @@ -904,7 +905,6 @@ * [RemoveDuplicateFromStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/RemoveDuplicateFromStringTest.java) * [ReverseStackUsingRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ReverseStackUsingRecursionTest.java) * [SkylineProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/SkylineProblemTest.java) - * [StringMatchFiniteAutomataTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/StringMatchFiniteAutomataTest.java) * [TestPrintMatrixInSpiralOrder](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java) * [TwoPointersTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TwoPointersTest.java) * [WorstFitCPUTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/WorstFitCPUTest.java) From 8bdededf5d289376dc99c6070270f8d46f173a9e Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Sat, 5 Oct 2024 19:38:39 +0530 Subject: [PATCH 14/16] Fix --- src/main/java/com/thealgorithms/others/SkylineProblem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/others/SkylineProblem.java b/src/main/java/com/thealgorithms/others/SkylineProblem.java index 99f1843cab08..e84a5c5b585b 100644 --- a/src/main/java/com/thealgorithms/others/SkylineProblem.java +++ b/src/main/java/com/thealgorithms/others/SkylineProblem.java @@ -27,7 +27,7 @@ public void add(int left, int height, int right) { /** * Computes the skyline for a range of buildings using the divide-and-conquer - * approach. + * strategy. * * @param start The starting index of the buildings to process. * @param end The ending index of the buildings to process. From 0f6001a34acd79e2813d22da49be3d4ceb31c117 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Sat, 5 Oct 2024 19:39:52 +0530 Subject: [PATCH 15/16] Fix --- src/test/java/com/thealgorithms/others/SkylineProblemTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/thealgorithms/others/SkylineProblemTest.java b/src/test/java/com/thealgorithms/others/SkylineProblemTest.java index c89d98354134..1ed5ced709c1 100644 --- a/src/test/java/com/thealgorithms/others/SkylineProblemTest.java +++ b/src/test/java/com/thealgorithms/others/SkylineProblemTest.java @@ -1,6 +1,6 @@ package com.thealgorithms.others; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import org.junit.jupiter.api.Test; From 935f717e4bbe78297574e69a5cf2aebcaca71e21 Mon Sep 17 00:00:00 2001 From: siriak Date: Mon, 7 Oct 2024 12:22:11 +0000 Subject: [PATCH 16/16] Update directory --- DIRECTORY.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 40bc4ed82616..0d34492fde9a 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -27,6 +27,7 @@ * [IndexOfRightMostSetBit](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBit.java) * [IsEven](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java) * [IsPowerTwo](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/IsPowerTwo.java) + * [LowestSetBit](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java) * [NonRepeatingNumberFinder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/NonRepeatingNumberFinder.java) * [NumbersDifferentSigns](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java) * [ReverseBits](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/ReverseBits.java) @@ -280,6 +281,12 @@ * [MinimizingLateness](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/greedyalgorithms/MinimizingLateness.java) * io * [BufferedReader](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/io/BufferedReader.java) + * lineclipping + * [CohenSutherland](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/lineclipping/CohenSutherland.java) + * [LiangBarsky](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/lineclipping/LiangBarsky.java) + * utils + * [Line](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/lineclipping/utils/Line.java) + * [Point](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/lineclipping/utils/Point.java) * maths * [AbsoluteMax](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AbsoluteMax.java) * [AbsoluteMin](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AbsoluteMin.java) @@ -615,6 +622,7 @@ * [IndexOfRightMostSetBitTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBitTest.java) * [IsEvenTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/IsEvenTest.java) * [IsPowerTwoTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/IsPowerTwoTest.java) + * [LowestSetBitTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/LowestSetBitTest.java) * [NonRepeatingNumberFinderTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/NonRepeatingNumberFinderTest.java) * [NumbersDifferentSignsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java) * [ReverseBitsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/ReverseBitsTest.java) @@ -785,6 +793,9 @@ * [MinimizingLatenessTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/greedyalgorithms/MinimizingLatenessTest.java) * io * [BufferedReaderTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/io/BufferedReaderTest.java) + * lineclipping + * [CohenSutherlandTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/lineclipping/CohenSutherlandTest.java) + * [LiangBarskyTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/lineclipping/LiangBarskyTest.java) * maths * [AbsoluteMaxTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AbsoluteMaxTest.java) * [AbsoluteMinTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AbsoluteMinTest.java)