-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweighted_graph.java
95 lines (94 loc) · 3.19 KB
/
weighted_graph.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package ex1.src;
import java.util.Collection;
/**
* This interface represents an undirectional weighted graph.
* It should support a large number of nodes (over 10^6, with average degree of 10).
* The implementation should be based on an efficient compact representation
* (should NOT be based on a n*n matrix).
*
*/
public interface weighted_graph {
/**
* return the node_data by the node_id,
* @param key - the node_id
* @return the node_data by the node_id, null if none.
*/
public node_info getNode(int key);
/**
* return true iff (if and only if) there is an edge between node1 and node2
* Note: this method should run in O(1) time.
* @param node1
* @param node2
* @return
*/
public boolean hasEdge(int node1, int node2);
/**
* return the weight if the edge (node1, node1). In case
* there is no such edge - should return -1
* Note: this method should run in O(1) time.
* @param node1
* @param node2
* @return
*/
public double getEdge(int node1, int node2);
/**
* add a new node to the graph with the given key.
* Note: this method should run in O(1) time.
* Note2: if there is already a node with such a key -> no action should be performed.
* @param key
*/
public void addNode(int key);
/**
* Connect an edge between node1 and node2, with an edge with weight >=0.
* Note: this method should run in O(1) time.
* Note2: if the edge node1-node2 already exists - the method simply updates the weight of the edge.
*/
public void connect(int node1, int node2, double w);
/**
* This method return a pointer (shallow copy) for a
* Collection representing all the nodes in the graph.
* Note: this method should run in O(1) tim
* @return Collection<node_data>
*/
public Collection<node_info> getV();
/**
*
* This method returns a Collection containing all the
* nodes connected to node_id
* Note: this method can run in O(k) time, k - being the degree of node_id.
* @return Collection<node_data>
*/
public Collection<node_info> getV(int node_id);
/**
* Delete the node (with the given ID) from the graph -
* and removes all edges which starts or ends at this node.
* This method should run in O(n), |V|=n, as all the edges should be removed.
* @return the data of the removed node (null if none).
* @param key
*/
public node_info removeNode(int key);
/**
* Delete the edge from the graph,
* Note: this method should run in O(1) time.
* @param node1
* @param node2
*/
public void removeEdge(int node1, int node2);
/** return the number of vertices (nodes) in the graph.
* Note: this method should run in O(1) time.
* @return
*/
public int nodeSize();
/**
* return the number of edges (undirectional graph).
* Note: this method should run in O(1) time.
* @return
*/
public int edgeSize();
/**
* return the Mode Count - for testing changes in the graph.
* Any change in the inner state of the graph should cause an increment in the ModeCount
* @return
*/
public int getMC();
}