Bugs
Your isRing()
function doesn't check that the whole graph is a single ring. If you had a graph with two disconnected rings, it would still return true.
Your isStar()
function doesn't check that the limbs are connected to the center, only that they have one outgoing edge. If you construct a graph where the center connects outwards to all other vertices, but the other vertices connect to each other in a one-way ring, it would pass your test (although this graph would be have asymmetrical one-way edges).
For both cases, you probably need to check this.matrix[row][row] != false
like you do with the third case. Otherwise your falseCount
will be off by one.
- 28.8k
- 3
- 41
- 83