Detect a cycle in a tree with only one pointer

In one parse, count the number Normal nodes and NULL nodes. If there is no cycle then the
number of NULL nodes = No. Normal nodes + 1

If this is not followed, which means there is a cycle in the tree.

But since there is a cycle, you will never finish counting the number of nodes.

Leave a Reply

Your email address will not be published. Required fields are marked *