Key Concepts in Computer Science -Midterm 1
[Basic Mathematics]
1. [5 marks] Find the tightest integer upper bound and lower bound for x if π= ππ¨π π(ππ). Justify your answer.
ππ<ππ< ππ βΉ ππ< ππ< ππ βΉ ππ¨π π(ππ)< ππ¨π π(ππ)< ππ¨π π(ππ) βΉ
π< ππ¨π π(ππ)< 6 βΉ π<π < 6
2. [5 marks] Simplify these expressions using the rules for logarithms. Your answer will be a simpler formula. You do not need to calculate a numeric answer:
a. ππ¨π π(ππππ) = ππ¨π πππ β ππ¨π πππ
b. ππ¨π π(ππ)=πΓππ¨π π(π)
3. [5 marks] Solve this inequality 5 β₯ -10x + 20 and write it using interval notations for x.
5 β₯ -10x + 20 βΉ -15 β₯ -10x βΉ ππππ β€ x βΉ ππ β€ x βΉ 1.5 β€ x
x β (-β, 1.5)
4. [5 marks] Plot the two functions y=2x, y=2x + 2 on the same X-Y graph for {x | -2 β€ x β€ 2}.
[Pseudocode]
5. [10 marks] Write pseudocode for an algorithm to compute the sum of a list of integers but only for integers that are even.
Example: input: L = [4,2,1,3,6,8,7,9] output = 4 + 2 + 6 + 8 = 20
procedure sumOfEvenInt(L: list of integers)
n := sizeOf(L)
result := 0
for i := 1 to n
if L[i] is even then
result := result + L[i]
return result
Note: we are not picky about the syntax. Also, they might write the if line (to see whether L[i] is even or not) in different ways. As long as their intention is clear, they should get the mark.
[Propositional Logic]
6. [10 marks] Construct a truth table for the following compound proposition: Β¬p ο«ο Β¬q
7. [10 marks] Let p be the proposition βYou have a car”, q be the proposition βYou miss the game” and r be the proposition βYou play golf”. Express the following as an English sentence:
(p –> Β¬r) ο (q –> Β¬r)
Answer: If you have a car, then you donβt play golf or if you miss the game, then you donβt play golf.
[Propositional Equivalences]
8. [10 marks] Use truth table to verify the following: p ^ (p v q) ο p
Since the values of the last column are all TRUE, then the proposition is a tautology.
10. [10 marks] Give a proof that p οο ο¨Β¬p ο q) and p ο q are logically equivalent.
Note: you cannot use truth table.
p οο ο¨Β¬p ο q) β‘
(pοΒ¬p) ο (pοq) β‘ Distributive laws (DIS)
T ο (pοq) β‘ Negation laws (NEG)
p οο q Identity laws (ID)
12. [10 marks] Consider the following propositional functions:
ο· Sheep(x): x is a sheep
ο· Gorilla(x): x is a gorilla
ο· Fed(x): x is fed after sunset
ο· Moon(x): x is exposed to moonlight
ο· Dies(x): x dies
write the following statements in predicate logic using the above propositional functions, connectives, negation, and any needed quantifiers.
Leave a reply