Sei sulla pagina 1di 5

Department of Computer Science and Engineering University of California at San Diego

CSE 21 Winter 2001

Solutions for Quiz 1


1. [10 points] Consider two simple graphs graph as follows: every node of and

and every node of and every edge of

becomes a node of

every edge of

becomes an edge of

add an extra node to . Let be a node coming from and a node coming from . Connect to with an edge , to with an edge , and to with an edge also has an Euler circuit.

Prove that

In order to prove that

has an Euler circuit, we need to show that:

is connected; and

all vertices in

have even degrees.

To prove that is connected, we need to show that, for any two vertices and in , there exists a path from to . To do so, we can consider several cases. First, suppose that both and are in or . Then, we know that such path exists from the fact that both and are connected. Now suppose is in and is in . Then, we can construct a path from to by concatenating a path from to (we know one exists since is connected), to a path from to (e.g., ), and to a path from to (we know one exists since is connected). The and is in can be handled similarly. case where is in

To prove that all vertices in have even degrees, it sufces to show that , and have even degrees since, for all other nodes, this property follows from the fact that both or have Euler circuits. But that is true because both and originally have even degrees and we added exactly 2 edges to each of them and because the degree of is 2. An alternative and perhaps simpler way to prove that has an Euler circuit is to construct one such circuit. Let be an Euler circuit in starting and ending at . We know one such circuit exists from the assumption that has an Euler circuit. Let be an Euler circuit in starting and ending at . Then, the circuit resulting from concatenating to to to to is an Euler circuit in since all its vertices are visited at least once and all its edges are visited exactly once.

"

 

If and is in from to (e.g., The cases where similarly.

, then we can construct a path from to by concatenating a path ) to a path from to (we know one exists since is connected). and is in and and is in either or can be handled

that have Euler circuits. Construct a new ; ;

            

 

$#

 

2. [10 points] Are the following two graphs isomorphic? Prove your answer.

4
(a) Graph 1

d
(b) Graph 2

Yes, the two graphs are in fact isomorphic. Let and be respectively the graphs on the left and right hand sides. To show that and are isomorphic, we need to provide a one-to-one mapping between nodes in and nodes in such that there is an edge between nodes and in if and only if there is an edge between nodes and in . One can see that the following mapping works (check that out!):

Note that other mappings between and satisfying the above denition are possible, but we only need to provide one such mapping.

& & H i h% 4 H f e% 4 H c% 4 H 4 `% 4 H X p6 1 P@YgG 1 '@YdR 1 P@baG 1 P@YG 1 AW@VG 1 P@SR 1 P@G 1 E@4 % 4 H U T% 4 H Q I% 4 H F D%

& 764 9 & 5 8 1 )( &% 03 ' 20# ' 1 )( &%

1 % C A@4

1 % B A@4

  e A@4 1 %

A% q h prYs1 q1 A% q h
for all

p G on  c  kj u u l Ag % i u % 1 u 1 % % 1 Ai 1 A@4 % % 1 A 1 A% q`  1 A@4


Path yes yes yes yes yes no yes yes yes Simple Path yes no no no no no yes no no Circuit no yes no yes no no no yes no is Simple Circuit no yes no no no no no yes no .

4. [12 points] Prove using the big-Oh denition that

3. [10 points] In the graph below, determine whether the following walks are paths, simple paths, circuits, simple circuits, or just walks. You do not have to justify your answer.

From the big-Oh denition, we know that if there exists and such that for every , . Hence, we need to nd two values and such that for every . The following shows that, for and , and will do.

%i 1 Agc ` 1 A% q` % % q 1 Ami A% 1 Aq ` h i1 ` e % f1 A@4 u d


.

Walk

e2

e12

e1

e3

e11

because and consequently

 1 A@4 %

T qh t 3e s qc r q`  q##D qI v q` v qT qI h u W Iwh `y $qT q#q q#xW e h ` y W  tq# qCx$qT qI #D I h qT q# q` u qT qI D qI w qh  v q` qI T w ` y Wv qI#qh # qT u qCx$qT h qI vv q` v qT qI w h s c ru ` Ct3eq##q qh W  qT qI #D

e10

1 e9 4

e8 e4 8 5

e13

e7 e5

7 6 e6

5. [12 points] (a) Find the function that counts the number of assignments and comparisons that must be performed when the following algorithm segment is executed. Do not count the := that appears in the for lines. for i:= 1 to n temp := a[i] for j:=1 to i if temp < a[j] then max:= a[j] + 1 next j next i

From the above segment, we can see that each iteration of the inner loop will perform two operations in the worst case, one comparison ( ) and one assignment ( ). The only exception is the last iteration of the inner loop ( ), which only performs one operation since the comparison will always return false. Since this inner loop iterates times, the total number of operations due to the inner loop is . Hence, each iteration of the outer loop will perform operations where is the index of the outer loop. The extra operation is due to the assignment . Therefore, because goes from to , the total number of is operations

%  t % 1 Atot R 1 At@4

gt

(b) Find the best big-Oh approximation for from the set of power functions do not have to justify your answer. By using Theorem 9.2.1 from the textbook, we know that

I  D  oD Y"I

x  

y3x wmQ h C v u yw 3x mQ h #E v u

t t % 1 I D Att j I 1 D At%t  I j

% 1 At@4

I 

At@4 % y w Q 5 v1u P m}|#E 

% 1 At@4

D  {I

y wQ 5 Q qx ~}|{zu

. You .

6. [12 points] Find an explicit formula for the following sequence.

To solve this problem, we rst need to compute the roots of characteristic equation. In this case, the characteristic equation is

By the quadratic formula. the roots are:

It follows from the distinct root theorem that the above sequence satises the explicit formula:

Hence, we have the following system of equations:

Substituting these values in Equation (5), we have the following:

I  ! gdT

By multiplying Equation (6) by 2 and subtracting it from Equation (7), we get that . By substituting this value in Equation (6), we get that . Hence,

Th 3dR

I % T ` %  'xj T I% `% vxj T {Q  1 'h 1 'I 1 h 1 I

I d` ! !

 G I  G I

Q uQ

I G Q

TI  3dg!

I G u Q !

where ditions

and

are the numbers whose values make the above formula meet the initial conand .

D g

"I H "`

I% `% j !  ( 1 'xj 1 P{o{Q

p  p R9CD

 CdI xW e @ pDj W 

"I H "I QpD Q ( "qC| {e e  

for all

(1) (2) (3)

 Q  Q  u"Q

(4)

(5)

(6) (7) .

(8)

Potrebbero piacerti anche