0% found this document useful (0 votes)
10 views1 page

Tree and Algorithm Analysis Exercises

This document outlines the expectations and exercises for Tutorial 3 of the MTH6105 - Algorithmic Graph Theory course. Students are expected to attempt all exercises before the tutorial and actively participate. The exercises cover proving properties of trees, analyzing algorithmic complexity, and analyzing Euclid's algorithm for finding the greatest common divisor of two numbers.

Uploaded by

adrverhar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Tree and Algorithm Analysis Exercises

This document outlines the expectations and exercises for Tutorial 3 of the MTH6105 - Algorithmic Graph Theory course. Students are expected to attempt all exercises before the tutorial and actively participate. The exercises cover proving properties of trees, analyzing algorithmic complexity, and analyzing Euclid's algorithm for finding the greatest common divisor of two numbers.

Uploaded by

adrverhar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MTH6105 – Algorithmic Graph Theory Spring 2023

Tutorial 3 F. Fischer

You are expected to attempt all exercises before the tutorial and to actively par-
ticipate in the tutorial itself.

1. Show that a graph G is a tree if and only if it contains no loops and a unique
u−v-path for every u, v ∈ V (G).
(a) For the direction from right to left, consider a graph G without loops and with
unique u−v-paths, and show that G is connected and acyclic.
(b) For the direction from left to right, show that if T is a tree, then it contains
unique u−v-paths.
2. (a) For functions f, g, h : N → R+ show the following:
(i) f (n) + g(n) is O(max{f (n), g(n)}).
(ii) if f (n) is O(g(n)) and g(n) is O(h(n)), then f (n) is O(h(n)).
(b) Let f (n) = a0 + a1 n + a2 n2 + a3 n3 , where a0 , a1 , a2 , a3 ∈ Z are constants. Show
that f (n) is O(n3 ).
(c) Show that 22n is not O(2n ). To this end, you may want to assume that it was
and derive a contradiction.
Note: This type of question looks intimidating, but really it is all bark and no
bite. Recalling the relevant definition, all we need to do to show that f (n) is O(g(n))
is find constants c and n0 with certain properties and verify that they indeed satisfy
these properties.
3. Euclid’s algorithm determines the greatest common divisor gcd(a, b) of two non-
negative integers a ≥ b by setting r0 = a, r1 = b, and then repeating the following
steps for rounds n = 2, 3, 4, . . . :
• If rn−1 = 0 then stop, output gcd(a, b) = rn−2 .
• Find qn and rn such that rn−2 = qn rn−1 + rn and 0 ≤ rn < rn−1 .
Note that (rn )n≥0 is a decreasing sequence of non-negative integers and the algorithm
thus stops after a finite number of rounds. Note further that it makes sense to say
that the size of the input of the algorithm is log2 a + log2 b, because this is the
number of digits of a and b as binary numbers.
(a) If rn were to decrease by 1 in each round, how many rounds would the algorithm
run for?
(b) Show that rn in fact decreases significantly over two consecutive rounds of the
algorithm, namely rn < rn−2 /2. You may want to distinguish among the three
cases where rn−1 = rn−2 , rn−2 /2 < rn−1 < rn−2 , or rn−1 ≤ rn−2 /2.
(c) Give an upper bound on the maximum number of rounds of the algorithm in
terms of the size of the input to the problem. You may want to argue that
after a certain number k of rounds, rk < 1 and the algorithm must therefore
have stopped.

Common questions

Powered by AI

To show that 2^2n is not O(2^n), assume for contradiction that it is. This assumption implies the existence of constants c and n0 such that for all n ≥ n0, 2^2n ≤ c * 2^n. Simplifying this inequality gives 2^n ≤ c, which is clearly false for sufficiently large n because 2^n grows exponentially. This contradiction shows that 2^2n is not O(2^n).

Viewing the input size of Euclid's algorithm as log2 a + log2 b implies that the number of bits (digits in binary) required to represent a and b directly affects computational efficiency. It frames the algorithm's performance in logarithmic terms, hence indicating that efficiency depends on the magnitude of numbers rather than their absolute values. This perspective reveals why the algorithm performs well even with large integers, as its cost grows modestly with input size .

Euclid’s algorithm is pivotal in number theory for its computational simplicity and robustness in evaluating gcds, reflecting the Euclidean property of integer reduction. Algorithmically, the notable insight is its logarithmic efficiency in terms of input size, log2 a + log2 b. The significant reductions achieved per round (rn < rn−2/2) underscore its optimized stepwise recursions compared to other methods, which supports its historical and ongoing relevance in algorithm design .

The uniqueness of a u-v path in a graph is critical in establishing it as acyclic because, in any cycle, there would exist at least two distinct u-v paths, contradicting the uniqueness assertion. Thus, proving unique paths inherently implies there are no cycles. Consequently, if any cycle were to exist, it would result in multiple paths between at least two vertices, thereby violating the condition that defines trees .

To prove f(n) = O(g(n)), one must find constants c and n0 such that for all n ≥ n0, the inequality |f(n)| ≤ c|g(n)| holds. The difficulty often lies in selecting an appropriate c and n0. For instance, demonstrating f(n) + g(n) is O(max{f(n), g(n)}) involves showing that the sum is dominated by the maximum of its components. This typically requires detailed analysis of how the functions grow relative to one another .

To establish that f(n) is O(n^3), recognize the terms that contribute to the growth rate. Given the dominant term is a3n^3, choose constants c ≥ |a0| + |a1| + |a2| + |a3| and n0 such that for n ≥ n0, |f(n)| = |a0 + a1n + a2n^2 + a3n^3| ≤ c|n^3|. This demonstrates that f(n) is bounded above by a constant multiple of n^3 for sufficiently large n, establishing the O(n^3) classification .

To show that a graph G is a tree by using the properties of no loops and unique u-v paths, start with the assumption that G has no loops and a unique path between any two vertices u and v. Demonstrate that G is connected because for any two vertices u, v, there is a path connecting them. Next, show G is acyclic by proving that any cycle would contradict the uniqueness condition of the u-v path. Conversely, if G is a tree, it is connected by definition, and the absence of cycles guarantees unique paths between any two vertices .

Euclid's algorithm exploits the relationship whereby the remainder rn decreases over two rounds such that rn < rn−2/2. By distinguishing cases such as rn−1 = rn−2, rn−2/2 < rn−1 < rn−2, or rn−1 ≤ rn−2/2, it becomes apparent that large steps are made towards the algorithm concluding. This decrease ensures rapid convergence, as significant shrinking of possible remainders occurs in successive rounds .

Euclid's algorithm calculates the gcd of two numbers, a and b (a ≥ b), by repeatedly setting r0 = a, r1 = b and executing division steps: rn−2 = qnrn−1 + rn, where 0 ≤ rn < rn−1, until rn reaches zero. The efficiency is influenced by input size, defined as log2 a + log2 b. Because rn decreases significantly, the number of rounds is bounded by a function of the input size. Specifically, rn < rn−2/2 ensures the sequence decreases quickly, which guarantees the algorithm finishes in at most O(log b) rounds .

If rn were to decrease by 1 each round, the algorithm would be inefficient because it would implicate linear progression down to zero, unnecessarily extending operational rounds. This behavior contrasts with the algorithm’s design where significant reduction (rn < rn−2/2) ensures rapid termination. Linear decrement would imply O(b) rounds, greatly exceeding its actual approximate O(log b) expectation, thus leading to suboptimal performance for large b .

You might also like