Skip to content

I've written some important Algorithms and Data Structures in an efficient way in Java with references to time and space complexity. These Pre-cooked and well-tested codes help to implement larger hackathon problems in lesser time. DFS, BFS, LCA, LCS, Segment Tree, Sparce Table, All Pair Shortest Path, Binary Search, Matching and many more ...

License

Notifications You must be signed in to change notification settings

joney000/Java-Competitive-Programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java-Competitive-Programming

In This Repository, I have written some of the important Algorithms and Data Structures efficiently in Java with proper references to time and space complexity. These Pre-cooked and well-tested codes helps to implement larger hackathon problems in lesser time.

Algorithms:

AlgorithmBig-O Time, Big-O SpaceComments/Symbols
DFS - 2-D GridO(M * N), O(M * N)M * N = dimensions of matrix
DFS - Adjency ListO(V + E), O(V + E)V = No of vertices in Graph, E = No of edges in Graph
BFS - 2-D GridO(M * N), O(M * N)M * N = dimensions of matrix
BFS - Adjency ListO(V + E), O(V + E)V = No of vertices in Graph, E = No of edges in Graph
LCA - Lowest Common AncestorO(V), O(V)
LCA - Using Seg TreeO(log V), O(V + E)Using Euler tour and Segment Tree, preprocessing/building tree = O(N) & Each Query = O(log N)
All Pair Shortest PathO(V^3), O(V + E)Floyd Warshall algorithm
Longest Common SubsequenceO(M * N), O(M * N)Finding LCS of N & M length string using Dynamic Programming
Binary SearchO(log(N), O(N)Search in N size sorted array
Lower Bound SearchO(log(N), O(1)Unlike C, Java Doesn't Provide Lower Bound, Upper Bound for already sorted elements in the Collections
Upper Bound SearchO(log(N), O(1)
Maximal MatchingO(√V x E), O(V + E)Maximum matching for bipartite graph using Hopcroft-Karp algorithm
Minimum Cost Maximal Matching - Hungarian algorithmO(N^3), O(N^2)
Matrix ExponentiationO(N^3 * log(X)) ,O(M * N)Exponentiation by squaring / divide and conquer MATRIX[N, N] ^ X
Segment TreeO(Q * log(N)), O(N)Q = no of queries , N = no of nodes , per query time = O(log N)
Segment Tree Lazy PropagationO(Q * log(N)), O(N)Q = no of queries , N = no of nodes , tree construction time = O(N), per query time = O(log N), range update time: O(log N)
Sparse TableO(Q * O(1) + N * log(N)), O(N * log(N))per query time = O(1) and precompute time and space: O(N * log(N))
Merge SortO(N * log(N)), O(N)divide and conquer algorithm
Miller Prime Testsoft-O notation Õ((log n)^4) with constant space
Kruskal- Minimum Spanning TreeO(E log V) , O(V + E)
BIT - Binary Index Tree / Fenwick TreeO(log N), O(N)per query time: O(log(N))
Two PointersO(N), O(N)two directional scan on sorted array
Binary Search Tree - BSTO(N), O(N)
Maximum Subarray SumO(N), O(N)Kadane's algorithm
Immutable Data Structures, Persistent Data Structurs - Persistent TrieO(N * log N), O(N)query & update time: O(log N). It's frequently used where you have to maintain multiple version of your data structure typically in lograthimic time.
DijkstraO((E+v) log V)), O(V + E)
Z - FunctionO(P + T), O(P + T)Leaner time string matching / occurrence finding of pattern string P into Large Text string T.
Heavy Light DecompositionO(N * log^2 N), O(N)per query time = (log N)^2
Interval MergeO(log N), O(N)
KnapsackO(N * S), (N * S)N = elements, S = MAX_Sum
Suffix Array and LCP - Longest Common PrefixO(N * log(N)), O(N)
Squre Root DecompositionO(N * √N), O(N)the range of N number can be divided in √N blocks
Kth Order StaticsO(N), O(N)K’th Smallest/Largest Element in Unsorted Array
Trie / Prefix TreeO(N * L), O(N * L)if there are N strings of L size, per query time(Prefix information) = O(L)
LIS - Longest Increasing SubsequenceO(N * log(N)), O(N)
Priority QueueO(log(N)), O(N)N = no of objects in the queue. peek: O(1), poll/add: O(log n)
MultisetO(log(N)), O(N)N = no of objects in the multiset. get/add: O(log n) and Average Case O(1)
MillerRabinO(log(N)), O(1)deterministic algorithm to identify if a number is prime or not
Disjoint Set Union - DSUO(log(N)), O(N)merge disjoint sets with O(log n) merge operation with path optimization

Contributions

Want to contribute to corrections or enhancement or any new idea around algorithms? Great! Please raise a PR, or drop a mail at developer.jaswant@gmail.com .

I also highly recommend reading Introduction to Algorithms(CLRS book) and same algorithm implementation from other authors, it will give you a diverse set of ideas to solve the same algorithmic challenge.

You can buy me a coffee if you find the implementation helpful. :) https://www.buymeacoffee.com/devjassi

About

I've written some important Algorithms and Data Structures in an efficient way in Java with references to time and space complexity. These Pre-cooked and well-tested codes help to implement larger hackathon problems in lesser time. DFS, BFS, LCA, LCS, Segment Tree, Sparce Table, All Pair Shortest Path, Binary Search, Matching and many more ...

Topics

Resources

License

Stars

Watchers

Forks

Languages

close