2024-04-26
24T1
00

目录

Question 5
5.1
5.2
5.3
Question 6
6.1
6.2
Question 7
7.1
7.2
Question 8
8.1
8.2
Question 9
9.1
9.2
Question 10
10.1
10.2
10.3
10.4

COMP9020 – Foundations of Computer Science

FINAL Exam – Term 3 2022

From Question 5 to Question 10

With my own solution (might be incorrect)

Question 5

image.png

5.1

Question

Prove or disprove:

G has an Eulerian path

Here is the degree list for all of the vertices:

  • vertex 0: 3
  • vertex 1: 2
  • vertex 2: 2
  • vertex 3: 4
  • vertex 4: 4
  • vertex 5: 2
  • vertex 6: 2
  • vertex 7: 3

We could find that there are 2 vertices (0 and 7) whose degree is odd. This could prove that there is an Eulerian path in G.

For example:

0 → 2 → 3 → 1 → 0 → 4 → 5 → 7 → 6 → 4 → 3 → 7

5.2

Question

Prove or disprove:

G has a Hamiltonian cycle

If it has a Hamiltonian cycle, it means that no matter which vertex I start, I could find a cycle. Because this cycle should get every vertex.

Divide these vertices into 2 subsets: {0, 1, 2, 3} and {4, 5, 6, 7}. Edges (0, 4), (3, 4) and (3, 7) are linking these 2 subsets.

Set start point at vertex 1, and we could go to vertex 0 or vertex 3.

If we go to vertex 0, we could go to vertex 2 or vertex 4 for next step.

If we go to vertex 2, we must go to vertex 3 for next step, but it means that we could not come back from {4, 5, 6, 7} because we should use vertex 0 or vertex 3 to go back and get vertex 1 at the last step.

So we should return, and go to vertex 4 when we are at vertex 0. However, after a trip in {4, 5, 6, 7}, we can only go back by vertex 3, and then we must choose to go to vertex 2 and get vertex 0. This is also a bad path.

So we return again, and go to vertex 3 when we are at vertex 1. However, it is same when we come back from {4, 5, 6, 7}. we could only choose vertex 0 to come back, but we have to go to vertex 2 and reach the vertex 3 in the end.

In conclusion, after the path finding, we could prove that this graph does not have a Hamiltonian cycle.

5.3

Question

Prove or disprove:

The chromatic number of G is equal to the clique number of G. That is, χ(G) = κ(G).

The clique number should be the vertex number of the smallest complete sub-graph in G.

In graph G, we could only find 2-clique (an edge and 2 vertices at 2 sides). There is not any tri-angle (3-complete graph) in G. Therefore, κ(G)=2κ(G) = 2.

Set vertex 0 in BLACK. And we could find that:

  • vertex 0: BLACK
  • vertex 1: WHITE
  • vertex 2: WHITE
  • vertex 3: BLACK
  • vertex 4: WHITE
  • vertex 5: BLACK
  • vertex 6: BLACK
  • vertex 7: WHITE

2 colors(black & white) could color graph G. Therefore, χ(G)=2χ(G) = 2.

We could prove that:

χ(G)=κ(G)χ(G) = κ(G)

Question 6

Let Σ = {a,b,c}

Consider the function del:Σ* → Σ* which works as follows:

For w∈Σ*, del(w) is the word that results from removing all c's from w.

For example:

  • del(aabbcc) = aabb
  • del(ccbbaacc) = bbaa
  • del(bacabc) = baba
  • del(cccc) = λ
  • del(bbbb) = bbbb

6.1

Question

Give a recursive definition of the function del:Σ* → Σ*

  • del(λ)=λdel(\lambda) = \lambda
  • del(cx)=del(x)del(cx) = del(x)
  • del(mx)=m+del(x)del(mx) = m + del(x) if ma,bm \in {a,b}
Python
def del(w): if not w: return w if w[0] == 'c': return del(w[1:]) else: return w[0] + del(w[1:])

6.2

Question

Let Σ={a,b,c}.

For w∈Σ*, let P(w) be the proposition that:

For all vΣv \in Σ^*: del(wv)=del(w)del(v)del(wv) = del(w)del(v)

Prove, using your definition of del from part (a), that P(w) holds for all w∈Σ*.

When w=λw = \lambda, P(w) could be:

For all vΣv \in Σ^*: del(v)=del(v)del(v) = del(v)

It is true.

When w=w1w2...wkw = w_1w_2...w_k,

Set: Σ=a,bΣ' = {a,b}, and single element wiw_i could be: ΣcΣΣ'^*c^*Σ'^*.

del(wv)=del((ΣcΣ)v)=(ΣΣ)del(v)del(wv) = del((Σ'^*c^*Σ'^*)^*v) = (Σ'^*Σ'^*)^*del(v)

In addition, del(w)=(ΣΣ)del(w) = (Σ'^*Σ'^*)^*

Therefore, we could prove that:

P(w) holds for all w∈Σ*.

Question 7

Consider the following two pieces of code.

The first moves the minimum element of a list to its head

extractMin(L): if length(L) <= 1: return L x = L.head L2 = extractMin(L.next) if x < L2.head: return L else: L3 = (x, L2.next) return (L2.head, L3)

The second sorts a list by repeatedly extracting the minimum element using extractMin

mySort(L): i = 0 L2 = empty L3 = L while i < length(L): L3 = extractMin(L3) L2 = (L3.head, L2) L3 = L3.next i = i+1 return L2

7.1

Question

Find an asymptotic upper bound for T(n): the running time of the worst-case of extractMin(L) where L is a list with n elements.

You may assume that creating a list is an elementary operation, as is checking the length of L.

The worst case is that:

for every element in position i, it is the least element compared with all elements before. function should move n-i times to make it to the top of this list.

T(n)=T(n1)+O(n)T(n) = T(n-1) + O(n)

And the sum is:

T(n)=O(n)+O(n1)+...+O(1)=O(n(n+1)2)T(n)=O(n2)T(n) = O(n) + O(n-1) + ... + O(1) = O(\frac{n(n+1)}{2}) \\ T(n) = O(n^2)

7.2

Question

Find an asymptotic upper bound for R(n): the running time of the worst-case of mySort(L) where L is a list of n elements.

You may assume that creating a list is an elementary operation, as is checking the length of L. You may assume the running time of extractMin on a list of length n is T(n) [if not previously calculated].

We have proved that the worst-case of extractMin(L) is: O(n2)O(n^2).

And for mySort(L), it use O(n)O(n) time to execute while command, and every loop it executes extractMin(L) to calculate the least element.

Therefore, the worst upper bould for R(n)=O(n2×n)=O(n3)R(n) = O(n^2 \times n) = O(n^3).

Question 8

A spaceship is full of crewmates and imposters. Crewmates always tell the truth, and imposters always lie. Everyone is either a crewmate or an imposter. Three members of the spaceship, Red, Green and Blue, make the following statements:

  • Red: Blue is not an imposter
  • Green: At least one of Blue or Green is a crewmate
  • Blue: Green is an imposter

You would like to know if at least one of Red or Blue is an imposter.

8.1

Question

Explain how this problem can be modelled as a problem in Propositional Logic. In particular, clearly define:

  • The propositional variables you are using and what propositions they represent
  • Any formulas that are appropriate, and what propositions they represent
  • The Propositional Logic problem to be solved

We could define that:

  • RR:Red is crewmate
  • GG: Green is crewmate
  • BB: Blue is crewmate

According to the statement of Red, if Red is crewmate, we could find that Blue is crewmate. If Red is not crewmate, Blue is not crewmate. That means:

RB¬R¬BRBR \rightarrow B\\ \neg R \rightarrow \neg B \\ R \leftrightarrow B

According to the statement of Green, there is at least one crewmate between Green and Blue.

¬B¬G\neg B \vee \neg G

According to the statement of Blue, if Green is a crewmate, Blue is an imposter; if Green is an imposter, we could find that this statement is true, and Blue is crewmate. That means:

¬GBG¬B¬GB\neg G \rightarrow B \\ G \rightarrow \neg B \\ \neg G \leftrightarrow B

8.2

Question

Using the Propositional Logic model of part (a), solve the given problem.

We have that:

  • RBR \leftrightarrow B
  • ¬GB\neg G \leftrightarrow B
  • ¬B¬G\neg B \vee \neg G

According to first two statement, we could find that:

  • R¬GR \leftrightarrow \neg G

Assum: R is true.

  • According to RBR \leftrightarrow B, B is true.
  • According to R¬GR \leftrightarrow \neg G, G is false.
  • ¬B¬G\neg B \vee \neg G is true. However, it should be false because Green is imposter.

Assum: R is false.

  • According to RBR \leftrightarrow B, B is false.
  • According to R¬GR \leftrightarrow \neg G, G is true.
  • ¬B¬G\neg B \vee \neg G is true.

Therefore, there is a solution for this spaceship:

  • Red is imposter
  • Green is crewmate
  • Blue is imposter

Question 9

9.1

Question

Suppose you have:

  • x indistinguishable red balls
  • y indistinguishable blue balls
  • z indistinguishable green balls

Show that there are:

(x+y+zz)(x+yy)\binom{x+y+z}{z}\binom{x+y}{y}

ways of placing the balls into x+y+z distinguishable boxes with exactly one ball per box.

We could use 3 steps to place all the balls:

  1. select z empty boxes and place all of the green balls.
  2. select y empty boxes and place all of the blue balls.
  3. place all of the red balls into the rest boxes.

Because every ball is indistinguishable, we do not need to consider the order of placing between same color balls.

For the first step, we have T1T_1 ways:

T1=Cx+y+zz=(x+y+zz)T_1 = C_{x+y+z}^{z} = \binom{x+y+z}{z}

For the second step, we have T2T_2 ways:

T2=Cx+yy=(x+yy)T_2 = C_{x+y}^{y} = \binom{x+y}{y}

And the last step do not need any extra calcuation. Because after step 1 and step 2, there is just one option for step 3 to put balls.

In addition, the selection in step 1 could effect selection in step 2. Because every box is distinguishable. Therefore, every selection is unique.

So we could prove that the way of placing balls are:

T1×T2=(x+y+zz)(x+yy)T_1 \times T_2 = \binom{x+y+z}{z}\binom{x+y}{y}

9.2

Question

Show that for all x,y,z ∈ ℕ:

(x+y+zz)(x+yy)=(x+y+zx)(y+zy)\binom{x+y+z}{z}\binom{x+y}{y} = \binom{x+y+z}{x}\binom{y+z}{y}

If we have the same question in 9.1, we could change the steps in another way:

  1. select x empty boxes and place all of the red balls.
  2. select y empty boxes and place all of the blue balls.
  3. place all of the green balls into the rest boxes.

Because every ball is indistinguishable, we do not need to consider the order of placing between same color balls.

For the first step, we have T3T_3 ways:

T3=Cx+y+zx=(x+y+zx)T_3 = C_{x+y+z}^{x} = \binom{x+y+z}{x}

For the second step, we have T4T_4 ways:

T4=Cy+zy=(y+zy)T_4 = C_{y+z}^{y} = \binom{y+z}{y}

And the last step do not need any extra calcuation. Because after step 1 and step 2, there is just one option for step 3 to put balls.

In addition, the selection in step 1 could effect selection in step 2. Because every box is distinguishable. Therefore, every selection is unique.

So we could prove that the way of placing balls are:

T3×T4=(x+y+zx)(y+zy)T_3 \times T_4 = \binom{x+y+z}{x}\binom{y+z}{y}

We use different ways to solve same question, and the result should be equal.

Therefore, it should be:

T=T1×T2=T3×T4T = T_1 \times T_2 = T_3 \times T_4

It means that:

(x+y+zz)(x+yy)=(x+y+zx)(y+zy)\binom{x+y+z}{z}\binom{x+y}{y} = \binom{x+y+z}{x}\binom{y+z}{y}

Question 10

Let Σ={a,b,c}Σ = \{a,b,c\}

Let p(k,n)p(k, n) be the probability that a word (over Σ) of length n, drawn uniformly at random from the set of all words of length n, contains exactly k c's.

10.1

Question

What is p(0,n)?

Justify your answer

For every character in a n-word, the possibility that it is not 'c' is 23\frac{2}{3}.

Therefore, p(0,n)=(23)np(0,n) = (\frac{2}{3})^n.

10.2

Question

What is p(n,n)?

Justify your answer

For every character in a n-word, the possibility that it is 'c' is 13\frac{1}{3}.

Therefore, p(n,n)=(13)np(n,n) = (\frac{1}{3})^n.

10.3

Question

Give, with justification, an expression for p(k,n), either:

  • in terms of combinatorial functions, or
  • recursively, in terms of p(k', n') where k'≤k and n'≤n

We use combinatorial functions to solve this question.

For a n-word, we should select k characters to set 'c', and other characters are not 'c'.

Therefore, we could find that:

p(k,n)=(nk)×(13)k×1×(23)nkp(k,n) = \binom{n}{k} \times (\frac{1}{3})^k \times 1 \times (\frac{2}{3})^{n-k}

It is:

p(k,n)=(nk)×2nk3kp(k,n) = \binom{n}{k} \times \frac{2^{n-k}}{3^k}

By the way, the recursive way is:

p(k,n)=13p(k1,n1)+23p(k,n1)p(k,n) = \frac{1}{3}p(k-1,n-1) + \frac{2}{3}p(k, n-1)

10.4

Question

What is the expected number of c's in a word of length n, drawn uniformly at random from the set of all words (over Σ) of length n?

For every character, cic_i, in n-word, the possibility of 'c', pip_i, is 13\frac{1}{3}.

The expected number of c is:

i=1npi×length(wi)=13×1+13×1...+13×1=n3\sum_{i=1}^n p_i \times length(w_i) = \frac{1}{3} \times 1 + \frac{1}{3} \times 1 ... + \frac{1}{3} \times 1 = \frac{n}{3}

本文作者:Jeff Wu

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!