As Mayer suggests, we still need to know what model iMac G5 this is. But if it happens to be the earlier version without the embedded iSight camera, these machines often suffer from the "bulging capacitor" issue, whereby capacitors attached to the logic board basically explode and ooze fluid, causing a myriad of various issues and symptoms. If it is the non-iSight version (I haven't dealt with enough of the iSight version to know if the have the same issue), you should loosen the three screws on the underside, pop the back casing off, and examine the board for bulging capacitors. Capacitors, if you aren't aware, look like smallish, cylindrical batteries, and there are a few clusters of them pointing vertically up from the board. The tops of all the capacitors should be perfectly flat, so if you see any that are peaking upward (like a volcano) or especially oozing a sticky substance, then your machine is suffering from this issue. Unfortunately if that is the problem, your machine is basically toast. You can replace all the capacitors if you're up for a significant project. I've never done it myself, but you can watch videos on YouTube detailing what's involved.
That aside, it could be your hard drive. I'd connect the machine to another via Firewire, put it in target mode, save your data onto the remote machine, and then wipe the drive and reinstall the OS, and see if symptoms persist. If they do, you know it's a hardware issue. I would then put the remote computer in target mode, and boot your iMac from the other computer's hard drive. If that works and you see no symptoms, you know your iMac's hard drive is at fault. Daniel brings up some good points, but honestly, I don't think I've ever seen Disk Utility save a drive that was so far gone as to be freezing constantly.