In a nutshell
Like a careful banker who lends cash only if every customer could still be paid off in some order, the operating system hands out resources only when it can prove everyone could still finish. Each program declares the most it will ever need up front; a request is granted only if a 'safe sequence' to finish all programs still exists. That foresight prevents deadlock before it can happen, rather than cleaning it up afterward.