0
0
VHDLprogramming~5 mins

Selected assignment (with-select) in VHDL - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Selected assignment (with-select)
O(n)
Understanding Time Complexity

We want to understand how the time needed to run a selected assignment using the with-select statement changes as the input size grows.

Specifically, how does the number of choices affect the time it takes to decide and assign a value?

Scenario Under Consideration

Analyze the time complexity of the following VHDL selected assignment.

with sel select
  result <= a when "00",
            b when "01",
            c when "10",
            d when others;
    

This code assigns one of four signals to result based on the value of sel.

Identify Repeating Operations

Look for repeated checks or operations that happen as the input changes.

  • Primary operation: Comparing sel against each choice to select the right value.
  • How many times: Once per choice, so 4 comparisons in this example.
How Execution Grows With Input

As the number of choices increases, the number of comparisons grows too.

Input Size (number of choices)Approx. Operations (comparisons)
44
1010
100100

Pattern observation: The number of comparisons grows directly with the number of choices.

Final Time Complexity

Time Complexity: O(n)

This means the time to select the correct assignment grows linearly with the number of choices.

Common Mistake

[X] Wrong: "The selected assignment picks the right value instantly, no matter how many choices there are."

[OK] Correct: Each choice must be checked until a match is found, so more choices mean more checks and more time.

Interview Connect

Understanding how selection statements scale helps you write efficient hardware descriptions and shows you think about performance in real designs.

Self-Check

"What if the selected assignment used a binary search tree structure internally? How would the time complexity change?"