Practice question · Put in order
Order the steps of evaluating the composition h after g after f, applied to an input x.
- Apply f to x
- Apply h to that result
- Apply g to the result
- Read off the final value
Hints
- Composition is read right to left, so the rightmost function is the first to run.
- Each function consumes the output of the one before it.
Show the answer
- Apply f to x
- Apply g to the result
- Apply h to that result
- Read off the final value
Why
The innermost function runs first and each result feeds the next, so the evaluation runs right to left through the written expression. This is exactly how a program built from a chain of transformations executes, which is why composition is the central idea behind pipelines of functions in computing.
Practise Functions
The app has 4 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Functions
- A hash function maps a large key space into a small one, so collisions are guaranteed. Which mathematical…
- Each option lists a set of ordered pairs from {1, 2, 3} to {a, b}. Select every one that is a function on the…
- A function has an inverse exactly when it is bijective. Why do both injectivity and surjectivity turn out to…
- Sort each description by the property of a function it is describing.