Use case diagrams in Software Engineering - Time & Space Complexity
When working with use case diagrams, it's helpful to understand how the effort to create or analyze them grows as the system gets bigger.
We want to know how the time needed changes when more actors or use cases are added.
Analyze the time complexity of the following process for creating a use case diagram.
// Pseudocode for creating a use case diagram
for each actor in systemActors:
identify use cases for actor
for each use case:
draw use case
connect actor to use case
end for
end for
This code shows how we add actors and their related use cases to the diagram step by step.
Look at the loops that repeat actions:
- Primary operation: Drawing and connecting each use case for every actor.
- How many times: For each actor, we repeat for all their use cases.
As the number of actors and use cases grows, the work grows too.
| Input Size (actors x use cases) | Approx. Operations |
|---|---|
| 10 actors x 5 use cases | 50 |
| 100 actors x 5 use cases | 500 |
| 100 actors x 50 use cases | 5,000 |
Pattern observation: The total steps increase roughly by multiplying the number of actors by the number of use cases.
Time Complexity: O(a * u)
This means the time needed grows in proportion to the number of actors times the number of use cases.
[X] Wrong: "Adding more actors doesn't affect the time much because use cases stay the same."
[OK] Correct: Each new actor usually has its own use cases or connections, so more actors mean more work overall.
Understanding how the size of a system affects the effort to model it helps you plan and communicate clearly in real projects.
"What if each actor shared the same set of use cases instead of having unique ones? How would the time complexity change?"