@code_master01 : StackOverflowError happens when you use recursion and number of times your function is recursing is a little large . It is not necessarily related to space usage . The same code may work perfectly with same space usage if implemented in iterative fashion . I have also experienced StackOverflowError in past for recursive functions and an iterative implementation of same logic has been accepted . answered 13 Aug '13, 10:12

@vineetpaliwal what modifications do u suggest exactly? because i m doing a dfs using recursion, i wonder whether changing it to iterative version (which explicitly uses stack) would be helpful. answered 13 Aug '13, 12:17
You are right, just use stack and it will work. FYI, if you were using c++ you could stick with your recursive dfs, but java has it's limits.
(13 Aug '13, 13:08)
yes java supports lesser recursive calls.
(20 Aug '13, 00:32)
most recursive sol give tle
(20 Aug '13, 01:27)
