You are on page 1of 11

CSCI 2014 - Module 4 Assignment

Author: Ahmed Haguf

Spring 2021 - 53 Points


Sec 10.2: #5

a. How many paths are there from a to c?

The objective is to find the number of paths in a graph between vertices to .

A path in a graph is a finite or infinite sequence of edges which connect a sequence of

vertices. Thus, the above graph has four paths namely

b. How many trails are there from a to c?

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 .

Therefore, the total number of trails is

c. How many walks are there from a to c?

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.2: #12

Does this graph contain an Euler circuit?


Yes
If ”no”, why? If ”yes”, describe one?
Starts and ends at the same vertex and traverses every edge in the graph exactly once.
Sec 10.2: #13
Does this graph contain an Euler circuit?
No
If ”no”, why? If ”yes”, describe one?
Odd degree vertices: v9, v7

Sec 10.2: #23


Describe a Hamiltonian circuit for the graph:
Hamiltonian Circuit will be ----
v0→v1→v2→v3→v4→v5→v6→v7→v0

Hence we see that each vertex is visited exactly once


Thus graph has Hamiltonian Circuit.

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: #7 Rewrite the following statement using O-notation. | 3x 6 + 5x 4 − x 3 |≤ 9 | x 6 |


for all real numbers x > 1 3x 6 + 5x 4 − x 3 is
The rewritten statement using Big O notation is:
|3x^6 + 5x^4 - x^3| ≤ O(x^6) for all real numbers x > 1.

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

The rewritten statement using Theta (Θ) notation is:


1/2 |x^2| ≤ |3x^2 - 80x + 7| ≤ 3 |x^2| for all real numbers x > 25.

Sec 11.2: #17


a. Show that for any real number x,
if x > 1 then | x 4 |≤| 23x 4 + 8x 2 + 4x |.
Given that x > 1, let's start by considering the expression on the right side:

|23x^4 + 8x^2 + 4x|

Now, we can break it down into cases based on the sign of x:

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

Now, comparing |x^4| and |23x^4 + 8x^2 + 4x|:


|x^4| = x^4

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

Now, comparing |x^4| and |23x^4 + 8x^2 + 4x|:


|x^4| = -x^4

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:

|23x^4 + 8x^2 + 4x|

We can break it down into cases based on the sign of x:

For x > 0:
In this case, |x| = x, so we have:
|23x^4 + 8x^2 + 4x| = 23x^4 + 8x^2 + 4x

Now, comparing |23x^4 + 8x^2 + 4x| and |x^4|:


|23x^4 + 8x^2 + 4x| = 23x^4 + 8x^2 + 4x
|x^4| = x^4
We need to show that 23x^4 + 8x^2 + 4x ≤ 35x^4 for x > 0.
Subtracting 23x^4 + 8x^2 + 4x from both sides, we get:
12x^4 - 8x^2 - 4x ≥ 0

Factoring out x, we have:


x(12x^3 - 8x - 4) ≥ 0

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.

Therefore, for x > 0, we have |23x^4 + 8x^2 + 4x| ≤ |x^4|.

For x < 0:
In this case, |x| = -x, so we have:
|23x^4 + 8x^2 + 4x| = -(23x^4 + 8x^2 + 4x)

Now, comparing |23x^4 + 8x^2 + 4x| and |x^4|:


|23x^4 + 8x^2 + 4x| = -(23x^4 + 8x^2 + 4x)
|x^4| = -x^4

We need to show that -(23x^4 + 8x^2 + 4x) ≤ 35(-x^4) for x < 0.


Multiplying both sides by -1 and simplifying, we get:
23x^4 + 8x^2 + 4x ≤ -35x^4

Rearranging the terms, we have:


58x^4 + 8x^2 + 4x ≤ 0

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.

Therefore, for x < 0, we have |23x^4 + 8x^2 + 4x| ≤ |x^4|.

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

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.
Using the O-notation, we can express the result as:
23x^4 + 8x^2 + 4x = O(x^4)
This means that 23x^4 + 8x^2 + 4x has an upper bound growth rate of x^4 or lower.

(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.

Using the O-notation, we can express the result as:


23x^4 + 8x^2 + 4x = O(x^4)

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:

The Ω-notation (lower bound) is Ω(x^4).


The O-notation (upper bound) is O(x^4).
The Theta-notation (tight bound) is Θ(x^4).
These notations provide information about the growth rate or complexity of the expression
with respect to the variable x.

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

a. Number of operations (additions, subtractions, multiplications, divisions) that must be


performed when the algorithm segment is executed:
In the given algorithm segment, we have:
Two assignments: a := 2 · n + i · j (1 multiplication, 1 addition)
Two nested loops:
The inner loop runs 2n times and performs one multiplication and one addition for each
iteration.
The outer loop runs n times and contains the inner loop.
Let's break down the number of operations:
Assignments: 2 (1 multiplication and 1 addition)
Inner loop (for j := 1 to 2n):
Number of multiplications: 2n (since the multiplication a := 2 · n + i · j is done 2n times)
Number of additions: 2n (since the addition a := 2 · n + i · j is done 2n times)
Outer loop (for i := 1 to n):
The inner loop runs 2n times for each iteration of the outer loop.
So, the total number of multiplications = n * (2n) = 2n^2
The total number of additions = n * (2n) = 2n^2
Total operations:
Multiplications: 2 (from assignments) + 2n (from inner loop) + 2n^2 (from outer loop) = 2n^2
+ 2n + 2
Additions: 2 (from assignments) + 2n (from inner loop) + 2n^2 (from outer loop) = 2n^2 + 2n
+2
b. Using the theorem on polynomial orders to find an order for the algorithm segment:
Based on the analysis, we can see that the algorithm segment has the following order of
operations:

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).

Sec 11.5: #26


To compute x^n efficiently using the binary representation of n, we can follow these steps in
the algorithm:

1. Initialize a variable result to store the final result, and set it to 1.


2. Initialize a variable temp to store the intermediate result, and set it to x.
3. Convert the positive integer n to its binary representation.
4. Traverse the binary representation of n from the least significant bit to the most
significant bit.
5. For each bit in the binary representation:
a. If the bit is 1, multiply the result by the current value of temp.
b. Shift the temp value by squaring it (multiply temp by itself).
c. Move on to the next bit in the binary representation by dividing n by 2 (right-shifting
n).
6. After the loop ends, return the final value of result, which will be x^n.

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).

Now, the number of multiplications in terms of the value of n is given by:

num_multiplications(n) = number of set bits in the binary representation of n = number of 1s


in the binary representation of n

The number of set bits in the binary representation of n is also known as the Hamming
weight of n.

Comparing with the optimal solution of ⌊log2(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.

In conclusion, the algorithm's number of multiplications is equal to the optimal solution of


⌊log2(n)⌋, making it an efficient approach to compute x^n.

You might also like