Cycle detection using DFS in a graph
Checking expression using stack