• No results found

FP 2005-2006, Tussentoets

N/A
N/A
Protected

Academic year: 2021

Share "FP 2005-2006, Tussentoets"

Copied!
4
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

FP 2005-2006, Tussentoets

March 10, 2006, 13.00-15.00

The exam consists of 6 multiple choice questions (1 point each) and two open questions (2 points each). A wrong multiple choice answer will give a negative result (−0.25 point), whereas omitting the answer results in 0 points. Therefore, guessing is not recommended.

Hand in the second page, with choices made and open questions answered. Put the right answer to the multiple choice questions in the corresponding box.

1. Which expressions are equivalent, i.e., can replace each other in any context?

(a) takeWhile p.dropWhile p and dropWhile p (b) takeWhile p.dropWhile p and id

(c) takeWhile p.dropWhile q and dropWhile q.takeWhile p (d) takeWhile p.takeWhile q and takeWhile (λx → p x ∧ q x ) 2. What is the result of foldr ((∗).(∗2)) 2 [2, 2, 2]?

(a) 16 (b) 32 (c) 64 (d) 128

3. What is the type of foldr map?

(a) [a ] → [a → a ] → [a ] (b) [a ] → [[a → a ]] → [a ]

(c) [a ] → [[a → a ] → [a ]]

(d) [[a ]] → [a → a ] → [a ]

4. Which of the following holds for the search trees (from Chapter 5)?

(a) Elements can only occur once (b) You cannot search in an empty tree

(c) You cannot delete an element that is not in the tree.

(d) The time to find an element depends on the way the tree was constructed.

1

Dit tentamen is in elektronische vorm beschikbaar gemaakt door de TBC van A–Eskwadraat.

A–Eskwadraat kan niet aansprakelijk worden gesteld voor de gevolgen van eventuele fouten in dit tentamen.

1

(2)

5. Someone who want to program list comprehension free, translates the right-hand side of the following definition into comprehension-free code. Which of the alternatives is the correct one?

segs xs = [ ] : [t | i ← inits xs, t ← tails i , not (null t )]

(a) [ ] : concat (map f (inits xs))

where f i = concat (map g (tails i ))

where g t = if not (null t ) then [ ] else [t ] (b) [ ] : concat (map f (inits xs))

where f i = concat (map g (tails i ))

where g t = if not (null t ) then [t ] else [ ] (c) [ ] : concat (map f .map g) (inits xs)

where f i = tails i

g t = if null t then [ ] else [t ]

(d) [ ] : filter (not.null ).concat (map f .map g) (inits xs) where f i = tails i

g t = [t ]

6. The function intersperse ::a → [a ] → [a ] puts its first argument between all the elements of a non-empty list. Thus intersperse ’a’ "xyz" results in "xayaz". Which definition is correct?

(a) intersperse a as = foldr (λe r → (e : a : r )) [ ] as (b) intersperse a as = tail .concat .map (λx → [a, x ]) $ as

(c) intersperse a as = foldl (λr e → (a : e : r )) [ ] as (d) intersperse a as = tail [(a : e) | e ← as ]

7. Given the type

data Tree = Node Tree Int Tree

| Leaf

Write a function sortedPathsOnly that efficiently produces all paths from the root to the leafs that are increasing

8. Give the type and the definition of the function foldl . Use the function foldl to define a function list2Int :: [Int ] → Int which maps a sequence of digits (represented as integers i , with 0 6 i < 10) to the Int value represented by these digits. Use the function in a program readAndPrintTheSquare that reads a line from the terminal which contains characters representing digits, and prints the square of the value represented by these digits. You may use the functions char2Digit :: Char → Int , show :: Int → String and the standard IO -functions from the Helium prelude.

2 2

(3)

Name:

Student nr:

Bachelor program: Inf/CKI/...

Answers to the mutiple choice questions:

1 2 3 4 5 6

QUESTION 7, the function sortedPathsOnly:

(see other side/ zie andere zijde)

3 2

(4)

QUESTION 8, the functions foldl , list2Int and readAndPrintAnInt and their types:

4 2

Referenties

GERELATEERDE DOCUMENTEN

Applying the good algorithm to the set of 83 digits that satisfy the coat of width 2 and taking the parameter λ = 1 in the distance function, yields thousands of solutions that

De present value van het restinkomen wordt zoals de meeste present value berekeningen tenslotte bepaald door de restwaarde (terminal value) welke op een andere wijze wordt

In the first scenario, HRM is on board and is of high value regarding the CEO, but the HRM expertise is low. Therefore, it is expected that HRM is not a valuable partner in the

Hereby, the following research question was formulated: “How can the supplier define customer solutions based on a customer value-in-use perspective and what are the consequences

We first analyze the creation and development of the different networks related to the Bosch 500 program, the ways in which the city learned to use its networks, and various

- current situation of the collection, analyses and interpretation of fingermarks in the Netherlands - the needs and opportunities in fingermark practice - the possibilities for

\linegoal \linegoal first expands to the current value (\linewidth or the line goal stored in the .aux file as a zref property). Thereafter, \LNGL@setlinegoal is expanded in order

Problem A) Consider the real valued function f (x) = x−2 2x and let A ⊆ R be the largest subset of the real numbers on which the function is well-defined. (1) Find the