COMP9020 – Foundations of Computer Science
FINAL Exam – Term 3 2022
From Question 5 to Question 10
With my own solution (might be incorrect)
Question
Prove or disprove:
G has an Eulerian path
Here is the degree list for all of the vertices:
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
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.
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, .
Set vertex 0 in BLACK. And we could find that:
2 colors(black & white) could color graph G. Therefore, .
We could prove that:
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:
Question
Give a recursive definition of the function del:Σ* → Σ*
Pythondef del(w):
if not w:
return w
if w[0] == 'c':
return del(w[1:])
else:
return w[0] + del(w[1:])
Question
Let Σ={a,b,c}.
For w∈Σ*, let P(w) be the proposition that:
For all :
Prove, using your definition of del from part (a), that P(w) holds for all w∈Σ*.
When , P(w) could be:
For all :
It is true.
When ,
Set: , and single element could be: .
In addition,
Therefore, we could prove that:
P(w) holds for all w∈Σ*.
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
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.
And the sum is:
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: .
And for mySort(L)
, it use time to execute while
command, and every loop it executes extractMin(L)
to calculate the least element.
Therefore, the worst upper bould for .
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:
You would like to know if at least one of Red or Blue is an imposter.
Question
Explain how this problem can be modelled as a problem in Propositional Logic. In particular, clearly define:
We could define that:
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:
According to the statement of Green, there is at least one crewmate between Green and Blue.
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:
Question
Using the Propositional Logic model of part (a), solve the given problem.
We have that:
According to first two statement, we could find that:
Assum: R is true.
Assum: R is false.
Therefore, there is a solution for this spaceship:
Question
Suppose you have:
Show that there are:
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:
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 ways:
For the second step, we have ways:
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:
Question
Show that for all x,y,z ∈ ℕ:
If we have the same question in 9.1, we could change the steps in another way:
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 ways:
For the second step, we have ways:
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:
We use different ways to solve same question, and the result should be equal.
Therefore, it should be:
It means that:
Let
Let 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.
Question
What is p(0,n)?
Justify your answer
For every character in a n-word, the possibility that it is not 'c' is .
Therefore, .
Question
What is p(n,n)?
Justify your answer
For every character in a n-word, the possibility that it is 'c' is .
Therefore, .
Question
Give, with justification, an expression for p(k,n), either:
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:
It is:
By the way, the recursive way is:
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, , in n-word, the possibility of 'c', , is .
The expected number of c is:
本文作者:Jeff Wu
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!