Quiz 3 Flashcards

1
Q

(define L ‘(5 (3 9 2) (6 4) 1))
(caadr L)
What is the output of the code above?

(6 4), 6, 3, or (9 2)?

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Tail recursion allows recursive functions to be executed more efficiently by storing intermediate results. So, no runtime stack is necessary to remember arguments of previous calls in tail recursion, T/F?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

(define L ‘(5 (3 9 2) (6 4) 1))
(cadr L)
What is the output of the code above?

1, 5, (6 4), or (3 9 2)?

A

(3 9 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which of the following is the correct Scheme expression to calculate the greatest common divisor of 10 and 15 with a given gcd function?
(gcd 10 15), gcd(10, 15), gcd,10,15, or gcd ( 10 15)?

A

(gcd 10 15)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

(define L ‘(5 (3 9 2) (6 4) 1))
(cadddr L)
What is the output of the code above?

4, 2, 6, or 1?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

(define L ‘(5 (3 9 2) (6 4) 1))
(caddr L)
What is the output of the code above?

3, 6, (9 2), or (6 4)?

A

(6 4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

(define L ‘(5 (3 9 2) (6 4) 1))
(car L)
What is the output of the code above?

(3 9 2), (6 4), 5, or 1?

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When you define variables in a let expression in Scheme, values of the variables can be accessed only within the let form, not outside it, T/F?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which function adds a new head to an existing list?

cons, null?, car, or cdr?

A

cons

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following is the correct Scheme expression to calculate (3 + 5) * 2

(* (+ 3 5) 2), (+ * (3 5) 2), (3 + 5 * 2), or (+ (3 5) * 2)?

A

(* (+ 3 5) 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly