the PC shuts down automatically after 30 - 40 minutes and then it restarts only after 20-30 minutes
-what do you mean by it restarts only after 20-30 minutes? Do you mean to say that you press the power button for 20-30 mins but nothing happens?
Likely components that may be causing this is faulty mobo and SMPS (PSU)
Some short of mobo with cabinet metal contact somewhere near screw might even cause this
Also using a suitable app monitor the CPU temperature and let us know if it's in limits
Does it happen randomly or when you are using some CPU intensive tasks like too many apps open, playing some games, ripping DVDs etc or does it happen even during very general purpose computing like just a browser window and may be some office file is open?
One somewhat complex task is to remove cabinet and run a bare PC with just SMPS, Mobo CPU, just one RAM stick and keyboard/mouse and observe the behavior if it repeats, also examine if the behavior repeats when you run a live linux os off USB
If you can get a SMPS from friend or from a local computer shop if you know someone there, try replacing that first and check.
Try connecting the system to another Mains point if possible.
When you press power button, does the system show a momentary life like fan spins for fraction of a sec and shut off?
Try paperclip test on SMPS (Google for more) and check if it runs. If you have a multimeter, measure the voltages. Don't keep it running like that for a long though.
When its basic PC just short the front panel pins where Power Switch connects to mobo to start it. Short it for extended period of 3 - 4 seconds and see if it makes any difference