Skip to content

Commit 0c83137

Browse files
authored
Merge pull request #58 from euchangxian/style/fix-checkstyle
Fix Checkstyle
2 parents b406797 + 1c1d8fc commit 0c83137

File tree

150 files changed

+6101
-5295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+6101
-5295
lines changed

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
# Data Structures & Algorithms
2-
This repository contains implementation of some fundamental data structures and algorithms in Computer Science. It is primarily used as a teaching resource and is currently being developed by ex-2040s students.
32

4-
The project uses Gradle and the structure is optimised for IntelliJ IDEA since implementation are mostly written in Java.
3+
This repository contains implementation of some fundamental data structures and algorithms in Computer Science. It is
4+
primarily used as a teaching resource and is currently being developed by ex-2040s students.
55

6-
**Note**: This is still being developed. Those below with links mean that they are complete (alongside testing). We project to complete CS2040s course content by November and along the way, add interesting algorithms/problems. We are hopeful that the subsequent batches of students (from AY23/24 S2) will benefit greatly from this.
6+
The project uses Gradle and the structure is optimised for IntelliJ IDEA since implementation are mostly written in
7+
Java.
8+
9+
**Note**: This is still being developed. Those below with links mean that they are complete (alongside testing). We
10+
project to complete CS2040s course content by November and along the way, add interesting algorithms/problems. We are
11+
hopeful that the subsequent batches of students (from AY23/24 S2) will benefit greatly from this.
712

813
If you wish to contribute, do drop an email at [email protected].
914

1015
## Full List of Implementation (in alphabetical order):
16+
1117
## Structures
18+
1219
- Adelson-Velskii and Landis (AVL) Binary Search Tree
1320
- Disjoint Set / Union Find
1421
* Quick Find
15-
* Weighted Union
22+
* Weighted Union
1623
* Path compression
1724
- [Hashing](src/main/java/dataStructures/hashSet)
1825
* [Chaining](src/main/java/dataStructures/hashSet/chaining)
@@ -25,12 +32,12 @@ If you wish to contribute, do drop an email at [email protected].
2532
- [Queue](src/main/java/dataStructures/queue)
2633
- Segment Tree
2734
* Array implementation
28-
* TreeNode implementation
35+
* TreeNode implementation
2936
- [Stack](src/main/java/dataStructures/stack)
3037
- Trie
3138

32-
3339
## Algorithms
40+
3441
- [Counting Sort](src/main/java/algorithms/sorting/countingSort)
3542
- [Cyclic Sort](src/main/java/algorithms/sorting/cyclicSort)
3643
* [Special case](src/main/java/algorithms/sorting/cyclicSort/simple) of O(n) time complexity
@@ -49,8 +56,8 @@ If you wish to contribute, do drop an email at [email protected].
4956
* [3-way Partitioning](src/main/java/algorithms/sorting/quickSort/threeWayPartitioning)
5057
- Radix Sort
5158

52-
5359
## Short-cut to CS2040S Material
60+
5461
1. Basic structures
5562
* [Linked List](src/main/java/dataStructures/linkedList)
5663
* [Stack](src/main/java/dataStructures/stack)
@@ -91,12 +98,13 @@ If you wish to contribute, do drop an email at [email protected].
9198
* Dijkstra
9299
* Directed acyclic graphs
93100
10. Minimum spanning tree
94-
* Prim's
101+
* Prim's
95102
* Kruskal's
96103

97-
98104
## Running Custom Inputs
105+
99106
See [here](scripts/README.md).
100107

101108
## Contributors
109+
102110
See the [team](docs/team/profiles.md)!

config/checkstyle/checkstyle.xml

Lines changed: 422 additions & 361 deletions
Large diffs are not rendered by default.

config/checkstyle/suppressions.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE suppressions PUBLIC
4+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
5+
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
6+
7+
<suppressions>
8+
<suppress checks="JavadocType" files=".*Test\.java"/>
9+
<suppress checks="MissingJavadocMethodCheck" files=".*Test\.java"/>
10+
</suppressions>

scripts/algorithms/patternFinding/RunKMP.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,42 @@
22

33
import java.util.List;
44

5+
/**
6+
* Runs the KMP algorithm.
7+
*/
58
public class RunKMP {
6-
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
7-
////////////////////////////////////////// This section is for user input \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
8-
static String seq = "abclaabcabcabc";
9-
static String pattern = "abc";
9+
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\
10+
////////////////////////////////////////// This section is for user input \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
11+
private static String seq = "abclaabcabcabc";
12+
private static String pattern = "abc";
1013

11-
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
14+
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\
1215

1316
public static void main(String[] args) {
1417
List<Integer> indices = KMP.findOccurrences(seq, pattern);
1518
display(indices);
1619
prettyPrint(seq, pattern, indices);
1720
}
1821

22+
/**
23+
* Prints the string representation of the List.
24+
* @param arr the given List.
25+
*/
1926
public static void display(List<Integer> arr) {
2027
StringBuilder toDisplay = new StringBuilder("[");
2128
for (int num : arr) {
2229
toDisplay.append(String.format("%d ", num));
2330
}
24-
toDisplay = toDisplay.replace(toDisplay.length()-1, toDisplay.length(), "]");
31+
toDisplay = toDisplay.replace(toDisplay.length() - 1, toDisplay.length(), "]");
2532
System.out.println(toDisplay);
2633
}
2734

35+
/**
36+
* Pretty prints the sequence and pattern.
37+
* @param seq the given string sequence.
38+
* @param pattern the given string pattern.
39+
* @param indices TODO.
40+
*/
2841
public static void prettyPrint(String seq, String pattern, List<Integer> indices) {
2942
StringBuilder prettySeq = new StringBuilder(" Sequence: ");
3043
StringBuilder prettyPtr = new StringBuilder("Start Pts: ");

scripts/algorithms/sorting/RunCountingSort.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,34 @@
22

33
import algorithms.sorting.countingSort.CountingSort;
44

5+
/**
6+
* Script to run Counting Sort.
7+
*/
58
public class RunCountingSort {
69

7-
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
8-
////////////////////////////////////////// This section is for user input \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
9-
static int[] toSort =
10+
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
11+
////////////////////////////////////////// This section is for user input \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
12+
private static int[] toSort =
1013
new int[] {3, 4, 2, 65, 76, 93, 22, 1, 5, 7, 88, 54, 44, 7, 5, 6, 2, 64, 43, 22, 27, 33, 59, 64, 76, 99, 37, 7};
1114

12-
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
15+
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
1316

1417
public static void main(String[] args) {
15-
toSort = CountingSort.sort(toSort);
16-
display(toSort);
18+
toSort = CountingSort.sort(toSort);
19+
display(toSort);
1720
}
1821

22+
/**
23+
* Prints the string representation of the array.
24+
*
25+
* @param arr the given array.
26+
*/
1927
public static void display(int[] arr) {
2028
StringBuilder toDisplay = new StringBuilder("[");
2129
for (int num : arr) {
2230
toDisplay.append(String.format("%d ", num));
2331
}
24-
toDisplay = toDisplay.replace(toDisplay.length()-1, toDisplay.length(), "]");
32+
toDisplay = toDisplay.replace(toDisplay.length() - 1, toDisplay.length(), "]");
2533
System.out.println(toDisplay);
2634
}
2735
}

src/main/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Implementation
1+
# Implementation
22

3-
This folder contains the source code for all the algorithms and data structures listed on the home page.
3+
This folder contains the source code for all the algorithms and data structures listed on the home page.

src/main/java/algorithms/binarySearch/BinarySearch.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
package algorithms.binarySearch;
22

3-
/** Here, we are implementing BinarySearch where we search an array for a target value at O(log n) time complexity.
4-
*
3+
/**
4+
* Here, we are implementing BinarySearch where we search an array for a target value at O(log n) time complexity.
5+
* <p>
56
* Assumptions:
67
* The array is sorted in ascending order.
78
* All elements in the array are unique. (to allow for easy testing)
8-
*
9+
* <p>
910
* Brief Description and Implementation Invariant:
1011
* With the assumption that the array is sorted in ascending order, BinarySearch reduces the search range by half or
1112
* half + 1 (due to floor division) after every loop. This is done by reassigning the max (high) or min (low) of the
1213
* search range to the middle of the search range when the target value is smaller than or larger than the current
1314
* middle value respectively, and continuing the search thereafter.
14-
*
15+
* <p>
1516
* In both scenarios where the target is not equal to arr[mid], the high and low pointers are reassigned mid decremented
1617
* /incremented by 1. This ensures that there will never be an infinite loop as the search range will no longer include
1718
* the mid-value, causing the search range to constantly "shrink". We know we can decrement/increment mid by 1 during
1819
* the reassignment as the mid-value is definitely not the target and should no longer be in the search range.
19-
*
20+
* <p>
2021
* At the end of every loop, we know that the target value is either within the search range or does not exist in the
2122
* array, thereby ensuring the correctness of the algorithm.
22-
*
23+
* <p>
2324
* Since after each iteration, the search range is halved, it will only take a maximum of O(log n) times before the
2425
* target is either found or determined to not exist in the array.
2526
*/
2627
public class BinarySearch {
2728
/**
2829
* Searches for a target value within a sorted array using the binary search algorithm.
29-
* @param arr the sorted array in which the search is to be performed.
30+
*
31+
* @param arr the sorted array in which the search is to be performed.
3032
* @param target the value to be searched for.
3133
* @return the index of the target if found, otherwise -1.
3234
*/
@@ -46,4 +48,4 @@ public static int search(int[] arr, int target) {
4648

4749
return -1;
4850
}
49-
}
51+
}

src/main/java/algorithms/binarySearch/BinarySearchTemplated.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
package algorithms.binarySearch;
22

3-
/** Here, we are implementing BinarySearchTemplated where we search an array for a target value at O(log n) time
3+
/**
4+
* Here, we are implementing BinarySearchTemplated where we search an array for a target value at O(log n) time
45
* complexity.
5-
*
6+
* <p>
67
* Assumptions:
78
* The array is sorted in ascending order.
89
* All elements in the array are unique. (to allow for easy testing)
9-
*
10+
* <p>
1011
* Brief Description and Implementation Invariant:
1112
* With the assumption that the array is sorted in ascending order, BinarySearchTemplated reduces the search range by
1213
* half or half + 1 (due to floor division) after every loop. This is done by reassigning the max (high) or min (low) of
1314
* the search range to the middle of the search range when the target value is smaller than or larger than the current
1415
* middle value respectively, and continuing the search thereafter.
15-
*
16+
* <p>
1617
* In this version, there is no condition to check if the current mid is equal to the target to prematurely end the
1718
* search. Hence, the only way for the loop to complete is when low exceeds high.
18-
*
19+
* <p>
1920
* At the end of every loop, we know that the target value is either within the search range or does not exist in the
2021
* array, thereby ensuring the correctness of the algorithm.
21-
*
22+
* <p>
2223
* Since after each iteration, the search range is halved, it will only take a maximum of O(log n) times before the
2324
* target is either found or determined to not exist in the array.
2425
*/
2526
public class BinarySearchTemplated {
2627
/**
2728
* A utility method to compare two integers.
28-
* @param value The current value from the array.
29+
*
30+
* @param value The current value from the array.
2931
* @param target The value being searched for.
3032
* @return true if the current value is less than the target, otherwise false.
3133
*/
@@ -37,7 +39,7 @@ public static boolean condition(int value, int target) {
3739
/**
3840
* Conducts a binary search to find the target within the sorted array.
3941
*
40-
* @param arr The sorted input array.
42+
* @param arr The sorted input array.
4143
* @param target The value to be searched within the array.
4244
* @return The index of the target value if found, otherwise -1.
4345
*/
@@ -63,4 +65,4 @@ public static int search(int[] arr, int target) {
6365
// Returns -1 if loop was exited without finding the target
6466
return -1;
6567
}
66-
}
68+
}

0 commit comments

Comments
 (0)