Lesson 4.12.3.1
4.12.3.1 List processing Quiz: AQA Computer Science, Unit 12
20 questions
In partnership with Revision Ninja
Lesson 4.12.3.1, List processing: 20 multiple choice questions for the AQA Computer Science (7517), Unit 12: Fundamentals of functional programming, written with Revision Ninja.
Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.
The 20 questions
-
In Haskell, what is the head of the list [4,3,5]?
- 3
- 5
- 4
- [3,5]
-
In Haskell, what is the tail of the list [4,3,5]?
- 5
- [4,3]
- [4]
- [3,5]
-
Which expression writes the list [4,3,5] in head and tail form?
- 4 : [3,5]
- [4] : [3,5]
- [4,3] : 5
- 5 : [4,3]
-
What is the empty list in Haskell?
- NULL
- [[]]
- []
- [0]
-
Which operation returns the number of elements in a list?
- tail, which returns the list without its first element.
- prepend, which adds an item to the front of the list.
- length, which counts the elements in the list.
- head, which returns the first element of the list.
-
Which operation adds an item to the front of a list?
- Append, which adds an item to the end of the list.
- Length, which counts the elements in the list.
- Prepend, using the cons operator, for example 7 : xs.
- Tail, which returns the list without its first item, and which also removes the item from the original list in the computer's memory.
-
Which operation adds an item to the end of a list?
- Empty test, which checks whether a list has no items.
- Append, for example xs ++ [7].
- Prepend, for example 7 : xs.
- Head, which returns the first item of the list.
-
What does the test for an empty list return when it is applied to []?
- The empty list []
- False
- True
- The number 0
-
What is the result of 1 : [2,3]?
- [1,2,3]
- [2,3,1]
- [3,2,1]
- [1,[2,3]]
-
What is the length of the list [5,6,7,8]?
- 8
- 3
- 5
- 4
-
What is the result of taking the head of the empty list?
- An error, because the empty list has no first element.
- [], because the head of an empty list is itself an empty list.
- NULL, because the head function returns a null value safely.
- 0, because the head of an empty list is always defined to be zero.
-
What is the tail of the single-element list [7]?
- []
- [7]
- undefined, because the list has only one item in it.
- 7
-
Which expression correctly prepends the number 9 to the list xs?
- xs : 9
- xs ++ 9
- 9 ++ xs
- 9 : xs
-
A function sumList is defined with sumList [] = 0 and sumList (x:xs) = x + sumList xs. What does sumList [1,2,3] return?
- 3
- 0
- 6
- 5
-
A function countList is defined with countList [] = 0 and countList (_:xs) = 1 + countList xs. What does countList [4,4,4] return?
- 4
- 0
- 3
- 12
-
What is the result of [1,2] ++ [3,4]?
- [4,3,2,1]
- [1,2,[3,4]]
- [3,4,1,2]
- [1,2,3,4]
-
Evaluate: why are prepends cheap but appends expensive when a list is stored as linked nodes?
- Both are equally expensive because each one copies the entire list every time it is used.
- Appending is cheap because it stores the new item at the start of memory, whereas prepending walks the list.
- Prepending is never possible in a functional language, because lists are fixed in length once created.
- Prepending creates one new head node, whereas appending must walk the whole list to reach its end.
-
Which description of a list as head and tail is correct?
- The head is an element of the list, and the tail is itself a list, which may be empty.
- The head is itself a list, and the tail is always a single element of the list.
- The head and the tail are both single elements, so the list has exactly two items.
- The head is always the last item in the list, and the tail holds the items before it, which is the reverse of the usual convention.
-
Which approach would be needed to return a list without its last element?
- The append operator applied to the list and [], which removes the last item of the list by joining the empty list onto the end of it.
- The length function applied to the list, which deletes the last item from the list.
- A recursive function that rebuilds the list one head at a time, stopping before the final element.
- The head function applied to the list, which removes the last item of the list.
-
Evaluate: why does reading the head of a list take one step, but reaching the end of a list of 1000 items takes 1000 steps?
- Reading the head is slow because the head is stored at the end of memory for the list.
- Reading the head uses the first node directly, whereas reaching the end needs each tail to be followed in turn.
- Reading the tail is quicker, because the tail is stored in a separate array of ten items.
- Both tasks need 1000 steps, because each item must be checked against every other item.
Related quizzes
- Function types and first-class objects Quiz · 4.12.1.1 · 20 questions
- Partial function application and composition of functions Quiz · 4.12.1.4 · 20 questions
- Writing functional programs Quiz · 4.12.2.1 · 20 questions
- Data types Quiz · 4.1.1.1 · 20 questions
- Entity relationship modelling Quiz · 4.10.1.1 · 20 questions
- Big Data Quiz · 4.11.1.1 · 20 questions
- Analysis Quiz · 4.13.1.1 · 20 questions
- Data structures and abstract data types Quiz · 4.2.1.1 · 20 questions
- Breadth-first and depth-first search Quiz · 4.3.1.1 · 20 questions
- Problem-solving and algorithms Quiz · 4.4.1.1 · 20 questions