Skip to content

Precedence Graph

Introduction to concurrent programming

During the analysis and design of a concurrent program, constructing a precedence graph is useful for making the dependencies between operations explicit. It helps determine which activities can be performed in parallel and which must wait, so that the necessary synchronizations can be designed, premature access to data that is not yet available can be avoided, and parallelism can be used without compromising the program’s correctness.

In everyday activities, some actions must be performed sequentially.

For example, to mail a letter, it must first be written and placed in an envelope, then stamped, and finally handed over for delivery.

flowchart LR A["Write and envelope"] --> B["Stamp"] --> C["Hand over for delivery"]

Diagram created with Mermaid

Other actions can proceed in parallel because they do not depend on one another: while the oven heats up, the ingredients can be prepared; alternatively, while one person sets the table, another can prepare drinks. If a subsequent activity requires the result of both, it can begin only when both have finished.

flowchart LR A["Heat the oven"] --> C["Put in the oven"] B["Prepare the ingredients"] --> C D["Set the table"] E["Prepare drinks"]

Diagram created with Mermaid

A precedence graph represents the dependencies between a program’s operations. Each node represents an operation; a directed arrow from one node to another indicates that the first operation must finish before the second can begin.

flowchart LR A["A = 25"] --> B["B = A + 3"]

Diagram created with Mermaid

In this example, node A precedes B: the value of A must be available to calculate B. The arrow’s direction therefore indicates the required order, not necessarily the order in which the operations are executed one after another in the program.

When two operations do not depend on each other, they can be executed in parallel. If both are required by a subsequent operation, that operation can begin only after both have completed:

flowchart LR A["A"] --> B["B"] A --> C["C"] B --> D["D"] C --> D

Diagram created with Mermaid

After A, operations B and C are independent of each other; D, however, waits for both B and C. The graph shows which operations can proceed at the same time and which precedence constraints must be respected.

Consider a set of operations in which the results obtained are reused to calculate new variables.

Observe the graph: each arc indicates that the value produced by the preceding operation must be available before the next operation can be performed.

flowchart TD A["A = 25"] --> B["B = A + 3"] A --> C["C = A + 5"] A --> J["J = A + 17"] B --> D["D = B + C"] C --> D C --> F["F = 12 + C"] D --> E["E = F + D + J"] F --> E J --> E J --> G["G = 15 + J"] F --> H["H = F + E + G"] E --> H G --> H H --> I["I = 8 + H"]

Diagram created with Mermaid

Answers to the quizzes on this page are saved in your browser's local storage and remain stored between visits

In this lesson, what does concurrent programming describe?

  • The mandatory execution of every instruction one at a time.
  • The execution of multiple operations that can advance simultaneously while respecting dependencies.

    Correct: independent operations can proceed in parallel, while dependencies impose waits.

  • Repeating the same operation until the program ends.

What does a node represent in a precedence graph?

  • An arrow between two operations.
  • An operation to execute.

    Correct: each node identifies a single operation in the program.

  • A shared resource used by every process.

In the graph A → B, what does the arrow indicate?

  • A can begin only after B completes.
  • B can begin only after A completes.

    Correct: the arrow’s direction represents the precedence constraint.

  • A and B must necessarily be executed one after the other on the same processor.

Consider the graph A → B, A → C, B → D, and C → D. When can D begin?

  • Immediately after A completes.
  • After only one of B or C completes.
  • After both B and C complete.

    Correct: D depends on both operations.

In the graph example, why must F wait for C?

  • Because calculating F uses the value contained in C.

    Correct: F can be calculated only after C has produced its result.

  • Because F and C are identical operations.
  • Because F is the last operation in the program.

In the graph A → B, A → C, B → D, and C → D, which statements are correct? Select all correct answers.

  • B and C can be executed in parallel.

    Correct: both depend on A, but not on each other.

  • D can begin only after both B and C complete.

    Correct: D depends on both operations.

  • B can begin before A has finished.
  • D can begin after B completes, even if C has not finished.

In a precedence graph, an arrow from A to B indicates that B can begin only after [[A]] has completed.

Quiz progress

0 / 0 answers answered (0%)

0 correct answers