AQA A Level · Computer Science 7517

Lists in functional programming:練習問題

その場で採点される選択問題 5 問と、解説つきの記述問題 5 問。すべて「Lists in functional programming」からの出題です。

10 問23 無料・登録不要
問 1
1

In functional programming, a list can be defined as a concatenation of two specific components. What are these two components called?
Example: in Haskell, the list \([4, 3, 5]\) can be written as \(4:[3, 5]\).

問 2
1

Given the list \(L = [10, 20, 30, 40]\), what would be the result of the operation prepend \(5\) to \(L\)?

問 3
1

Let \(L = [5, 12, 18, 21]\). Consider a recursive function f:
\(f([]) = 0\)
\(f(head:tail) = 1 + f(tail)\)

What is the result of applying \(f(L)\)?

問 4
1

If a list \(L\) is defined as \(7:[2, 9, 1]\), what is the result of the operation that returns the tail of the list?

問 5
1

In functional list processing, how is the list \([1, 2, 3, 4]\) represented using recursive construction with the empty list symbol \([]\)?

問 6
2

What is the resulting list when you prepend the item \( 5 \) to the list \( [12, 15] \)?

まず自分で答えを書いてから、解説と照らし合わせましょう。

問 7
3

A programmer uses a function to test for an empty list. If the input is \( head:tail \), what is the Boolean result of this test?

まず自分で答えを書いてから、解説と照らし合わせましょう。

問 8
5

A programmer is using Lists in functional programming. If a list is constructed as \( L = x:xs \), describe the result of the operation head(tail(tail([1, 2, 3, 4]))).

まず自分で答えを書いてから、解説と照らし合わせましょう。

問 9
3

A list in a functional language is often represented as a head and a tail.

(a) Define what is meant by the 'head' and 'tail' of a list.
(b) Given the list \( L = [10, 20, 30, 40] \), show how this list would be represented using the construction operator (often denoted as a colon \( : \) in Haskell) and the empty list symbol \( [] \).

まず自分で答えを書いてから、解説と照らし合わせましょう。

問 10
5

A programmer is writing a functional program to process a list of integers.

(a) Write a recursive definition for a function length(L) that returns the number of elements in a list \( L \). You should use the concepts of head, tail, and empty list.
(b) Trace your function with the list \( [7, 3] \), showing each recursive call.

まず自分で答えを書いてから、解説と照らし合わせましょう。

※ thinkaのコンテンツはAIにより生成されているため、内容が正確でない場合があります。補助教材としてご使用いただき、公式の教材と合わせてご確認ください。

模範解答は見ました。次はあなたの答案を採点します。

このページは良い答案の形を示せますが、あなたの答案に何が足りないかは教えられません。thinka は実際の採点基準に沿って記述答案を約 15 秒で採点します。

同じような問題をもっと解きたい?このトピックの新しい問題を、解きながら採点。

練習を始める