Skip to content

Commit 03b8339

Browse files
committed
network algorithms
1 parent 7c9d47e commit 03b8339

9 files changed

+179
-1
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
"# data-structures-in-java"
1+
ToDo's:
2+
*******
3+
- Appendix will be crated in this Readme file
4+
- DS_011 Package: BTree implementation will be completed
5+
- DS_011 Package: AVLTree implementation will be completed
6+
- DS_012 Package: Knight's Tour is going to be demonstrated
7+
- DS_013 Package: Graphs are going to be completed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
TERMINOLOGY
2+
***********
3+
Network / Graph A set of nodes connected by links
4+
Node / Vertex A spot in a network
5+
Link / Edge Connects nodes, can be either directed or indirected
6+
Path A sequence of nodes and links
7+
Cycle / Loop A path that returns to its starting point
8+
Reachable B is reachable from A if there is a path from A to B
9+
Connected Nodes A and B are connected if B is reachable from A and vice versa
10+
Undirected A graph is connected if every node is connected to every other node
11+
Strongly Connected If every node in a graph is reachable from every other node
12+
Weakly Connected A directed network becomes connected when you replace its links with undirected links
13+
Adjacent Nodes are connected by a link
14+
Neighbor An adjacent node
15+
16+
Example;
17+
18+
A ---- 75 ----> B
19+
20+
Node A and Node B are connected by a link so they are adjacent nodes.
21+
Node B is Node A's neighbor because there is a directed link from Node A
22+
to Node B however, Node A is not neighbor of Node B because there is not a
23+
backward directed link from Node B to Node A. If the graph was undirected,
24+
then both Nodes would be neighbors of each other.
25+
26+
Degree In an undirected network, he number of links a node has is called Degree.
27+
In-Degree In a directed network, the number of links entering a node is called In-Degree.
28+
Out-Degree Same as In-Degree but Out-Degree is the number of links leaving the node.
29+
30+
31+
NETWORK REPRESENTATION
32+
**********************
33+
You can save network in a text file in order to reuse it. Check out following directed graph;
34+
35+
A
36+
/ \
37+
/ \
38+
10 15
39+
/ \
40+
|/_ _\|
41+
42+
B --- 12 --> C
43+
\ /
44+
\ /
45+
16 13
46+
\ /
47+
_\|/_
48+
D
49+
50+
To save it to a text file, you can use following format;
51+
52+
nodeLabel, toNode#1, cost#1, toNode#2, cost#2,... toNode#N, cost#N
53+
54+
So, the text representation will be as follows;
55+
56+
A, B, 10, C, 15
57+
B, C, 12, D, 16
58+
C, D, 13
59+
D
60+
61+
Other Representations;
62+
**********************
63+
XML
64+
JSON
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ds_013_network_algorithms.sampleClasses;
2+
3+
public class DirectedLinkExampleClass {
4+
5+
private Integer cost;
6+
private DirectedNodeExampleClass toNode;
7+
8+
public DirectedLinkExampleClass(Integer cost) {
9+
this.cost = cost;
10+
}
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ds_013_network_algorithms.sampleClasses;
2+
3+
import java.util.LinkedList;
4+
import java.util.List;
5+
6+
public class DirectedNodeExampleClass {
7+
8+
private final String label;
9+
private List<DirectedLinkExampleClass> links;
10+
11+
public DirectedNodeExampleClass(String label) {
12+
this.label = label;
13+
this.links = new LinkedList<>();
14+
}
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ds_013_network_algorithms.sampleClasses;
2+
3+
public class EnhancedDirectedLinkExampleClass {
4+
5+
private Integer cost;
6+
private DirectedNodeExampleClass fromNode;
7+
private DirectedNodeExampleClass toNode;
8+
9+
public EnhancedDirectedLinkExampleClass(Integer cost) {
10+
this.cost = cost;
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ds_013_network_algorithms.sampleClasses;
2+
3+
import java.util.LinkedList;
4+
import java.util.List;
5+
6+
public class EnhancedDirectedNodeExampleClass {
7+
8+
private final String label;
9+
private List<EnhancedDirectedLinkExampleClass> inLinks;
10+
private List<EnhancedDirectedLinkExampleClass> outLinks;
11+
12+
public EnhancedDirectedNodeExampleClass(String label) {
13+
this.label = label;
14+
this.inLinks = new LinkedList<>();
15+
this.outLinks = new LinkedList<>();
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ds_013_network_algorithms.sampleClasses;
2+
3+
import java.util.LinkedList;
4+
import java.util.List;
5+
6+
public class SimpleNodeClassExample {
7+
8+
private final String label;
9+
private final List<SimpleNodeClassExample> neighbors;
10+
private final List<Integer> costs;
11+
private boolean visited;
12+
13+
public SimpleNodeClassExample(String label) {
14+
this.label = label;
15+
this.neighbors = new LinkedList<>();
16+
this.costs = new LinkedList<>();
17+
this.visited = false;
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ds_013_network_algorithms.sampleClasses;
2+
3+
public class UndirectedLinkExampleClass {
4+
5+
private Integer cost;
6+
private DirectedNodeExampleClass[] nodes;
7+
8+
public UndirectedLinkExampleClass(Integer cost) {
9+
this.cost = cost;
10+
this.nodes = new DirectedNodeExampleClass[2];
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ds_013_network_algorithms.sampleClasses;
2+
3+
import java.util.LinkedList;
4+
import java.util.List;
5+
6+
public class UndirectedNodeExampleClass {
7+
8+
private final String label;
9+
private List<UndirectedLinkExampleClass> links;
10+
11+
public UndirectedNodeExampleClass(String label) {
12+
this.label = label;
13+
this.links = new LinkedList<>();
14+
}
15+
16+
}

0 commit comments

Comments
 (0)