CSCI 2014 - Module 4 Assignment
CSCI 2014 - Module 4 Assignment
The objective is to find the number of trails in the graph from vertices to .
From part (a), it is clear that there are 4 trails, that is, there is a choice of 4 edges when
going from a to b, and two choices of different edges to come back to , then 2 choices of
different edges to go to and once choice of different edge to return to .Thus, there are
4! trails from to .
The objective is to find the number of walks between the vertices and . As the walk
may have repeated edges, a walk from a to b may contain an arbitrarily large number of
edges joining a pair of vertices along the way. Thus, the number of walks from a to b is
infinite.
Sec 10.5: #7
List all terminal vertices:
v1, v5, v7
List all internal vertices:
v2, v3, v4, v6
Sec 10.5: #8 Draw a tree with nine vertices and nine edges. If no such graph exists, explain
why.
1
/|\
2 3 4
/\|/\
5 67 8
|
9
Sec 10.5: #22 A connected graph has twelve vertices and eleven edges. Does it have a
vertex of degree 1? Why?
In a connected graph with twelve vertices and eleven edges, it is not possible for every
vertex to have a degree greater than or equal to 2. This is because each edge connects two
vertices, and if each vertex had a degree of 2 or more, the graph would have at least 12 * 2
= 24 degrees in total, which would require at least 12 edges.
Since the graph has only eleven edges, it means that at least one vertex must have a
degree less than 2 in order to compensate for the shortage of edges.
Therefore, in a connected graph with twelve vertices and eleven edges, there must be at
least one vertex of degree 1. This vertex would have only one edge incident to it, while the
remaining vertices would have degrees greater than or equal to 2.
Sec 11.2: #9 Rewrite the following statement using Θ-notation. 1 2 | x 2 |≤| 3x 2 − 80x + 7 |≤
3 | x 2 | for all real numbers x > 25. 3x 2 − 80x + 7 is
For x > 0:
In this case, |x| = x, so we have:
|23x^4 + 8x^2 + 4x| = 23x^4 + 8x^2 + 4x
Since x > 1, x^4 > x^2 > x, and we can rewrite the expression as:
23x^4 + 8x^2 + 4x > x^4 + x^2 + x
We can see that x^4 ≤ x^4 + x^2 + x, so |x^4| ≤ |23x^4 + 8x^2 + 4x| when x > 0.
For x < 0:
In this case, |x| = -x, so we have:
|23x^4 + 8x^2 + 4x| = -(23x^4 + 8x^2 + 4x)
Since x < 0, x^4 > x^2 > x, and we can rewrite the expression as:
-(23x^4 + 8x^2 + 4x) < -x^4 - x^2 - x
We can see that -x^4 ≤ -x^4 - x^2 - x, so |x^4| ≤ |23x^4 + 8x^2 + 4x| when x < 0.
Since we have covered both cases (x > 0 and x < 0), we can conclude that for any real
number x, if x > 1, then |x^4| ≤ |23x^4 + 8x^2 + 4x|.
b. Show that for any real number x, if x > 1 then | 23x 4 + 8x 2 + 4x |≤ 35 | x 4 |.
Given that x > 1, let's consider the expression on the left side:
For x > 0:
In this case, |x| = x, so we have:
|23x^4 + 8x^2 + 4x| = 23x^4 + 8x^2 + 4x
Since x > 0, we need to consider the sign of 12x^3 - 8x - 4. We can notice that for x > 1, this
expression is greater than or equal to zero, ensuring the inequality holds.
For x < 0:
In this case, |x| = -x, so we have:
|23x^4 + 8x^2 + 4x| = -(23x^4 + 8x^2 + 4x)
Similar to the previous case, we can notice that for x > 1, this expression is less than or
equal to zero, ensuring the inequality holds.
Since we have covered both cases (x > 0 and x < 0), we can conclude that for any real
number x, if x > 1, then |23x^4 + 8x^2 + 4x| ≤ 35 |x^4|.
c. Use the Ω- and O-notations to express the results of parts (a) and (b).
(a): 23x 4 + 8x 2 + 4x is
(b): 23x 4 + 8x 2 + 4x is
23x^4 + 8x^2 + 4x = Ω(x^4)
This means that 23x^4 + 8x^2 + 4x has a lower bound growth rate of x^4 or higher.
This means that 23x^4 + 8x^2 + 4x has an upper bound growth rate of x^4 or lower.
In both cases (a) and (b), the expressions 23x^4 + 8x^2 + 4x fall within the same growth rate
bounds of Ω(x^4) and O(x^4), indicating that the growth rate of the expressions is
proportional to x^4.
d. What are the Ω-, O-, and T heta-notations for 23x 4 + 8x 2 + 4x?
For the expression 23x^4 + 8x^2 + 4x, the notations are as follows:
Ω-notation: Ω(x^4)
The Ω-notation provides a lower bound growth rate. In this case, 23x^4 + 8x^2 + 4x has a
lower bound growth rate of x^4 or higher.
O-notation: O(x^4)
The O-notation provides an upper bound growth rate. In this case, 23x^4 + 8x^2 + 4x has an
upper bound growth rate of x^4 or lower.
Theta-notation: Θ(x^4)
The Theta-notation combines the Ω-notation and the O-notation to indicate a tight bound
growth rate. In this case, 23x^4 + 8x^2 + 4x has a growth rate that is proportional to x^4.
To summarize:
Sec 11.3: #3 Suppose an algorithm requires cn3 operations when performed with an input of
size n (where c is a constant).
a. How many operations will be required when the input size is increased
from m to 2m (where m is a positive integer)?
The expression 23x^4 + 8x^2 + 4x involves three terms: 23x^4, 8x^2, and 4x. For each term,
the power of x is fixed and does not change with the input size. Therefore, the number of
operations remains constant regardless of the input size.
So, when the input size is increased from m to 2m, the number of operations required will
remain the same.
b. By what factor will the number of operations increase when the input size
is doubled?
Since the number of operations remains the same when the input size is doubled, the factor
by which the number of operations will increase is 1.
c. By what factor will the number of operations increase when the input size
is increased by a factor of ten?
Let's consider the expression 23x^4 + 8x^2 + 4x again.
When the input size is increased by a factor of ten, it means we are multiplying the original
input size (m) by ten to get the new input size (10m).
Now, let's see how the number of operations changes when the input size increases from m
to 10m.
For the expression 23x^4 + 8x^2 + 4x, the number of operations remains constant,
regardless of the input size, because the powers of x in each term (x^4, x^2, x) do not
change with the input size.
Therefore, when the input size is increased by a factor of ten (from m to 10m), the number of
operations required remains the same. The factor by which the number of operations
increases is 1.
Sec 11.3: #9 Assume that n is a positive integer. Given this algorithm,
answer the following questions:
for i := 1 to n
for j := 1 to 2n
a := 2 · n + i · j
next j
next i
Order: O(n^2)
The dominant term is 2n^2, and the lower-order terms (2n and 2) become insignificant as n
becomes larger. Therefore, we can approximate the order of this algorithm segment as
O(n^2).
b. Analyze your algorithm in part (a) and determine the number of multiplications performed
in terms of the value of n. How does it compare with
the optimal solution of ⌊log2(n)⌋
The algorithm iterates over each bit of n, performing a multiplication if the current bit is 1 and
then squares the value of x at each iteration. We perform a multiplication only when the
current bit in the binary representation of n is 1, which is why the total number of
multiplications in the algorithm is equal to the number of set bits (1s) in the binary
representation of n.
Let's denote the number of multiplications performed in the algorithm as
num_multiplications(n).
The number of set bits in the binary representation of n is also known as the Hamming
weight of n.
The optimal solution for computing x^n using only multiplication and squaring requires
log2(n) multiplications. This is because we can determine the number of bits in the binary
representation of n, which is ⌊log2(n)⌋ + 1, and perform log2(n) multiplications (when
counting from 0 to ⌊log2(n)⌋).
The algorithm provided in part (a) computes x^n using the same number of multiplications as
the optimal solution, which is log2(n) multiplications. This is achieved by efficiently
leveraging the binary representation of n to determine the relevant x^2^i terms that need to
be multiplied together and using squaring to avoid unnecessary multiplications.