Skip to content

Commit e4895d8

Browse files
authored
Merge pull request #75 from 4ndrelim/branch-RoutineCleanUp
docs: Improve clarity and clean-up some parts
2 parents fbf1883 + aa47450 commit e4895d8

File tree

12 files changed

+101
-182
lines changed

12 files changed

+101
-182
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,28 @@ Gradle is used for development.
108108
* Prim's
109109
* Kruskal's
110110

111-
## Running Custom Inputs
112-
See [here](scripts/README.md).
111+
## Set-up
112+
If you are a CS2040s student, your IDEA configurations should already be compatible with this project structure. So,
113+
feel free to clone and use it as you see fit. Note, below configuration is as per CS2040s PS1 set-up guide.
114+
115+
1. Choose Java Version 11.0.XX for Project SDK. You can download it [here](https://www.oracle.com/java/technologies/downloads/#java11)
116+
- Create account and login if necessary
117+
- Make sure to download the correct one compatible with your hardware
118+
2. Download IntelliJ (Community Edition) [here](https://www.jetbrains.com/idea/download/?section=mac) if you do not have it.
119+
3. Fork the repo and clone it on your local device
120+
4. Launch IntelliJ on your device and under the `Projects` tab, and click `open`. Navigate to where the local repo is
121+
cloned
122+
1. Configure to Java SDK (if not done) by first heading to `File` on the top-left panel,
123+
2. Click on `Project Structure...`
124+
3. Apply the desired Java SDK in the `SDK:` dropdown. Remember to click `Apply`.
125+
5. You can test if everything is properly set-up with the command: <br/>
126+
`./gradlew clean test` <br/>
127+
All files should be compiled and all testcases should pass.
128+
129+
## Usage
130+
The resources here can be directly viewed from GitHub interface, but it is advisable for you to fork and clone
131+
it to your local desktop, especially if you wish to tweak or play with custom inputs. There is a folder where you can
132+
import and run the algorithms/structures here for your own input. See [here](scripts/README.md).
113133

114134
## Disclaimer
115135
While our team of TAs and students have diligently verified the correctness of our code, there might still be

docs/team/profiles.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Team Profile
22

3-
| Name | Description/About | Website (LinkedIn/GitHub/Personal) | Contributions |
4-
|-----------|----------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
5-
| Andre | Aspiring ML engineer. My stint as a CS2040s TA has convinced several capable and passionate students to develop this together :) | You can find me [here](https://4ndrelim.github.io)! | Team lead |
6-
| Kai ting | ... | ... | Cool sorting and obscure trees! B-Trees, ORS.. |
7-
| Changxian | ... | ... | Hashing variants! BTS DevOps - configure Gradle & workflows |
8-
| Shu Heng | Interested in ML, aspiring researcher. | No website but here's my [Linkedin](https://www.linkedin.com/in/yeoshuheng), please give me a job :< | CS Fundamentals! Stacks and queues! RB-tree. |
9-
| Junneng | Aspiring tech entrepreneur. | [LinkedIn](https://www.linkedin.com/in/soo-jun-neng/) | Binary Search variants, Minimum Spanning Trees! |
10-
| Amadeus | ... | ... | Graphs! |
11-
| Owen | ... | ... | Graphs and confusing mazes |
3+
| Name | Description/About | Website (LinkedIn/GitHub/Personal) | Contributions |
4+
|-----------|-------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
5+
| Andre | Aspiring ML engineer. Developing this with wonderful ex-students. | You can find me [here](https://4ndrelim.github.io)! | Team lead |
6+
| Kai ting | Likes algorithms and a committed TA! | [Hi](https://www.linkedin.com/in/kai-ting-ho-425181268/) | Cool sorting and obscure trees! B-Trees, ORS.. |
7+
| Changxian | DevOps is right up his alley! | ... | Hashing variants! BTS DevOps - configure Gradle & workflows |
8+
| Shu Heng | Interested in ML, aspiring researcher. | No website but here's my [Linkedin](https://www.linkedin.com/in/yeoshuheng), please give me a job :< | CS Fundamentals! Stacks and queues! RB-tree. |
9+
| Junneng | Aspiring tech entrepreneur. | [LinkedIn](https://www.linkedin.com/in/soo-jun-neng/) | Binary Search variants, Minimum Spanning Trees! |
10+
| Amadeus | ... | ... | Graphs! |
11+
| Owen | ... | ... | Graphs and confusing mazes |

scripts/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Running On Custom Inputs
22

3-
This folder allows you to pass user input and view the output after running the desired algorithm.
3+
This folder allows you to run the algorithm/structures on any custom input you pass in.
44

5-
Simply run the file via IntelliJ in the respective folder.
5+
Simply create a file of the similar structure as in the src/ folder or import the respective package to call the
6+
algorithm/structure in the `main` method of the file you create. Then, run the file via IntelliJ as per normal.
7+
8+
Some samples are shown.

scripts/algorithms/sorting/RunCountingSort.java renamed to scripts/algorithms/sorting/countingSort/RunCountingSort.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
package algorithms.sorting;
2-
3-
import algorithms.sorting.countingSort.CountingSort;
1+
package algorithms.sorting.countingSort;
42

53
/**
64
* Script to run Counting Sort.
@@ -15,8 +13,8 @@ public class RunCountingSort {
1513
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
1614

1715
public static void main(String[] args) {
18-
toSort = CountingSort.sort(toSort);
19-
display(toSort);
16+
int[] sorted = CountingSort.sort(toSort);
17+
display(sorted);
2018
}
2119

2220
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package algorithms.sorting.insertionSort;
2+
3+
/**
4+
* Script to run Insertion Sort.
5+
*/
6+
public class RunInsertionSort {
7+
8+
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
9+
////////////////////////////////////////// This section is for user input \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
10+
private static int[] toSort =
11+
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};
12+
13+
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
14+
15+
public static void main(String[] args) {
16+
int[] sorted = InsertionSort.sort(toSort);
17+
display(sorted);
18+
}
19+
20+
/**
21+
* Prints the string representation of the array.
22+
*
23+
* @param arr the given array.
24+
*/
25+
public static void display(int[] arr) {
26+
StringBuilder toDisplay = new StringBuilder("[");
27+
for (int num : arr) {
28+
toDisplay.append(String.format("%d ", num));
29+
}
30+
toDisplay = toDisplay.replace(toDisplay.length() - 1, toDisplay.length(), "]");
31+
System.out.println(toDisplay);
32+
}
33+
}

src/main/java/algorithms/sorting/quickSort/lomuto/QuickSort.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ private static int partition(int[] arr, int start, int end) {
5151

5252
swap(arr, start, pIdx); // swap the pivot to the start of the array
5353

54-
int less = start + 1;
54+
int idx = start + 1; // interpret: at the end, all elements at indices less than this var is <= pivot
5555

5656
for (int i = start + 1; i <= end; i++) {
5757
if (arr[i] <= pivot) {
58-
swap(arr, less, i);
59-
less++;
58+
swap(arr, idx, i);
59+
idx++;
6060
}
6161
}
6262

63-
swap(arr, less - 1, start); // swap the pivot to its correct position
63+
swap(arr, idx - 1, start); // swap the pivot to its correct position
6464

65-
return less - 1;
65+
return idx - 1;
6666
}
6767

6868
/**

src/main/java/algorithms/sorting/quickSort/paranoid/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Paranoid QuickSort
22

33
## Background
4-
Paranoid Quicksort is the naive quicksort with an additional check to guarantee a good pivot.
4+
Paranoid Quicksort is the naive quicksort with that allow additional attempts to guarantee a good pivot selection.
55

66
![ParanoidQuickSort](../../../../../../../docs/assets/images/ParanoidQuickSort.jpeg)
77

src/main/java/algorithms/sorting/quickSort/threeWayPartitioning/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Three-Way Partitioning
22

33
## Background
4-
Three-way partitioning is used in QuickSort to tackle the scenario where there are many duplicate elements in the
5-
array being sorted.
4+
Three-way partitioning is an improved partitioning scheme, used in QuickSort, to tackle the scenario where there are
5+
many duplicate elements. This partitioning scheme will resolve the infinite loop error possibly faced by
6+
Paranoid Quicksort.
67

78
The idea behind three-way partitioning is to divide the array into three sections: elements less than the pivot,
89
elements equal to the pivot, and elements greater than the pivot. By doing so, we can avoid unnecessary comparisons
910
and swaps with duplicate elements, making the sorting process more efficient.
1011

12+
Note that during the partitioning process, there would be a 4th region - 'In Progress' region that will hold elements
13+
that haven't yet been placed in the right section (see below).
14+
1115
![ThreeWayPartitioning](../../../../../../../docs/assets/images/ThreeWayPartitioning.jpeg)
1216

1317
## Implementation Invariant:

src/main/java/dataStructures/bTree/README.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
# B-Trees
22

3-
### Table of Contents
4-
- [Background](#background)
5-
- [(a,b) trees](#-ab--trees)
6-
- [Implementation Invariants/(a,b) Tree Rules](#implementation-invariants--ab--tree-rules)
7-
- [Complexity Analysis](#complexity-analysis)
8-
- [How do B Trees relate to (a,b) trees?](#how-do-b-trees-relate-to--ab--trees)
9-
- [Search Operation](#search-operation)
10-
- [Insert Operation](#insert-operation)
11-
- [Split Child Method](#split-child-method)
12-
- [Delete Operation](#delete-operation)
13-
- [Application](#application)
14-
15-
163
## Background
174
Is the fastest way to search for data to store them in an array, sort them and perform binary search? No. This will
185
incur minimally O(nlogn) sorting cost, and O(n) cost per insertion to maintain sorted order. <br>
@@ -76,7 +63,7 @@ Rule #3: Leaf depth
7663
All leaf nodes must be at the same depth from root.
7764
- This property forces the tree to be balanced.
7865

79-
### Complexity Analysis
66+
## Complexity Analysis
8067

8168
**Search, Insertion, Deletion Time**: O(bloga(n)) = O(logn)
8269

@@ -90,20 +77,22 @@ where n is the number of elements (whatever the structure, it must store at leas
9077
## How do B Trees relate to (a,b) trees?
9178
A B-Tree is an (a,b) tree with a = ceil(b/2).
9279

93-
There are varying definitions of B-trees but we will be following the CLRS definition: a B tree is parameterized by
80+
There are varying definitions of B-trees, but we will be following the CLRS definition: a B tree is parameterized by
9481
a value t >= 2, known as its minimum degree.
9582
- Every internal node other than the root has at least t children.
9683
- Following this definition, t = a in the naming convention of (a,b) trees.
9784

98-
## Search Operation
85+
## Operations
86+
87+
### Search Operation
9988
Here is an outline of the search operation:
10089
1. Begin the search at the root of the B tree.
10190
2. If the key being searched for is in the current node, return true (i.e. found).
10291
3. Else, determine the child node where the key might be located based on comparison with the keys in the current node.
10392
4. Recursively perform the search operation in the determined child node.
10493
5. If the search reaches a leaf node, and the key is not found, return false (i.e. not found).
10594

106-
## Insert Operation
95+
### Insert Operation
10796
You can read more about how the insert operation works
10897
[here](https://www.geeksforgeeks.org/insert-operation-in-b-tree/).
10998

@@ -121,7 +110,7 @@ datasets by optimizing disk accesses.
121110

122111
Large amounts of data have to be stored on the disk. But disk I/O operations are slow and not knowing where to look
123112
for the data can drastically worsen search time. B-Tree is used as an index structure to efficiently locate the
124-
desired data. Note, the B-Tree itself can be partially stored in RAM (higher levels) and and partially on disk
113+
desired data. Note, the B-Tree itself can be partially stored in RAM (higher levels) and partially on disk
125114
(lower, less freq accessed levels).
126115

127116
Consider a database of all the CS modules offered in NUS. Suppose there is a column "Code" (module code) in the
@@ -134,7 +123,7 @@ data can be found. For e.g., a key for "CS2040s" would have a pointer to the dis
134123
and find the disk location of the desired data without having to scan the whole "CS Modules" table.
135124

136125
The choice of t will impact the height of the tree, and hence how fast the query is. Trade-off would be space, as a
137-
higher t means more keys in each node and they would have to be (if not already) loaded to RAM.
126+
higher t means more keys in each node, and they would have to be (if not already) loaded to RAM.
138127

139128
## References
140-
This description heavily references CS2040S Recitation Sheet 4.
129+
This description heavily references CS2040S Recitation Sheet 4.

src/main/java/dataStructures/disjointSet/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
A disjoint-set structure also known as a union-find or merge-find set, is a data structure
66
keeps track of a partition of a set into disjoint (non-overlapping) subsets.
77

8-
In CS2040s, this
9-
is introduced in the context of checking for dynamic connectivity. For instance, Kruskal's algorithm
8+
In CS2040s, this is introduced in the context of checking for dynamic connectivity. For instance, Kruskal's algorithm
109
in graph theory to find minimum spanning tree of a graph utilizes disjoint set to efficiently
1110
query if there already exists a path between 2 nodes.
1211

@@ -42,4 +41,4 @@ Because of its efficiency and simplicity in implementing, Disjoint Set structure
4241

4342
## Notes
4443
Disjoint Set is a data structure designed to keep track of a set of elements partitioned into a number of
45-
non-overlapping subsets. **It is not suited for handling duplicates** and so our implementation ignores duplicates.
44+
non-overlapping subsets. **It is not suited for handling duplicates**, so our implementation ignores duplicates.

0 commit comments

Comments
 (0)