Skip to content

Commit c207c28

Browse files
committed
Merged README
1 parent d2376e5 commit c207c28

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed

README.md

+156
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,22 @@ Algorithms and Data Structures implemented in Java
55

66
This is a collection of algorithms and data structures which I've implement over the years in my academic and professional life. The code isn't overly-optimized but is written to be correct and readable. The algorithms and data structures are well tested and, unless noted, are believe to be 100% correct.
77

8+
<<<<<<< HEAD
89
* Created by Justin Wetherell
10+
=======
11+
## Table of Contents
12+
- [Data Structures](#data-structures)
13+
- [Mathematics](#mathematics)
14+
- [Numbers](#numbers)
15+
- [Graphs](#graphs)
16+
- [Search](#search)
17+
- [Sequences](#sequences)
18+
- [Sorts](#sorts)
19+
- [String Functions](#string-functions)
20+
21+
## * Created by Justin Wetherell
22+
23+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
924
* For questions use: http://groups.google.com/forum/#!forum/java-algorithms-implementation
1025
* Google: http://code.google.com/p/java-algorithms-implementation
1126
* Github: http://github.com/phishman3579/java-algorithms-implementation
@@ -20,6 +35,7 @@ This is a collection of algorithms and data structures which I've implement over
2035
# What's been implemented:
2136

2237
## Data Structures
38+
<<<<<<< HEAD
2339
* AVL Tree
2440
* B-Tree
2541
* Binary Heap [backed by an array or a tree]
@@ -58,16 +74,61 @@ This is a collection of algorithms and data structures which I've implement over
5874
+ chebyshev
5975
+ euclidean
6076
* Division
77+
=======
78+
* [AVL Tree](src/com/jwetherell/algorithms/data_structures/AVLTree.java)
79+
* [B-Tree](src/com/jwetherell/algorithms/data_structures/BTree.java)
80+
* [Binary Heap (backed by an array or a tree)](src/com/jwetherell/algorithms/data_structures/BinaryHeap.java)
81+
* [Binary Search Tree](src/com/jwetherell/algorithms/data_structures/BinarySearchTree.java)
82+
* [Compact Suffix Trie (backed by a Patricia Trie)](src/com/jwetherell/algorithms/data_structures/CompactSuffixTrie.java)
83+
* [Disjoint Set](src/com/jwetherell/algorithms/data_structures/DisjointSet.java)
84+
* [Fenwick Tree {Binary Indexed Tree (BIT)}](src/com/jwetherell/algorithms/data_structures/FenwickTree.java)
85+
* [Graph](src/com/jwetherell/algorithms/data_structures/Graph.java)
86+
+ Undirected
87+
+ Directed (Digraph)
88+
* [Hash Array Mapped Trie (HAMT)](src/com/jwetherell/algorithms/data_structures/HashArrayMappedTrie.java)
89+
* [Hash Map (associative array)](src/com/jwetherell/algorithms/data_structures/HashMap.java)
90+
* [Interval Tree](src/com/jwetherell/algorithms/data_structures/IntervalTree.java)
91+
* [Implicit Key Treap]((src/com/jwetherell/algorithms/data_structures/ImplicitKeyTreap.java))
92+
* [KD Tree (k-dimensional tree or k-d tree)](src/com/jwetherell/algorithms/data_structures/KDTree.java)
93+
* [List [backed by an array or a linked list]]((src/com/jwetherell/algorithms/data_structures/List.java))
94+
* [Matrix](src/com/jwetherell/algorithms/data_structures/Matrix.java)
95+
* [Patricia Trie](src/com/jwetherell/algorithms/data_structures/PatriciaTrie.java)
96+
* [Quad-Tree (Point-Region or MX-CIF)](src/com/jwetherell/algorithms/data_structures/QuadTree.java)
97+
* [Queue [backed by an array or a linked list]](src/com/jwetherell/algorithms/data_structures/Queue.java)
98+
* [Radix Trie (associative array) [backed by a Patricia Trie]](src/com/jwetherell/algorithms/data_structures/RadixTree.java)
99+
* [Red-Black Tree](src/com/jwetherell/algorithms/data_structures/RedBlackTree.java)
100+
* [Segment Tree](src/com/jwetherell/algorithms/data_structures/SegmentTree.java)
101+
* [Skip List](src/com/jwetherell/algorithms/data_structures/SkipList.java)
102+
* [Splay Tree](src/com/jwetherell/algorithms/data_structures/SplayTree.java)
103+
* [Stack [backed by an array or a linked list]](src/com/jwetherell/algorithms/data_structures/Stack.java)
104+
* [Suffix Tree (Ukkonen's algorithm)](src/com/jwetherell/algorithms/data_structures/SuffixTree.java)
105+
* [Suffix Trie [backed by a Trie]](src/com/jwetherell/algorithms/data_structures/SufficTrie.java)
106+
* [Treap](src/com/jwetherell/algorithms/data_structures/Treap.java)
107+
* [Tree Map (associative array) [backed by an AVL Tree]](src/com/jwetherell/algorithms/data_structures/TreeMap.java)
108+
* [Trie](src/com/jwetherell/algorithms/data_structures/Trie.java)
109+
* [Trie Map (associative array) [backed by a Trie]](src/com/jwetherell/algorithms/data_structures/TrieMap.java)
110+
111+
## Mathematics
112+
* [Distance](src/com/jwetherell/algorithms/mathematics/Distance.java)
113+
+ chebyshev
114+
+ euclidean
115+
* [Division](src/com/jwetherell/algorithms/mathematics/Division.java)
116+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
61117
+ using a loop
62118
+ using recursion
63119
+ using shifts and multiplication
64120
+ using only shifts
65121
+ using logarithm
122+
<<<<<<< HEAD
66123
* Multiplication
124+
=======
125+
* [Multiplication](src/com/jwetherell/algorithms/mathematics/Multiplication.java)
126+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
67127
+ using a loop
68128
+ using recursion
69129
+ using only shifts
70130
+ using logarithms
131+
<<<<<<< HEAD
71132
+ using FFT
72133
* Primes
73134
+ is prime
@@ -81,14 +142,37 @@ This is a collection of algorithms and data structures which I've implement over
81142
+ strings
82143
+ numbers
83144
* Modular arithmetic
145+
=======
146+
+ [Fast Fourier Transform](src/com/jwetherell/algorithms/mathematics/FastFourierTransform.java)
147+
* [Primes](src/com/jwetherell/algorithms/mathematics/Primes.java)
148+
+ is prime
149+
+ prime factorization
150+
+ sieve of eratosthenes
151+
+ [Co-Primes (relatively prime, mutually prime)](src/com/jwetherell/algorithms/mathematics/Coprimes.java)
152+
+ [Greatest Common Divisor](src/com/jwetherell/algorithms/mathematics/GreatestCommonDivisor.java)
153+
- using Euclid's algorithm
154+
- using recursion
155+
* [Permutations](src/com/jwetherell/algorithms/mathematics/Permutations.java)
156+
+ strings
157+
+ numbers
158+
* [Modular arithmetic](src/com/jwetherell/algorithms/mathematics/Modular.java)
159+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
84160
+ add
85161
+ subtract
86162
+ multiply
87163
+ divide
88164
+ power
165+
<<<<<<< HEAD
89166

90167
## Numbers
91168
* Integers
169+
=======
170+
* [Knapsack](src/com/jwetherell/algorithms/mathematics/Knapsack.java)
171+
* [Ramer Douglas Peucker](src/com/jwetherell/algorithms/mathematics/RamerDouglasPeucker.java)
172+
173+
## Numbers
174+
* [Integers](src/com/jwetherell/algorithms/numbers/Integers.java)
175+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
92176
+ to binary String
93177
- using divide and modulus
94178
- using right shift and modulus
@@ -100,12 +184,20 @@ This is a collection of algorithms and data structures which I've implement over
100184
- using logarithm
101185
- using bits
102186
+ to English (e.g. 1 would return "one")
187+
<<<<<<< HEAD
103188
* Longs
189+
=======
190+
* [Longs](src/com/jwetherell/algorithms/numbers/Longs.java)
191+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
104192
+ to binary String
105193
- using divide and modulus
106194
- using right shift and modulus
107195
- using BigDecimal
196+
<<<<<<< HEAD
108197
* Complex
198+
=======
199+
* [Complex](src/com/jwetherell/algorithms/numbers/Complex.java)
200+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
109201
+ addition
110202
+ subtraction
111203
+ multiplication
@@ -114,6 +206,7 @@ This is a collection of algorithms and data structures which I've implement over
114206

115207
## Graphs
116208
* Find shortest path(s) in a Graph from a starting Vertex
209+
<<<<<<< HEAD
117210
- Dijkstra's algorithm (non-negative weight graphs)
118211
- Bellman-Ford algorithm (negative and positive weight graphs)
119212
* Find minimum spanning tree
@@ -144,10 +237,47 @@ This is a collection of algorithms and data structures which I've implement over
144237
* Find longest increasing subsequence (dynamic programming)
145238
* Find number of times a subsequence occurs in a sequence (dynamic programming)
146239
* Find i-th element in a Fibonacci sequence
240+
=======
241+
- [Dijkstra's algorithm (non-negative weight graphs)](src/com/jwetherell/algorithms/graph/Dijkstra.java)
242+
- [Bellman-Ford algorithm (negative and positive weight graphs)](src/com/jwetherell/algorithms/graph/BellmanFord.java)
243+
* Find minimum spanning tree
244+
- [Prim's (undirected graphs)](src/com/jwetherell/algorithms/graph/Prim.java)
245+
- [Kruskal's (undirected graphs)](src/com/jwetherell/algorithms/graph/Kruskal.java)
246+
* Find all pairs shortest path
247+
- [Johnsons's algorithm (negative and positive weight graphs)](src/com/jwetherell/algorithms/graph/Johnsons.java)
248+
- [Floyd-Warshall (negative and positive weight graphs)](src/com/jwetherell/algorithms/graph/FloydWarshall.java)
249+
* [Cycle detection](src/com/jwetherell/algorithms/graph/CycleDetection.java)
250+
- Depth first search while keeping track of visited Verticies
251+
- [Connected Components](src/com/jwetherell/algorithms/graph/ConnectedComponents.java)
252+
* [Topological sort](src/com/jwetherell/algorithms/graph/TopologicalSort.java)
253+
* [A* path finding algorithm](src/com/jwetherell/algorithms/graph/AStar.java)
254+
* Maximum flow
255+
- [Push-Relabel](src/com/jwetherell/algorithms/graph/PushRelabel.java)
256+
* Graph Traversal
257+
- [Depth First Traversal](src/com/jwetherell/algorithms/graph/DepthFirstTravesal.java)
258+
* [Edmonds Karp](src/com/jwetherell/algorithms/graph/EdmondsKarp.java)
259+
260+
## Search
261+
* Get index of value in array
262+
+ [Linear](src/com/jwetherell/algorithms/Sequences/LinearSearch.java)
263+
+ [Quickselect](src/com/jwetherell/algorithms/Sequences/QuickSelect.java)
264+
+ [Binary [sorted array input only]](src/com/jwetherell/algorithms/Sequences/BinarySearch.java)
265+
+ [Lower bound [sorted array input only]](src/com/jwetherell/algorithms/Sequences/LpperBound.java)
266+
+ [Upper bound [sorted array input only]](src/com/jwetherell/algorithms/Sequences/UpperBound.java)
267+
+ Optimized binary (binary until a threashold then linear) [sorted array input only]
268+
+ [Interpolation [sorted array input only]](src/com/jwetherell/algorithms/Sequences/InterpolationSearch.java)
269+
270+
## Sequences
271+
* [Find longest common subsequence (dynamic programming)](src/com/jwetherell/algorithms/Sequences/LongestCommonSubsequence.java)
272+
* [Find longest increasing subsequence (dynamic programming)](src/com/jwetherell/algorithms/Sequences/LongestIncreasingSubsequence.java)
273+
* [Find number of times a subsequence occurs in a sequence (dynamic programming)](src/com/jwetherell/algorithms/Sequences/SubsequenceCounter.java)
274+
* [Find i-th element in a Fibonacci sequence](src/com/jwetherell/algorithms/Sequences/FibonacciSequence.java)
275+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
147276
+ using a loop
148277
+ using recursion
149278
+ using matrix multiplication
150279
+ using Binet's formula
280+
<<<<<<< HEAD
151281
* Find total of all elements in a sequence
152282
+ using a loop
153283
+ using Triangular numbers
@@ -166,6 +296,27 @@ This is a collection of algorithms and data structures which I've implement over
166296
* Shell's Sort
167297

168298
## String Functions
299+
=======
300+
* [Find total of all elements in a sequence(Arithmetic Progression)](src/com/jwetherell/algorithms/Sequences/ArithmeticProgression.java)
301+
+ using a loop
302+
+ using Triangular numbers
303+
* [Largest sum of contiguous subarray (Kadane's algorithm)](src/com/jwetherell/algorithms/Sequences/LargestSumContiguousSubarray.java)
304+
* [Longest palin­dromic sub­se­quence (dynamic programming)](src/com/jwetherell/algorithms/Sequences/LongestPalin­dromicSub­se­quence.java)
305+
306+
## Sorts
307+
* [American Flag Sort](src/com/jwetherell/algorithms/Sorts/AmericanFlagSort.java)
308+
* [Bubble Sort](src/com/jwetherell/algorithms/Sorts/BubbleSort.java)
309+
* [Counting Sort (Integers only)](src/com/jwetherell/algorithms/Sorts/CountingSort.java)
310+
* [Heap Sort](src/com/jwetherell/algorithms/Sorts/HeapSort.java)
311+
* [Insertion Sort](src/com/jwetherell/algorithms/Sorts/InsertionSort.java)
312+
* [Merge Sort](src/com/jwetherell/algorithms/Sorts/AMergeSort.java)
313+
* [Quick Sort](src/com/jwetherell/algorithms/Sorts/QuickSort.java)
314+
* [Radix Sort (Integers only)](src/com/jwetherell/algorithms/Sorts/RadixSort.java)
315+
* [Shell's Sort](src/com/jwetherell/algorithms/Sorts/ShellSort.java)
316+
317+
## String Functions
318+
### [String Functions](src/com/jwetherell/algorithms/strings/StringFunctions.java)
319+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
169320
* Reverse characters in a string
170321
+ using additional storage (a String or StringBuilder)
171322
+ using in-place swaps
@@ -180,8 +331,13 @@ This is a collection of algorithms and data structures which I've implement over
180331
+ using in-place symetric element compares
181332
* Subsets of characters in a String
182333
* Edit (Levenshtein) Distance of two Strings
334+
<<<<<<< HEAD
183335
* KMP (Knuth–Morris–Pratt) Algorithm - Length of maximal prefix-suffix for each prefix
184336
* String rotations
337+
=======
338+
* [KMP (Knuth–Morris–Pratt) Algorithm - Length of maximal prefix-suffix for each prefix](src/com/jwetherell/algorithms/strings/KnuthMorrisPratt.java)
339+
* [String rotations](src/com/jwetherell/algorithms/strings/Rotation.java)
340+
>>>>>>> c0d476f8e48bd15f03ff6c83905785ddd922e873
185341
+ Findin lexicographically minimal string rotation
186342
+ Findin lexicographically maximal string rotation
187343

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.util.Stack;
2+
3+
//implemented Depth First Travesal in given "Directed graph" (Adjacany matrix)
4+
class DepthFirstTraversal {
5+
6+
public static int[] arr;
7+
public static int k = 0;
8+
9+
public static void depthFirstTraversal(int[][] a, int[] visited,int source){
10+
for (int i = 0; i < visited.length; i++) {
11+
visited[i] = -1;
12+
}
13+
Stack<Integer>stack = new Stack();
14+
int element = source;
15+
int i = source;
16+
int n = visited.length - 1;
17+
arr[k] = element;
18+
k++;
19+
visited[source] = 1;
20+
stack.push(source);
21+
22+
while (!stack.isEmpty()) {
23+
element = stack.peek();
24+
i = element;
25+
while (i <= n) {
26+
if (a[element][i] == 1 && visited[i] == -1) {
27+
stack.push(i);
28+
visited[i] = 1;
29+
element = i;
30+
i = 1;
31+
arr[k] = element;
32+
k++;
33+
continue;
34+
}
35+
i++;
36+
}
37+
stack.pop();
38+
}
39+
}
40+
}
41+

0 commit comments

Comments
 (0)