Repository navigation
Expand go java implementations - #1
Conversation
- UnionFind: add WeightedUnionFind, numIslands, findRedundantConnection - LruCache: add peek, remove, resize, keys/values/entries iteration, eviction tracking - BloomFilter: add CountingBloomFilter and ScalableBloomFilter variants - AdjacencyMatrix: add BFS, DFS, Floyd-Warshall, transitive closure, hasPath - Trie: add TrieMap key-value store and WordDictionary wildcard search - Heap: add kWayMerge, topKFrequent, MedianFinder two-heap approach - LfuCache: add getFrequency, remove, peek, putIfAbsent, min/max frequency - FenwickTree: add FenwickTree2D and countInversions utility - Queue: add slidingWindowMaximum, PriorityDeque, expanded Deque operations - SinglyLinkedList: add mergeSorted, map/filter/reduce, isPalindrome - DoublyLinkedList: add insertAfter/insertBefore, map/filter, forEach variants - Comprehensive tests for all new features
…ethods - Searching: add two-pointer (twoSumSorted, threeSum, containerWithMostWater), sliding window (longestSubstringWithoutRepeating, minWindowSubstring, findAllAnagrams, maxSumSubarray), findRotationPoint, sqrtInt - Sorting: add bucketSort, timSort, quickSelect, isStable utility - DynamicProgramming: add houseRobber I/II, unboundedKnapsack, longestPalindromicSubsequence, canPartition, minCostClimbingStairs, numDecodings, maximalSquare, LIS with sequence reconstruction - StringAlgorithms: add Boyer-Moore, shortestPalindrome, longestHappyPrefix, countPalindromicSubstrings, LCP array, suffix array search, isSubsequence - GraphAlgorithms: add Floyd-Warshall, Prim MST, Kruskal MST, Tarjan SCC, Kosaraju SCC, isBipartite - Comprehensive tests for all new algorithms
Add methods to BST (CountNodes, Diameter, IsBalanced, Serialize, etc.), AVL (Floor, Ceiling, RangeQuery, KthSmallest), Red-Black tree (traversals, BlackHeight, RangeQuery), Skip List (Pop, Rank, ForEach), linked lists (IsPalindrome, Sort, Partition), and expand tests for bloom filters, hash tables, heaps, tries, union-find, and caches.
Add ArticulationPoints, Bridges (Tarjan's), ShortestPathUnweighted, InDegree, OutDegree, Degree, IsDAG, Transpose, AllPaths, CountPaths to GraphCore. Remove duplicate Degree/InDegree from graph_core.go. Add comprehensive tests for all new graph methods.
…nd strings Add sliding window (MinWindowSubstring, TrappingRainWater), two-pointer (FourSum, ContainerWithMostWater), sorting (TimSort, CombSort, DutchNationalFlag), DP (MatrixChain, SubsetSum, RodCutting, MaximalSquare), and string algorithms (BoyerMoore, Levenshtein, GroupAnagrams, RunLengthEncode) with tests.
Backtracking: Permutations, Subsets, CombinationSum, NQueens, Sudoku, GenerateParentheses, LetterCombinations, WordSearch, PalindromePartition, RestoreIPAddresses. Greedy: ActivitySelection, MergeIntervals, Huffman, JumpGame, GasStation, TaskScheduler, FractionalKnapsack, JobSequencing. Math: GCD, LCM, Sieve, PrimeFactors, FastPow, EulerTotient, ModInverse, NChooseK, CatalanNumber, bit manipulation. All with comprehensive tests.
There was a problem hiding this comment.
Pull request overview
This PR expands the Java and Go implementations of common data structures/algorithms by adding new capabilities (maps/advanced operations/utilities) and significantly extending test coverage to validate the new behaviors.
Changes:
- Added multiple new data structure variants and utility operations (e.g., trie map + word dictionary, weighted/persistent union-find, cache and linked-list helpers, heap utilities).
- Added new algorithm implementations (e.g., k-way merge, median finder, bucket/tim sort, additional DP routines, graph traversal/closure utilities).
- Added/expanded unit tests across Java and Go to cover the new APIs and edge cases.
Reviewed changes
Copilot reviewed 74 out of 74 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| by-language/java/src/test/java/dsa/datastructures/TrieTest.java | Adds tests for TrieMap and WordDictionary behaviors. |
| by-language/java/src/test/java/dsa/datastructures/SinglyLinkedListTest.java | Adds tests for newly added singly linked list operations. |
| by-language/java/src/test/java/dsa/datastructures/LfuCacheTest.java | Adds tests for new LFU cache APIs (frequency, remove, peek, etc.). |
| by-language/java/src/test/java/dsa/datastructures/HeapTest.java | Adds tests for k-way merge, top-k frequent, median finder, and median-of-two-arrays. |
| by-language/java/src/test/java/dsa/datastructures/FenwickTreeTest.java | Adds tests for 2D Fenwick tree and inversion counting. |
| by-language/java/src/test/java/dsa/datastructures/DoublyLinkedListTest.java | Adds tests for new doubly linked list operations. |
| by-language/java/src/test/java/dsa/datastructures/BloomFilterTest.java | Adds tests for CountingBloomFilter and ScalableBloomFilter. |
| by-language/java/src/test/java/dsa/datastructures/AdjacencyMatrixTest.java | Adds tests for new adjacency-matrix graph operations. |
| by-language/java/src/test/java/dsa/algorithms/StringAlgorithmsTest.java | Adds tests for additional string algorithms. |
| by-language/java/src/test/java/dsa/algorithms/SortingTest.java | Adds tests for new sorting/selection/stability APIs. |
| by-language/java/src/main/java/dsa/datastructures/UnionFind.java | Adds weighted union-find variant and additional union-find utilities. |
| by-language/java/src/main/java/dsa/datastructures/Trie.java | Adds TrieMap and WordDictionary implementations. |
| by-language/java/src/main/java/dsa/datastructures/SinglyLinkedList.java | Adds several list convenience operations (contains/set/array/palindrome/map/filter/reduce/merge/fromArray). |
| by-language/java/src/main/java/dsa/datastructures/Queue.java | Adds queue/deque/circular-queue helpers plus sliding window max and a priority deque. |
| by-language/java/src/main/java/dsa/datastructures/LruCache.java | Extends LRU cache API (peek/remove/keys/values/entries/resize/eviction count). |
| by-language/java/src/main/java/dsa/datastructures/LfuCache.java | Extends LFU cache API (frequency inspection, remove, peek, getOrDefault, etc.). |
| by-language/java/src/main/java/dsa/datastructures/Heap.java | Adds k-way merge, top-k frequent, median-of-two-arrays, and running median helper. |
| by-language/java/src/main/java/dsa/datastructures/FenwickTree.java | Adds 2D Fenwick tree and inversion counting utility. |
| by-language/java/src/main/java/dsa/datastructures/DoublyLinkedList.java | Adds multiple DLL convenience operations and higher-order helpers. |
| by-language/java/src/main/java/dsa/datastructures/BloomFilter.java | Adds counting and scalable bloom filter variants. |
| by-language/java/src/main/java/dsa/datastructures/AdjacencyMatrix.java | Adds traversal/path/closure/edge listing utilities to adjacency-matrix graph. |
| by-language/java/src/main/java/dsa/algorithms/Sorting.java | Adds bucket sort, tim sort, quickselect, stable sort wrapper, and stability lookup. |
| by-language/java/src/main/java/dsa/algorithms/DynamicProgramming.java | Adds several additional DP routines (house robber variants, LPS, decoding, etc.). |
| by-language/go/datastructures/union_find_test.go | Adds tests for persistent UF, redundant connection, components, weighted UF, etc. |
| by-language/go/datastructures/union_find.go | Adds persistent UF + extra UF helpers and weighted UF component count. |
| by-language/go/datastructures/trie_test.go | Extends trie tests; adds TrieMap + compressed trie tests. |
| by-language/go/datastructures/trie.go | Adds TrieMap and CompressedTrie implementations. |
| by-language/go/datastructures/skip_list_test.go | Adds tests for new skip list APIs. |
| by-language/go/datastructures/skip_list.go | Adds values/clear/level/rangeCount/foreach/getOrDefault/pop/rank helpers. |
| by-language/go/datastructures/singly_linked_list_test.go | Adds tests for multiple new singly linked list utilities. |
| by-language/go/datastructures/singly_linked_list.go | Adds palindrome/reversal/cycle detection/sort/merge/remove/rotate/partition utilities. |
| by-language/go/datastructures/red_black_tree_test.go | Adds tests for new RB-tree APIs (min/max/contains/stress/etc.). |
| by-language/go/datastructures/red_black_tree.go | Adds min/max/contains/height/traversals/queries/clear helpers. |
| by-language/go/datastructures/lru_cache.go | Extends Go LRU cache API (peek/resize/keys/values/items/iteration/etc.). |
| by-language/go/datastructures/heap_test.go | Adds tests for priority queue, heap merges, k-way merge, median finder, etc. |
| by-language/go/datastructures/heap.go | Adds stable priority queue, heap merge, k-way merge, and median finder. |
| by-language/go/datastructures/hash_table.go | Adds set ops and hash table convenience methods (union/intersection/etc., load factor, entries). |
| by-language/go/datastructures/graph_core.go | Removes degree helpers (moved to algorithms file). |
| by-language/go/datastructures/graph_algorithms.go | Adds articulation points, bridges, shortest path, degrees, DAG check, transpose, all paths. |
| by-language/go/datastructures/doubly_linked_list_test.go | Adds extensive tests for new DLL operations. |
| by-language/go/datastructures/doubly_linked_list.go | Adds reverse/iteration/palindrome/rotate/swap/sorted insert/merge/copy/clear helpers. |
| by-language/go/datastructures/cache_test.go | Adds extended LRU/LFU cache tests. |
| by-language/go/datastructures/bloom_filter_test.go | Adds tests for scalable BF, unions/intersections, estimates, sizing, etc. |
| by-language/go/datastructures/bloom_filter.go | Adds counting BF FP rate, scalable BF, union/intersection, estimate, and introspection helpers. |
| by-language/go/datastructures/avl_tree_test.go | Adds tests for newly added AVL APIs. |
| by-language/go/datastructures/avl_tree.go | Adds min/max/contains/traversals/range/floor/ceiling/kth/clear/values/count helpers. |
| by-language/go/algorithms/string_algorithms_test.go | Adds/extends string algorithm tests (BM, shortest palindrome, LPS, etc.). |
| by-language/go/algorithms/sorting_test.go | Adds tests for new sorting algorithms/utilities. |
| by-language/go/algorithms/sorting.go | Adds TimSort, comb/gnome/pancake/cycle sorts, iterative merge sort, DNF, and stability check. |
| by-language/go/algorithms/searching_test.go | Adds tests for additional searching/two-pointer/sliding-window problems. |
| by-language/go/algorithms/dynamic_programming_test.go | Adds tests for additional DP algorithms/utilities. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public static int[] slidingWindowMaximum(int[] nums, int k) { | ||
| if (nums == null || nums.length == 0 || k <= 0) { | ||
| return new int[0]; | ||
| } | ||
| int n = nums.length; | ||
| int[] result = new int[n - k + 1]; | ||
| ArrayDeque<Integer> deque = new ArrayDeque<>(); // stores indices |
There was a problem hiding this comment.
slidingWindowMaximum allocates new int[n - k + 1] without guarding k > n, which will throw NegativeArraySizeException. Consider returning an empty array (or throwing IllegalArgumentException) when k > nums.length.
| public Deque<T> reversed() { | ||
| Deque<T> result = new Deque<>(); | ||
| for (int i = data.size() - 1; i >= 0; i--) { | ||
| result.addRear(data.get(i)); | ||
| } | ||
| return result; |
There was a problem hiding this comment.
Deque.reversed() iterates indices and calls LinkedList.get(i) each time, which is O(n) per access; overall this makes reversed() O(n^2). Prefer iterating with a descending iterator / ListIterator from the end to keep this O(n).
| public List<Map.Entry<K, V>> entries() { | ||
| List<Map.Entry<K, V>> result = new ArrayList<>(); | ||
| Node<K, V> current = head.next; | ||
| while (current != tail) { | ||
| result.add(Map.entry(current.key, current.value)); | ||
| current = current.next; | ||
| } | ||
| return result; |
There was a problem hiding this comment.
entries() uses Map.entry(current.key, current.value), which throws NullPointerException if either the key or value is null. Since put()/get() don't reject null keys/values, this method can unexpectedly crash; either validate/disallow nulls at insertion, or build entries with an implementation that permits nulls (e.g., AbstractMap.SimpleEntry).
| func (puf *PersistentUnionFind) getParentAtVersion(x, version int) int { | ||
| parent := puf.parent[x] | ||
| for i := len(puf.history) - 1; i >= 0; i-- { | ||
| e := puf.history[i] | ||
| if e.version > version && e.index == x { | ||
| parent = e.oldParent | ||
| } | ||
| } | ||
| return parent |
There was a problem hiding this comment.
getParentAtVersion scans the entire history even after reaching entries with e.version <= version. Since history is appended in non-decreasing version order, you can break once e.version <= version to avoid an O(history) scan for every parent lookup.
No description provided.