Deadlock prevention breaks at least one necessary condition. Resource ordering prevents circular wait. Atomic acquisition of all resources prevents hold-and-wait. Avoidance algorithms (Banker's algorithm) allocate only if the system remains safe. Prevention is simpler but reduces concurrency; avoidance is complex but allows more parallelism.
From deadlock conditions and resource-allocation graphs, you know the four conditions that must all hold simultaneously for deadlock: mutual exclusion, hold-and-wait, no preemption, and circular wait. Deadlock prevention takes a structural approach: design the system so that at least one of these four conditions can never be satisfied. If any single condition is impossible, deadlock cannot occur — regardless of how processes behave at runtime.
The most practical prevention technique targets circular wait through resource ordering. Assign every resource type a global number (e.g., mutex A = 1, mutex B = 2, database lock = 3). Require that every process requests resources in strictly increasing order. A process holding resource 2 may request resource 3 but may never request resource 1. This makes cycles impossible: if process P holds resource i and waits for resource j, then j > i, meaning no chain of waiting can loop back to a lower-numbered resource. This technique is widely used in real systems — the Linux kernel, for example, enforces lock ordering conventions and has tooling (lockdep) to detect violations. The downside is that it constrains the order of operations, which can force awkward code restructuring.
Preventing hold-and-wait requires a process to request all resources it will ever need at once, before it begins executing. If all resources are available, they are granted atomically; if any is unavailable, the process waits without holding anything. This eliminates the possibility of holding one resource while waiting for another. The problem is obvious: processes often cannot predict their full resource needs in advance, and requesting everything upfront leads to poor utilization — resources sit locked and idle while the process works on unrelated tasks.
Deadlock avoidance takes a fundamentally different approach. Instead of eliminating conditions structurally, it allows processes to request resources in any order but checks each request against a safety algorithm before granting it. The classic example is the Banker's algorithm: the OS maintains a matrix of maximum resource demands declared by each process and, before granting any request, simulates whether there exists at least one sequence in which all processes can finish. If granting the request would leave the system in an unsafe state — one where no such completion sequence exists — the request is denied and the process must wait. Avoidance permits more concurrency than prevention because it only restricts allocations that would actually lead to danger, but it requires advance knowledge of maximum resource needs and runs the safety check on every allocation, making it computationally expensive for systems with many processes and resource types.