@gauravkc, check this- https://gateoverflow.in/3780/gate2005-it-34?show=101261#a101261, wiki link explains this very well.