Key Concepts in Computer Science -Assignment 2
1. [6 marks] Plot the three functions y=x2, y=2×2, y=x2+2 on the same X-Y graph for {x | -3 ≤ x ≤ 3}.
2. [6 marks] Write pseudocode for an algorithm to compute the minimum value of a list of integers.
procedure minimumOfList(L: list of integers)
n := sizeOf(L)
min := L[1]
for i := 2 to n
if L[i] < min then
min := L[i]
return min
3. [9 marks] Write pseudocode for an algorithm to compute the product of a list of integers.
procedure productOfElements(L: list of integers)
n := sizeOf(L)
product := 1
for i := 1 to n
product:= product × L[i]
return product
4. [8 marks] Which of these are propositions?
a) Do not pass go. This is NOT a proposition.
b) There is no green bird in BC. This is a proposition.
c) 4 + z = 7 This is NOT a proposition.
d) Jupiter is made of water. This is a proposition.
5. [9 marks] Let p, q, and r be the following propositions:
p: You have the flu.
q: You miss the midterm exam.
r: You pass the course.
Using the above propositions, write these compound propositions in English sentences:
a) p → ¬r If you have the flu, then you don’t pass the course
b) ¬p ∧ q ∧ r You don’t have the flu and you miss the midterm exam and you pass the course.
c) ¬q ↔ r you don’t miss the midterm exam if and only if you pass the course.
6. [12 marks] Write the truth table for the following compound propositions:
a) (p ∨ q) ∧ ¬r
Leave a reply