Computer Science I / Functions
Practice question · Put in order

Order the steps of evaluating the composition h after g after f, applied to an input x.

Hints
  1. Composition is read right to left, so the rightmost function is the first to run.
  2. Each function consumes the output of the one before it.
Show the answer
  1. Apply f to x
  2. Apply g to the result
  3. Apply h to that result
  4. 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.

Read the lesson: Functions →

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