Skip to content

Commit bfefa52

Browse files
committed
improve clarity
1 parent 48870c9 commit bfefa52

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Gradle is used for development.
3838
- [Monotonic Queue](src/main/java/dataStructures/queue/monotonicQueue)
3939
- [Segment Tree](src/main/java/dataStructures/segmentTree)
4040
- [Stack](src/main/java/dataStructures/stack)
41-
- [Segment Tree](src/main/java/dataStructures/segmentTree)
4241
- [Trie](src/main/java/dataStructures/trie)
4342

4443
## Algorithms

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# AVL Trees
22

33
## Background
4-
Is the fastest way to search for data to store them in an array, sort them and perform binary search? No. This will
5-
incur minimally O(nlogn) sorting cost, and O(n) cost per insertion to maintain sorted order.
4+
Say you want to search of a data in an array. If the array were sorted, lucky you! You can do it with binary search in
5+
`O(logn)` time. But if the array weren't sorted, you can't avoid that `O(n)` linear search loop. Now, one idea is to
6+
first sort the array, and incur a 1-time cost of `O(n)` and subsequent search operations can enjoy that `O(logn)` query
7+
cost. This is all gucci, but it assumes that there will be no additional data streaming in. If incoming data is not
8+
infrequent, you'll have to incur `O(n)` insertion cost each time to maintain sorted order, and this can undermine
9+
performance as a whole. If only there were some structure that allows us to enjoy `O(logn)` operations across..
610

711
We have seen binary search trees (BSTs), which always maintains data in sorted order. This allows us to avoid the
812
overhead of sorting before we search. However, we also learnt that unbalanced BSTs can be incredibly inefficient for
9-
insertion, deletion and search operations, which are O(h) in time complexity (in the case of degenerate trees,
10-
operations can go up to O(n)).
13+
insertion, deletion and search operations, which are O(height) in time complexity (in the case of degenerate trees,
14+
think of a linked list, operations can go up to O(n)).
1115

1216
Here we discuss a type of self-balancing BST, known as the AVL tree, that avoids the worst case O(n) performance
1317
across the operations by ensuring careful updating of the tree's structure whenever there is a change

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ a balanced tree and hence complexity does not necessarily improve
2828
- Note, this is not implemented but details can be found under weighted union folder.
2929

3030
3. **Weighted Union** - Same idea of using a tree, but constructed in a way that the tree is balanced, leading to
31-
4. improved complexities. Can be further augmented with path compression.
31+
improved complexities.
32+
- Can be further augmented with path compression.
3233

3334
## Applications
3435
Because of its efficiency and simplicity in implementing, Disjoint Set structures are widely used in practice:
@@ -38,6 +39,7 @@ Because of its efficiency and simplicity in implementing, Disjoint Set structure
3839
- Or even analyse social networks, finding communities and determining if two users are connected through a chain
3940
3. Can be part of clustering algorithms to group data points based on similarity - useful for ML
4041
4. It can be used to detect cycles in dependency graphs, e.g, software dependency management systems
42+
1. Static analysis tools like `mypy` use this to identify circular dependencies!
4143
5. It can be used for image processing, in labelling different connected components of an image
4244

4345
## Notes

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ and check if they are equal. This is why this implementation is known as "Quick
2323
## Complexity Analysis
2424
Let n be the number of elements in consideration.
2525

26-
**Time**: O(n) for Union and O(1) for Find operations
26+
**Time**:
27+
- Union: O(n)
28+
- Find: O(1)
2729

2830
**Space**: O(n) auxiliary space for the component identifier
2931

0 commit comments

Comments
 (0)