Skip to content

Commit 1713518

Browse files
committed
Merge branch 'main' into branch-RefactorKMP
2 parents 778283d + d55074b commit 1713518

File tree

14 files changed

+619
-430
lines changed

14 files changed

+619
-430
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Gradle is used for development.
3434
- [Monotonic Queue](src/main/java/dataStructures/queue/monotonicQueue)
3535
- Segment Tree
3636
- [Stack](src/main/java/dataStructures/stack)
37-
- Trie
37+
- [Trie](src/main/java/dataStructures/trie)
3838

3939
## Algorithms
4040
- [Bubble Sort](src/main/java/algorithms/sorting/bubbleSort)
@@ -81,9 +81,9 @@ Gradle is used for development.
8181
* [Binary search tree](src/main/java/dataStructures/binarySearchTree)
8282
* AVL-tree
8383
* Orthogonal Range Searching
84-
* Trie
84+
* [Trie](src/main/java/dataStructures/trie)
8585
* B-Tree
86-
* * Red-Black Tree (Not covered in CS2040s but useful!)
86+
* Red-Black Tree (Not covered in CS2040s but useful!)
8787
* Kd-tree (**WIP**)
8888
* Interval tree (**WIP**)
8989
5. [Binary Heap](src/main/java/dataStructures/heap) (Max heap)

docs/assets/images/Trie.png

454 KB
Loading

src/main/java/algorithms/patternFinding/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ in text editors when searching for a pattern, in computational biology sequence
99
in NLP problems, and even for looking for file patterns for effective file management.
1010
It is hence crucial that we develop an efficient algorithm.
1111

12+
Typically, the algorithm returns a list of indices that denote the start of each occurrence of the pattern string.
13+
1214
![KMP](../../../../../docs/assets/images/kmp.png)
1315
Image Source: GeeksforGeeks
1416

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Quick Union
2-
2+
If you wish to jump to [weighted union](#Weighted-Union).
33
## Background
44
Here, we consider a completely different approach. We consider the use of trees. Every element can be
55
thought of as a tree node and starts off in its own component. Under this representation, it is likely

src/main/java/dataStructures/hashSet/chaining/HashSet.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public HashSet() {
6767
* @return the number of elements in this set (its cardinality)
6868
*/
6969
public int size() {
70-
return this.size;
70+
return size;
7171
}
7272

7373
/**
@@ -76,13 +76,12 @@ public int size() {
7676
* @return true if this set contains no elements
7777
*/
7878
public boolean isEmpty() {
79-
return this.size() == 0;
79+
return size() == 0;
8080
}
8181

8282
/**
83-
* TODO formal documentation.
8483
* Simple hash function to hash the element into their respective bucket.
85-
* Currently uses the division method (k % m).
84+
* Currently, uses the division method (k % m).
8685
* T must override both Object::equals and Object::hashCode.
8786
*
8887
* @param element the specified element to be hashed.
@@ -104,12 +103,12 @@ private int hashFunction(T element) {
104103
* element
105104
*/
106105
public boolean add(T element) {
107-
int bucket = this.hashFunction(element);
108-
LinkedList<T> bucketLinkedList = this.buckets[bucket];
106+
int bucket = hashFunction(element);
107+
LinkedList<T> bucketLinkedList = buckets[bucket];
109108
if (bucketLinkedList.search(element) != -1) {
110109
return false; // element is already in the set.
111110
}
112-
++this.size; // updates the cardinality of this hashset.
111+
++size; // updates the cardinality of this hashset.
113112
return bucketLinkedList.insertFront(element);
114113
}
115114

@@ -120,8 +119,8 @@ public boolean add(T element) {
120119
* @return true if this set contains the specified element
121120
*/
122121
public boolean contains(T element) {
123-
int bucket = this.hashFunction(element);
124-
LinkedList<T> bucketLinkedList = this.buckets[bucket];
122+
int bucket = hashFunction(element);
123+
LinkedList<T> bucketLinkedList = buckets[bucket];
125124
return bucketLinkedList.search(element) != -1;
126125
}
127126

@@ -137,14 +136,14 @@ public boolean contains(T element) {
137136
* @return true if this set contained the specified element
138137
*/
139138
public boolean remove(T element) {
140-
int bucket = this.hashFunction(element);
141-
LinkedList<T> bucketLinkedList = this.buckets[bucket];
139+
int bucket = hashFunction(element);
140+
LinkedList<T> bucketLinkedList = buckets[bucket];
142141
int index = bucketLinkedList.search(element);
143142
if (index == -1) {
144143
return false; // If the element is not in the hashset.
145144
}
146145
bucketLinkedList.remove(index);
147-
--this.size; // updates the cardinality of the hash set.
146+
--size; // updates the cardinality of the hash set.
148147
return true;
149148
}
150149

@@ -155,7 +154,7 @@ public boolean remove(T element) {
155154
*/
156155
public List<T> toList() {
157156
List<T> outputList = new ArrayList<>();
158-
for (LinkedList<T> bucket : this.buckets) {
157+
for (LinkedList<T> bucket : buckets) {
159158
while (bucket.size() != 0) {
160159
outputList.add(bucket.pop());
161160
}

0 commit comments

Comments
 (0)