Download Exercise 3 1 Breadth-first Search (4 Points)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Mathematical optimization wikipedia , lookup

Network science wikipedia , lookup

Types of artificial neural networks wikipedia , lookup

Corecursion wikipedia , lookup

Transcript
Exercise 3
Due date: May 15 2013
Prof. Steffen Staab, Dr. Jérôme Kunegis
Exercise 3
1
1
2
3
4
P
4
2
2
2
10
Breadth-first Search (4 Points)
Write a function that performs a breadth-first search in an undirected network G = (V, E) from a given
starting node s and returns a node vector d ∈ (N ∪ {∞})|V | with d(u) defined as the distance in the BFS
tree from the starting node to node u. The signature of the function must be:
function bfsVector = BFS(A, startingNode)
where startingNode is the ID of the first node in the node list and A is the adjacency matrix of a network.
For instance, using the following network1 (given in sparse format):
1,2
1,4
2,3
2,4
3,4
3,6
4,5
4,7
4,9
5,6
the function should work as follows:
bfsVector = BFS(A, 1);
% bfsVector is now [0,1,2,1,2,3,2,Inf,2]
where 0 indicates the starting node, 1 indicates that the node is at the first level of the BFS tree, 2 at the
second level of the BFS tree, and Inf indicates that the node is not connected to the starting node.
Instead of implementing an ordinary breadth-first search you should use only matrix and vector
operations. Consider the following vector:
v(0) = (0, . . . , 0, 1, 0, . . . , 0),
i.e., the vector v(0) defined by
(v
(0)
)u =
1
0
when u = s
when u =
6 s
Then, consider the vector v(1) defined by
v(1) = Av(0) .
1
Available online
sparse.txt/view
at
https://west.uni-koblenz.de/teaching/ss13/network-theory-and-dynamic-systems/bfs-network-
Page 1 of 3
Exercise 3
Due date: May 15 2013
Prof. Steffen Staab, Dr. Jérôme Kunegis
What is the meaning of the value (v(1) )u for a node u?
Finally, consider the recursively defined
v(k) = Av(k−1)
What does (v(k) )u represent for an integer k ≥ 0 and a node u?
What is the stopping criterion for this algorithm and why does it work?
2
Connectivity (2 Points)
Write a function that returns whether a given undirected network is connected.
A network is connected when all pairs of nodes in the network are connected by a continuous path of
edges.
The signature of the function must be
function connected = isConnected(A)
The function should return zero if the network is not connected and one if it is connected. Test your
function on the following two networks:
• http://konect.uni-koblenz.de/networks/loc-gowalla edges (Gowalla social network)
• http://konect.uni-koblenz.de/networks/loc-brightkite edges (Brightkite social network)
Which of these networks is connected?
3
Eccentricity (2 Points)
Write a function that returns the eccentricity of a given node.
The eccentricity of a node in a network is defined as the longest shortest pairwise distance from the node
to any other node in the network. The eccentricity is defined to be ∞ (infinity) if the network is not
connected.
The signature of the function must be:
function eccentricity = eccentricityOfNode(A, nodeId)
Test your function on the following network:
• http://konect.uni-koblenz.de/networks/ucidata-zachary (Zachary karate club social network)
4
Radius and Diameter (2 Points)
Write a function that returns the radius and diameter of an undirected network.
The radius and diameter of a network are defined respectively as the smallest and largest node eccentricity
in the network. The signature of the function must be:
Page 2 of 3
Exercise 3
Due date: May 15 2013
Prof. Steffen Staab, Dr. Jérôme Kunegis
function [radius, diameter] = radiusAndDiameter(A)
Hence, calling this function for the network of Exercise 1 should return
radius = Inf
diameter = Inf
Does this definition of radius and diameter make sense for real networks? In theory, how could it be
changed such that it makes sense as a network characteristic?
Apply your function to the Zachary karate club social network.
Tips
• ∞ (infinity) can be represented in GNU Octave using Inf.
• For Exercise 1: Can you give a non-recursive expression for v(k) ?
• For Exercise 1, it is important to understand matrix multiplication. For an integer k ≥ 0 and two
nodes u and v, what does the number (Ak )uv represent?
• For Exercise 4: Can you apply the function radiusAndDiameter to the Brightkite social network?
Page 3 of 3