I came across a problem concerning graphs. Let's define a rake graph.
A n-vertex graph is a rake when it meets certain conditions:
- there is a vertex of degree 1 in the graph
- this vertex is connected to a vertex of degree 2
- this second vertex is connected to another vertex of degree n-2 other vertices may or may not be connected to each other.
I have been given an adjacency matrix for a graph of n vertices. My task is to check if the graph represented by the given matrix is a "rake" or not. The catch is that is has to be done in linear time.
I've tried like everything. It's easy to do when you have adjacency list, but how do I make it take O(n) time with the matrix given?
O(n)
for the worst-case? (btw. it is really nice problem;-) thanks for that! ) – artur grzesiak