comp9020 - lecture 17: course review

55
COMP9020 Foundations of Computer Science Lecture 17: Course Review

Upload: others

Post on 11-May-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COMP9020 - Lecture 17: Course Review

COMP9020Foundations of Computer Science

Lecture 17: Course Review

Page 2: COMP9020 - Lecture 17: Course Review

Course ReviewGoal: for you to become a competent computer scientist.

Requires an understanding of fundamental concepts:

Structures

RecursionProbability

Logic

2

Page 3: COMP9020 - Lecture 17: Course Review

Course ReviewGoal: for you to become a competent computer scientist.

Requires an understanding of fundamental concepts:

Structures

RecursionProbability

Logic

Topic 0: Number Theory

2

Page 4: COMP9020 - Lecture 17: Course Review

Course ReviewGoal: for you to become a competent computer scientist.

Requires an understanding of fundamental concepts:

Structures

RecursionProbability

Logic

Topic 1: Structures

Sets

Relations

Functions

Graph Theory

2

Page 5: COMP9020 - Lecture 17: Course Review

Course ReviewGoal: for you to become a competent computer scientist.

Requires an understanding of fundamental concepts:

Structures

RecursionProbability

Logic

Topic 2: Recursion

Recursion

Induction

AlgorithmicAnalysis

2

Page 6: COMP9020 - Lecture 17: Course Review

Course ReviewGoal: for you to become a competent computer scientist.

Requires an understanding of fundamental concepts:

Structures

RecursionProbability

Logic

Topic 3: Logic

Boolean Logic

Propositional Logic

2

Page 7: COMP9020 - Lecture 17: Course Review

Course ReviewGoal: for you to become a competent computer scientist.

Requires an understanding of fundamental concepts:

Structures

RecursionProbability

Logic

Topic 4: Probability

Combinatorics

Probability

Statistics

2

Page 8: COMP9020 - Lecture 17: Course Review

Course ReviewGoal: for you to become a competent computer scientist.

Requires an understanding of fundamental concepts:

Structures

RecursionProbability

Logic

In CS/CE these are used to:

formalise problemspecifications andrequirements

develop abstract solutions(algorithms)

analyse and proveproperties of yourprograms

2

Page 9: COMP9020 - Lecture 17: Course Review

Outline

Assessment Summary

Examination Philosophy

Content Review

Selection of Sample Questions

3

Page 10: COMP9020 - Lecture 17: Course Review

Assessment Summary

Quizzes: Best 6 out of 10 – (10 marks)Assignments: 3 assignments worth 13.33 marks each – (40 marks)Final exam – (50 marks)

NB

You must achieve 40% on the final exam AND 50% overall to passthe course.

4

Page 11: COMP9020 - Lecture 17: Course Review

Final Exam

Goal: to check whether you are a competent computer scientist.

Requires you to demonstrate:

understanding of mathematical concepts

ability to apply these concepts and explain how they work

Lectures, quizzes and assignments have built you up to this point.

5

Page 12: COMP9020 - Lecture 17: Course Review

Final Exam

Available: Tuesday, 30th November, 13:45 (AEDST)Due: Tuesday, 30th November, 17:00 (AEDST)

Access: Inspera through Moodle

15 Questions, 1-3 parts per question (22 parts in total)

Parts are mostly long-answer questions (e.g.proofs/counterexamples)

Questions equally weighted (parts not necessarily): 12 marksper question = 180 marks in total

Covers all of the contents of this course up to and includingWeek 10.

I will be available (email/forum/zoom) to answer anyquestions, but first point of contact should be exams team

6

Page 13: COMP9020 - Lecture 17: Course Review

MaterialsThe questions are intended to assess your understanding and yourability rather than your knowledge.

Access to passive sources (i.e. existing material) is permitted –should be properly referenced.

Accessing active sources (e.g. collaborating with other students,actively seeking answers through forums/social media, contractcheating, etc) is a breach of the University’s Plagiarism Policy andwill be subject to disciplinary action as outlined in the Studentcode of conduct

Can use the unicode/LATEXeditor on course website;Strongly recommended to have external writing materials for roughworking

NB

Questions are culturally neutral – no concepts other than thosetaught in this course are assumed.

7

Page 14: COMP9020 - Lecture 17: Course Review

Special consideration

Review the UNSW policy on Special Consideration.

UNSW has a “fit-to-sit” policy: by undertaking the assessment youare declaring that you are fit to do so.

If there are any foreseeable issues you must apply before the exam.If circumstances prevent you from applying before the exam, youmust apply as soon as possible (within 3 days).

NB

Supplementary exams are only available to students grantedSpecial Consideration.

8

Page 15: COMP9020 - Lecture 17: Course Review

Technical issues

If you experience technical issues before or during the exam, youshould follow these instructions:

Take screenshots (including time and date) of as many of thefollowing as possible:

error messagesscreen not loadingtimestamped speed testspower outage mapsmessages or information from your internet provider regardingthe issues experienced

Make contact with me immediately (through email, ed, orzoom) and advise me of the issue.

Submit a Special Consideration application immediately at theconclusion of your assessment and upload your screenshots.

9

Page 16: COMP9020 - Lecture 17: Course Review

Revision Strategy

Re-read lecture slides

Read the corresponding chapters in the book (R & W)

Review/solve assignments and quizzes

Review/solve problem sets

Solve more problems from the books

Attempt sample exam

(Applying mathematical concepts to solve problems is a skill thatimproves with practice)

10

Page 17: COMP9020 - Lecture 17: Course Review

Outline

Assessment Summary

Examination Philosophy

Content Review

Selection of Sample Questions

11

Page 18: COMP9020 - Lecture 17: Course Review

Examiner’s comments

The questions are intended to assess your understanding and yourability rather than your knowledge.

Unless specified, any valid proof technique is acceptable.

Partial marks are always available for incomplete answers.

12

Page 19: COMP9020 - Lecture 17: Course Review

How hard is it?

A common question is how will the exam compare toassignment/quiz/practice questions?

The exam situation is significantly different to assignments.

You have less time for the exam, so on the face of it questionsmay appear harder (even if this is not the case).

I am aware of the reduced timeframe, so exam marking willlikely be more forgiving than assignment marking.

Assignments had a wide range of difficulty.

Answer

Assignment questions (and practice questions) are indicative of thequestions likely to appear on the exam.

13

Page 20: COMP9020 - Lecture 17: Course Review

Assessment

Assessment is about determining how well you understand thesyllabus of this course.

If you can’t demonstrate your understanding, you don’t pass.

In particular, I can’t pass people just because ...

please, please, ... my family/friends will be ashamed of me

please, please, ... I tried really hard in this course

please, please, ... I’ll be excluded if I fail COMP9020

please, please, ... this is my final course to graduate

etc. etc. etc.

(Failure is a fact of life. For example, my scientific papers or project

proposals get rejected sometimes too)

14

Page 21: COMP9020 - Lecture 17: Course Review

Assessment (cont’d)

Of course, assessment isn’t a “one-way street” ...

I get to assess you in the final exam

you get to assess me in UNSW’s MyExperience Evaluation

go to https://myexperience.unsw.edu.au/

login using [email protected] and your zPass

Please fill it out ...

give me some feedback on how you might like the course torun in the future

even if that is “Exactly the same. It was perfect this time.”

15

Page 22: COMP9020 - Lecture 17: Course Review

Outline

Assessment Summary

Examination Philosophy

Content Review

Selection of Sample Questions

16

Page 23: COMP9020 - Lecture 17: Course Review

Week 1 Recap

Proof strategies

Number theory

Floor b·c and ceiling d·e functionsAbsolute value | · | functionDivides relation ·|·Greatest common divisor, least common multiplediv, %, =(n)

17

Page 24: COMP9020 - Lecture 17: Course Review

Need to know for this course

How to present proofs

Number theory definitions and notation. Especially:

Divides relationgcd, lcma =(n) b

18

Page 25: COMP9020 - Lecture 17: Course Review

Week 2 Recap

Sets:

Set notation: ∈, ∅, U , ⊆, . . ., [. . .], (. . .)

Set operations: ∩, ∪, c , \, ⊕, Pow(), ×

Defining sets:

Explicitly listing elementsSubsets of a given setConstructed using set operations

Cardinality: |X | = #(X ) = card(X )

Venn diagrams

Laws of set operations

Formal languages:

Symbols, words, languages

Language definitions: Σ∗, length(), concatenation, Kleene star

19

Page 26: COMP9020 - Lecture 17: Course Review

Laws of Set Operations

For all sets A, B, C :Commutativity A ∪ B = B ∪ A

A ∩ B = B ∩ AAssociativity (A ∪ B) ∪ C = A ∪ (B ∪ C )

(A ∩ B) ∩ C = A ∩ (B ∩ C )Distribution A ∪ (B ∩ C ) = (A ∪ B) ∩ (A ∪ C )

A ∩ (B ∪ C ) = (A ∩ B) ∪ (A ∩ C )Identity A ∪ ∅ = A

A ∩ U = AComplementation A ∪ (Ac) = U

A ∩ (Ac) = ∅

20

Page 27: COMP9020 - Lecture 17: Course Review

Other useful set laws

Idempotence A ∩ A = AA ∪ A = A

Double complementation (Ac)c = AAnnihilation A ∩ ∅ = ∅

A ∪ U = Ude Morgan’s Laws (A ∩ B)c = Ac ∪ Bc

(A ∪ B)c = Ac ∩ Bc

Theorem (Principle of Duality)

If you can prove A1 = A2 using the Laws of Set Operations thenyou can prove dual(A1) = dual(A2)

Theorem (Uniqueness of complement)

A ∩ B = ∅ and A ∪ B = U if, and only if, B = Ac .

21

Page 28: COMP9020 - Lecture 17: Course Review

Need to know for this course

How to define sets

Cartesian product

Cardinality computations

Proofs using Laws of Set Operations

How to define languages

22

Page 29: COMP9020 - Lecture 17: Course Review

Week 3 Recap

Relations:

Definitions, n-ary relations

Binary Relations:

Representations: Matrix, graphical, directed graph

Relational image (R(A)), converse relation (R←), inverseimage (R←(B)), relation composition (R;S)

Properties: Fun, Tot, Inj, Sur

Properties: Reflexivity, Antireflexivity, Symmetry,Antisymmetry, Transitivity

Functions: Domain, codomain, image

23

Page 30: COMP9020 - Lecture 17: Course Review

Week 3 Recap

Equivalence Relations:

Generalize equality

Reflexive, Symmetric, Transitive

Equivalence classes, Partitions

Partial Orders:

Generalize ≤Reflexive, Antisymmetric, Transitive

Hasse diagram, minimum vs minimal, glb/lub, lattice

24

Page 31: COMP9020 - Lecture 17: Course Review

Need to know for this course

Relational image, relational composition

Properties of binary relations – examples and non-examples

Equivalence classes

Hasse diagram, glb/lub

25

Page 32: COMP9020 - Lecture 17: Course Review

Week 4 Recap

Partial Orders:

Generalize ≤Reflexive, Antisymmetric, Transitive

Hasse diagram

Minimum/maximum vs minimal/maximal

glb/lub

lattice, complete lattice

total order, topological sort

product/lexicographic/lenlex order

Functions:

Domain, Codomain, Image

Surjective, Injective, Bijective

26

Page 33: COMP9020 - Lecture 17: Course Review

Need to know for this course

Hasse diagram, glb/lub

lattice

topological sort

lexicographic/lenlex order

27

Page 34: COMP9020 - Lecture 17: Course Review

Week 5 Recap

Functions:

Matrices: Add, Scalar multiplication, Matrix multiplication,Transpose

big-O notation: O, Ω, Θ

Graphs:

Formulating problems as graph problems

28

Page 35: COMP9020 - Lecture 17: Course Review

Need to know for this course

Basic matrix definitions and operations

How to compare a variety of functions using big-O

How to present problems as graph problems

29

Page 36: COMP9020 - Lecture 17: Course Review

Week 6 Recap

Graph Theory

Definitions and notation: vertices, edges, paths, cycles,connectedness, isomorphisms

Important graphs: Trees, Complete graphs, complete k-partitegraphs

Graph traversals: DFS/BFS, Eulerian path/circuit,Hamiltonian path/cycle

Graph properties: Chromatic number, Clique number,Planarity

30

Page 37: COMP9020 - Lecture 17: Course Review

Need to know for this course

Graph definitions and important graph classes

How to show/calculate graph properties:

ConnectednessEulerian/Hamiltonian traversalsChromatic numberClique numberPlanarity

Interactions between graph properties

31

Page 38: COMP9020 - Lecture 17: Course Review

Week 7 Recap

Recursion: Defining more complex objects/processes in terms ofsimpler ones

Recursive datatypes: Natural numbers, Words, Expressions,Well-formed formulas

Recursive programming/functions: Factorial, concatenate,length

Recurrence equations

UnrollingApproximating with big-OMaster Theorem

32

Page 39: COMP9020 - Lecture 17: Course Review

Master Theorem

The following result covers many recurrences that arise in practice(e.g. divide-and-conquer algorithms)

Theorem

Suppose

T (n) = a · T(nb

)+ f (n)

where f (n) ∈ Θ(nc(log n)k).

Let d = logb(a). Then:

Case 1: If c < d then T (n) = Θ(nd)

Case 2: If c = d then T (n) = Θ(nc(log n)k+1)

Case 3: If c > d then T (n) = Θ(f (n))

33

Page 40: COMP9020 - Lecture 17: Course Review

Week 7 Recap (continued)

Induction:

Basic induction

Variants of basic induction

Structural induction

Algorithmic Analysis:

Count “cost” (default: running time) of elementaryoperations as a function of (a parameter of) the input

Approximates real-world cost

Using both big-O and worst-case to simplify analysis

Recursive algorithms lead to recurrence equations

34

Page 41: COMP9020 - Lecture 17: Course Review

Week 8 Recap

Boolean logic

2-element Boolean Algebra

Boolean functions

CNF/DNF, canonical DNF

Karnaugh maps, optimal DNF

Propositional logic

Propositions

Tautologies, Contradictions, Contingencies

Logical equivalence

Entailment

35

Page 42: COMP9020 - Lecture 17: Course Review

Need to know for this course

Properties of 2-element Boolean Algebra

How to compute canonical CNF/DNF

How to prove properties of Boolean Algebras

How to prove/disprove logical equivalence and logicalentailment

36

Page 43: COMP9020 - Lecture 17: Course Review

Week 9 Recap

Combinatorics

Basic counting rules: Disjoint sets, Cartesian products

Permutations and Combinations

Balls in boxes

Using recursion to count

Approximate counting

37

Page 44: COMP9020 - Lecture 17: Course Review

Selecting items summary

Selecting k items from a set of n items:

With Order Balls in boxes Formulareplacement matters

Yes Yes Distinguishable balls nk

Multiple balls per box

No Yes Distinguishable balls Π(n, k)At most one ball per box

No No Indistguishable balls(nk

)At most one ball per box

Yes No Indistinguishable balls((nk

))=

(n+k−1k

)Multiple balls per box

38

Page 45: COMP9020 - Lecture 17: Course Review

Need to know for this course

Counting selections - which one to apply and how

Identifying symmetries

Using recursion to count

39

Page 46: COMP9020 - Lecture 17: Course Review

Need to know for this course

How and when to define datatypes and functions recursively

How to solve recurrence equations (up to big-O)

How to use induction to prove results about natural numbers

How to use structural induction on recursive structures

How to compute algorithm run-time in a variety of situations

40

Page 47: COMP9020 - Lecture 17: Course Review

Week 10 Recap

Probability

Sample spaces, probability distributions, events

Independence

Recursive probability calculations

Conditional probability

Statistics

Random variables

Expectation, linearity of expectation

Variance, standard deviation

41

Page 48: COMP9020 - Lecture 17: Course Review

Need to know for this course

How to calculate probabilities in various situations:

Uniform distributionsEvent combinationsSequences of independent eventsRecursive scenariosConditional cases

Interaction between properties such as independence,conditionality

How to calculate expected value of random variables invarious situations

42

Page 49: COMP9020 - Lecture 17: Course Review

Outline

Assessment Summary

Examination Philosophy

Content Review

Selection of Sample Questions

43

Page 50: COMP9020 - Lecture 17: Course Review

Sample Relations Question

Consider the relation R ⊆ R× R defined by aRb if, and only if,b + 0.5 ≥ a ≥ b − 0.5. Is R

(a) reflexive?

(b) antireflexive?

(c) symmetric?

(d) antisymmetric?

(e) transitive?

44

Page 51: COMP9020 - Lecture 17: Course Review

Sample Functions Question

Let Σ = a, b and define f : Σ∗ → R recursively as follows:

f (λ) = 0,

f (aw) = 12 + 1

2 f (w) for w ∈ Σ∗, and

f (bw) = −12 + 1

2 f (w) for w ∈ Σ∗.

Prove that f is injective.

45

Page 52: COMP9020 - Lecture 17: Course Review

Sample Graph Theory Question

Draw a single graph with 6 vertices and 10 edges that satisfieseach of the following:

(a) is planar,

(b) contains a Hamiltonian circuit, and

(c) does not contain an Eulerian path.

46

Page 53: COMP9020 - Lecture 17: Course Review

Sample Logic Question

Let (T ,∧,∨,′ , 0, 1) be a Boolean Algebra. Define ⊕ : T × T → Tas follows:

x ⊕ y = (x ∧ y ′) ∨ (x ′ ∧ y)

(a) Prove using the laws of Boolean Algebra that for all x ∈ T ,x ⊕ 1 = x ′.

(b) Prove using the laws of Boolean Algebra thatx ∧ (y ⊕ z) = (x ∧ y)⊕ (x ∧ z).

(c) Find a Boolean Algebra (and x , y , z) which demonstrates thatx ⊕ (y ∧ z) 6= (x ⊕ y) ∧ (x ⊕ z)

47

Page 54: COMP9020 - Lecture 17: Course Review

Sample Recursion/Induction Question

Let Σ = 1, 2, 3.(a) Give a recursive definition for the function sum : Σ∗ → N

which, when given a word over Σ returns the sum of thedigits. For example sum(1232) = 8, sum(222) = 6, andsum(1) = 1. You should assume sum(λ) = 0.

(b) For w ∈ Σ∗, let P(w) be the proposition that for all wordsv ∈ Σ∗, sum(wv) = sum(w) + sum(v). Prove that P(w)holds for all w ∈ Σ∗.

(c) Consder the function rev : Σ∗ → Σ∗ defined recursively asfollows:

rev(λ) = λFor w ∈ Σ∗ and a ∈ Σ, rev(aw) = rev(w)a

Prove that for all words w ∈ Σ∗, sum(rev(w)) = sum(w)

48

Page 55: COMP9020 - Lecture 17: Course Review

Sample Probability Question

A 4-letter word is selected at random from Σ4, whereΣ = a, b, c , d , e.

(a) What is the probability that the letters in the word aredistinct?

(b) What is the probability that there are no vowels in the word?

(c) What is the probability that the word begins with a vowel?

(d) What is the expected number of vowels in the word?

(e) Let x be the answer to the previous question. What is theprobability of the word having dxe or more vowels?

49