sample final questions for rrr - complexity zoo and...

163
Sample Final Questions for RRR - Complexity Zoo and Counting F1. Find the error in this false statement and correct it: Finding the chromatic number of a graph is NP-complete.F2. Find the error in this false statement and correct it: Solving the Traveling Salesman Problem NP-complete.F3. Is this problem “Is the number N=561 composite?” in NP? F4. Count the number of proper 3-colorings of the graph G : G v 3 v 2 v 1 v 4 F5. Count the number of proper colorings of the graph G above that uses at most one color. Count the number of proper colorings of the graph G above that uses at most two colors. Count the number of proper colorings of the graph G above that uses at most four colors. Rubalcaba ([email protected] ) Sample Final Questions 1 / 162

Upload: nguyenkhuong

Post on 27-Mar-2018

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Complexity Zoo and

Counting

F1. Find the error in this false statement and correct it:“Finding the chromatic number of a graph is NP-complete.”

F2. Find the error in this false statement and correct it:“Solving the Traveling Salesman Problem NP-complete.”

F3. Is this problem “Is the number N=561 composite?” in NP?

F4. Count the number of proper 3-colorings of the graph G :

G

v3v

2v

1v

4

F5. Count the number of proper colorings of the graph G above that usesat most one color. Count the number of proper colorings of the graphG above that uses at most two colors. Count the number of propercolorings of the graph G above that uses at most four colors.

Rubalcaba ([email protected]) Sample Final Questions 1 / 162

Page 2: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Greedy Colorings

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color the vertices ofthe graph using this ordering v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

F7. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color the vertices ofthe above graph using this orderingv1, v2, v3, v5, v7, v9, v11, v4, v6, v8, v10, v12 of the vertices.

F8. Explain the difference between greedy coloring and the chromaticnumber.

Rubalcaba ([email protected]) Sample Final Questions 2 / 162

Page 3: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Minimum Proper

Colorings

For F9 - F13 properly color the vertices of the graph using the minimumnumber of colors.

F9. The complete multipartite graph K2,3,3,7.

F10. The Petersen graph

F11. The Grotzsch graph

F12. A random tree on 10 vertices.

F13. The graph G in question F6

Rubalcaba ([email protected]) Sample Final Questions 3 / 162

Page 4: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Graph Isomorphisms

F14. Are these two graphs isomorphic?Hv

3v

2v

10v

4v

5v6v

7v

8v

9v

1u 2u

3u

4u

5u

6u7u

8u

9u

10u

G 1

F15. In two line notation, list all isomorphisms from G to H

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Rubalcaba ([email protected]) Sample Final Questions 4 / 162

Page 5: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Graph Isomorphisms

F16. Are these two graphs isomorphic?Hv

3v

2v

10v

4v

5v6v

7v

8v

9v

10u

1u

4u7u

3u

2u

8u

9u

5u 6u

G 1

F17. Explain why the YES / NO question is in NP:“Are the two graphs G and H isomorphic?”

F18. Verify that

ˆ

v1 v2 v3 v4 v5 v6 v7 v8 v9 v10u1 u2 u3 u4 u5 u6 u7 u8 u9 u10

˙

is an

isomorphism between the two graphs G and H in F16.

Rubalcaba ([email protected]) Sample Final Questions 5 / 162

Page 6: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Graph modeling question

F19. Given these five websites and links between them, how would youmodel this as a graph or a directed graph?

vlsicad.ucsd.edu/courses/cse−s14/

webwork.cse.ucsd.edu/webwork2/CSE21_Spring2014 https://piazza.com/ucsd/spring2014/cse21/home

vlsicad.ucsd.edu/courses/cse−s14/

Links to websites:

webwork.cse.ucsd.edu/webwork2/CSE21_Spring2014

https://piazza.com/ucsd/spring2014/cse21/home

Links to websites:

www.soundcloud.com/ProfessorShadow

www.instagram.com/ProfessorShadow

www.soundcloud.com/ProfessorShadow

Links to websites:

www.soundcloud.com/ProfessorShadow

Links to websites:

webwork.cse.ucsd.edu/webwork2/CSE21_Spring2014

Links to websites:

Rubalcaba ([email protected]) Sample Final Questions 6 / 162

Page 7: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Minimum Spanning

Trees

F20. Using the greedy algorithm, find the minimum weight spanning tree.F21. What is the total weight of the minimum spanning tree?

189

2

18

1 11

10

12

5

8

13

17

A

72

6

B C D

E F G

H I J

Z4

3

2321

16

1415

Rubalcaba ([email protected]) Sample Final Questions 7 / 162

Page 8: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Traveling Salesman

Problem

F22. Using the sorted edges method, find the length of the tour goingthrough all six cities.

15

CB

A

EF

D

1

3

2

4

5

6

7

8

9

10

11

1213

14

Rubalcaba ([email protected]) Sample Final Questions 8 / 162

Page 9: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Traveling Salesman

Problem

F23. Using the nearest neighbor method, find the length of the tour goingthrough all six cities, starting and ending at A.

15

CB

A

EF

D

1

3

2

4

5

6

7

8

9

10

11

1213

14

Rubalcaba ([email protected]) Sample Final Questions 9 / 162

Page 10: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Permutations

F24. rp1, 2, 3, 4q ˝ p1, 2qp3, 5qs´1

F25. The cipher is given below in two line notation:ˆ

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

˙

Decrypt this message that was encrypted with the above cipher:S U R J U D P P L Q J L Q W K H E D V H P H Q W V W L Q N V

F26. What is the probability that a random permutation on five letters is aderangement?

Rubalcaba ([email protected]) Sample Final Questions 10 / 162

Page 11: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Random Graphs

For F27–F29: Let B be a random bipartite graph with independent sets ofsizes |X | “ 3 and |Y | “ 5. Each edge px , yq of B has probability 1

5 .

F27. Draw an example of a random bipartite graph with independent setsof sizes 3 and 5.

F28. What is the maximum number of edges in B?

F29. What is the probability that B has 5 edges?

F30. What is the expected number of edges of B?

Rubalcaba ([email protected]) Sample Final Questions 11 / 162

Page 12: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Basic Counting

F31. How many solutions using positive integers are there to the equationx1 ` x2 ` x3 ` x4 ` x5 “ 15?

F32. How many possible surjections are there from t1, 2, 3, 4u ÞÑ tA,Bu?

F33. How many possible injections are there from t1, 2, 3, 4u ÞÑ tA,Bu?

F34. How many possible injections are there from tA,Bu ÞÑ t1, 2, 3, 4u?

F35. N “ 210 “ 2 ˆ 3 ˆ 5 ˆ 7. How many ways can you write this as aproduct of non-negative integers? (Hint: The number 30 has five ways:

2 ˆ 3 ˆ 5 “ 2 ˆ 15 “ 6 ˆ 5 “ 3 ˆ 10 “ 30)

Rubalcaba ([email protected]) Sample Final Questions 12 / 162

Page 13: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Conditional Probability

and Independence

F36. PpAq “ 0.3,PpA Y Bq “ 0.7, and PpBqc “ 0.6. Are A and B

independent events?

F37. Among 60-year-old college professors, 10% are smokers and 90% arenonsmokers. The probability of a non-smoker dying in the next year is0.005 and the probability of a smoker dying is 0.05. Given that one60-year-old professor dies in the next year, what is the probability thatthe professor is a smoker?

F38. At a hospital’s emergency room, patients are classified and 20% arecritical, 30% are serious and 50% are stable. Of the critical patients,30% die; of the serious patients, 10% die; and of the stable patients,1% die.

§ (a) What is the probability that a patient who dies was classified ascritical?

§ (b) What is the probability that a critical patient dies?

Rubalcaba ([email protected]) Sample Final Questions 13 / 162

Page 14: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Conditional Probability

and Independence

F40. In Madison County, Alabama, a sample of 100 cases from 1960 areinvestigated, and the 100 defendants are interviewed as to their trueinnocence or guilt.

B1 Actually guilty B2 Actually innocent totals

A1 Jury finds guilty 35 45 80

A2 Jury finds not guilty 5 15 20

totals 40 60 100

§ (a) Assuming they answer honestly, what is the probability that adefendant who was actually innocent was found guilty by a jury?

§ (b) What is the probability that a defendant that was found guilty by ajury was actually innocent?

§ (c) Are the events A1 and B2 independent?

Rubalcaba ([email protected]) Sample Final Questions 14 / 162

Page 15: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Recursion, Big-O

F41. The determinant of a matrix can be calculated by expansion alongminors. The determinant detpMq of the n ˆ n square matrix M canbe recursively calculated as:detpMq “ m11 ¨ detpM11q ` ¨ ¨ ¨ ` p´1q1`j ¨ m1j ¨ detpM1jq ` ¨ ¨ ¨ whereM1j is the submatrix formed by eliminating the first row and jth

column of M. Give an expression for Rpnq, the asymptotic number ofmultiplications and additions used to calculate the determinant of ann ˆ n matrix using the above recursion.

F42.`

N2

˘

is Op?q

F43. !N (which counts the number of derangements on N letters) is Op?q

F44. Finding thee shortest tour through N cities (for the travelingsalesman problem) is Op?q

Rubalcaba ([email protected]) Sample Final Questions 15 / 162

Page 16: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Modeling and solving

real world problems

F45. Roadtrip! You just joined a band and you are on a tour of thefollowing six cities. Note that not all cities are connected by roads.Find the absolute shortest tour while visiting each city exactly once,starting and returning to San Diego.

6

9

2

3

8

5

7

San Diego

Los Angeles San Francisco

Phoenix

Fresno

Yuma

1

4

Rubalcaba ([email protected]) Sample Final Questions 16 / 162

Page 17: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Modeling and solving

real world problems

F46. Street sweeping in South Park. If the street sweeper starts at thecorner of Date and 28th Street, is it possible for the street sweeper toclean each side of the street and return to 28th and Date, withoutdiving down any side of the street more than once?

Rubalcaba ([email protected]) Sample Final Questions 17 / 162

Page 18: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Modeling and solving

real world problems

F47. Mail Delivery in South Park. If the mail carrier starts at the corner ofDate and 28th Street, is it possible for the mail carrier to deliver mailto each house and business and return to 28th and Date, withoutwalking down a any sidewalk more than once?

Rubalcaba ([email protected]) Sample Final Questions 18 / 162

Page 19: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Modeling and solving

real world problems

F48. Map coloring. Color the map of the following countries so that notwo countries that share a border get colored with the same color.Model this as a graph problem, solve the graph problem, then solvethe original map coloring question.

Rubalcaba ([email protected]) Sample Final Questions 19 / 162

Page 20: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Modeling and solving

real world problems

F49. High speed network. In a new housing development the internetservice provider needs to provide high speed access to each hometA,B ,C ,Du using the fewest underground cables. This networkneeds to be connected. Find the cheapest high speed network thatconnects all of the homes tA,B ,C ,Du, using the fewest undergroundcables given the following underground cable costs:

A B C D

A 70 10 3

B 70 7 5

C 10 7 2

D 3 5 2

Rubalcaba ([email protected]) Sample Final Questions 20 / 162

Page 21: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - How a computer might

see a graph

F50. Find a way of communicating this graph to a computer, which cannot see images, only lists or arrays (i.e. matrices).

Gv1v 3v

6v5v4v

2

Rubalcaba ([email protected]) Sample Final Questions 21 / 162

Page 22: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Graph Modeling

Problem

F51. You are in a band on tour, with shows at: San Diego, CA, Topeka,KS, Washington D.C., Seattle, WA and Auburn, AL. Using the milagebetween the cities, model this as a graph problem where you need tovisit each city exactly once, starting and returning to your home inAuburn, AL.

San Diego Auburn Seattle Washington D.C. TopekaSan Diego 0 2059 1255 2614 1492Auburn 2059 0 2631 748 860Seattle 1255 2631 0 2764 1818

Washington D.C. 2614 748 2764 0 1117Topeka 1492 860 1818 1117 0

Rubalcaba ([email protected]) Sample Final Questions 22 / 162

Page 23: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

Sample Final Questions for RRR - Solving the TSP vs

greedy approximations

F52. What is the length of the tour found by using the nearest neighbormethod, starting at Auburn, AL and visiting all four other cities andthen returning to Auburn, AL? (same problem as HW9, number 11a)

F53. What is the length of the tour found by using the sorted edgesmethod, starting at Auburn, AL and visiting all four other cities andthen returning to Auburn, AL? (same problem as HW9, number 11b)

F54. List all tours and calculate the cost for each tour. (Seepiazza post 678)

F55. What is the absolute shortest tour? What is the longest?

F56. Consider the problem: ”Is there a tour through all five cities that usesless than 7000 miles?” Is this problem in NP? Justify your answer.

Rubalcaba ([email protected]) Sample Final Questions 23 / 162

Page 24: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F1. Find the error in this false statement and correct it:

“Finding the chromatic number of a graph is

NP-complete.”

This question is not even in NP, it is not a YES/NO question and verifyingan answer could take avery long time. Suppose someone told you that thechromatic number of a graph with a thousand vertices and 250,000 edgeswas 49. How long would it take you to verify this claim? You would needto check that you could not color this huge graph with 48 colors, 47colors, 46 colors, etc.

The correct statement

Finding the chromatic number of a graph is NP-hard. Asking if a graphcan be colored with k colors is NP-complete (since a YES answer can beverified quickly, and this problem is reduced from 3-SAT which is also anNP-complete problem)

Rubalcaba ([email protected]) Sample Final Questions 24 / 162

Page 25: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F2. Find the error in this false statement and correct it:

“Solving the Traveling Salesman Problem NP-complete.”

This question is also not in NP, it is not a YES/NO question and verifyingan answer could take avery long time. To verify that a tour is theeshortest tour, you would need to check (N-1)!/2 tours.

The correct statement

Solving the Traveling Salesman Problem is NP-hard. Asking if there is atour with total cost less than a fixed value k is NP-complete (since a YESanswer can be verified quickly, and since you can reduce the decisionversion of TSP to the problem of Hamiltonian Cycle - an NP-completeproblem). If you can find a tour using less than cost k, you will have founda Hamiltonian cycle.

Rubalcaba ([email protected]) Sample Final Questions 25 / 162

Page 26: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F3. Is this problem “Is the number N=561 composite?” in

NP?

“Is the number N=561 composite?”

This problem is in NP. If someone tells you YES and presents you with561 “ 3 ˆ 11 ˆ 17, you can verify this very quickly. Finding thatfactorization may take some time, but verifying the YES answer is fast.

Do you believe my YES answer? Try verifying it yourself, just multiply 33times 17.

Rubalcaba ([email protected]) Sample Final Questions 26 / 162

Page 27: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F4. Count the number of proper 3-colorings of the graph

G :

G

v3v

2v

1v

4

There are 12 proper colorings of this graph.Three choices for v4, two choices for v3 once v4 is colored, two choice forv2 and only one choice for v1.

Rubalcaba ([email protected]) Sample Final Questions 27 / 162

Page 28: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F5. Count the number of proper 1,2,4-colorings of the

graph G :

G

v3v

2v

1v

4

There are 0 proper colorings that use at most 1 color.There are 0 proper colorings that use at most 2 colors.Solution 1: With at most four colors, there are 4 ¨ 3 ¨ 3 ¨ 2 “ 72 propercolorings.

§ 4 choices for v4§ 3 choices for v3§ 3 choices for v2§ 2 choices for v1

Solution 2: There are 24 ``

43

˘

¨ 12 “ 72 proper colorings that use atmost 4 colors: using all four colors, there are 4! “ 24 valid colorings(every assignment of four colors is a proper coloring); and for everychoice of three of the four colors, there are 12 valid 3-colorings.

Rubalcaba ([email protected]) Sample Final Questions 28 / 162

Page 29: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

6

v

2v

3v

4v

5v1

v

7v

8v

9v

10v

11v

12v

G

1

Rubalcaba ([email protected]) Sample Final Questions 29 / 162

Page 30: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

G

1

1

Rubalcaba ([email protected]) Sample Final Questions 30 / 162

Page 31: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

G

21

1

Rubalcaba ([email protected]) Sample Final Questions 31 / 162

Page 32: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

7v

2v

3v

4v

5v

6v

1 v

8v

9v

10v

11v

12v

G

1

1

2

2

Rubalcaba ([email protected]) Sample Final Questions 32 / 162

Page 33: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

7v

2v

3v

4v

5v

6v

1 v

8v

9v

10v

11v

12v

G

1

1

2

2

3

Rubalcaba ([email protected]) Sample Final Questions 33 / 162

Page 34: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

7v

2v

3v

4v

5v

6v

1 v

8v

9v

10v

11v

12v

G

1

1

2

2

3

3

Rubalcaba ([email protected]) Sample Final Questions 34 / 162

Page 35: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

G

41

1

2

2

3

3

Rubalcaba ([email protected]) Sample Final Questions 35 / 162

Page 36: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

G

4

1

1

2

2

3

3

4

Rubalcaba ([email protected]) Sample Final Questions 36 / 162

Page 37: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

G

51

1

2

2

3

3

4

4

Rubalcaba ([email protected]) Sample Final Questions 37 / 162

Page 38: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

G

5

1

1

2

2

3

3

4

4

5

Rubalcaba ([email protected]) Sample Final Questions 38 / 162

Page 39: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

G

61

1

2

2

3

3

4

4

5

5

Rubalcaba ([email protected]) Sample Final Questions 39 / 162

Page 40: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F6. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 will require all 6 colors.

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

G

6

1

1

2

2

3

3

4

4

5

5

6

Rubalcaba ([email protected]) Sample Final Questions 40 / 162

Page 41: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F7. Given this set of colors t1, 2, 3, 4, 5, 6u greedily color

the vertices of the graph using this orderingv1, v2, v3, v5, v7, v9, v11, v4, v6, v8, v10, v12 of the vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

Greedily coloring this graph with the orderingv1, v2, v3, v5, v7, v9, v11, v4, v6, v8, v10, v12 will require 3 colors.

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

G

3

1

1

2 2 2 2 2

3 3 3 3

Rubalcaba ([email protected]) Sample Final Questions 41 / 162

Page 42: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F8. Explain the difference between greedy coloring and the

chromatic number.

Finding the chromatic number is a hard problem (NP-hard and outside ofNP). Greedy coloring is fast but it only gives a bound on the chromaticnumber. In practice for really really large graphs, you can choose a feworderings, quickly greedily color, then obtain a decent bound on thechromatic number.

If you choose an ordering and greedily color with k colors, then χpG q ď k

Rubalcaba ([email protected]) Sample Final Questions 42 / 162

Page 43: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F9. Find the chromatic number of the complete

multipartite graph K2,3,3,7.

χpK2,3,3,7q “ 4

12

11

10

9

8 7

6

5

4

3

2

0114

13

Rubalcaba ([email protected]) Sample Final Questions 43 / 162

Page 44: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F10. Find the chromatic number of the Petersen Graph.

This proper 3-coloring shows χpPq ď 3. Since there is a five cycleχpPq ě 3.

χpPq ď 3 & χpPq ě 3 ñ χpPq “ 3

Rubalcaba ([email protected]) Sample Final Questions 44 / 162

Page 45: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F11. Find the chromatic number of the Grotzcsh Graph.

These two different 4-colorings each show χpG q ď 4. Since there is a fivecycle, which is an odd cycle, then χpG q ě 3.On the left start with coloring the five cycle, then copy that coloring to themiddle five vertices, you are forced to color the vertex in the center with anew color.On the right color the outside cycle first, then color the vertex in thecenter with one of your three colors, say blue. Then the remaining fivevertices must be a new color. No matter how hard you try there is noproper three coloring of this graph, four colors must be used.

χpG q “ 4

Rubalcaba ([email protected]) Sample Final Questions 45 / 162

Page 46: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F12. Find the chromatic number of a random tree on 10

vertices.

0

1

2

3

4

5

6

7

8

9

No matter which tree on 10 vertices you use, all trees (with at least oneedge) have chromatic number 2, since all trees are bipartite.

χpT10q “ 2

Rubalcaba ([email protected]) Sample Final Questions 46 / 162

Page 47: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F13. Find the chromatic number of a random tree on 10

vertices.

G

v

2v

3v

4v

5v

6v

7v

8v

9v

10v

11v

12v

1

This graph is bipartite, therefore χpG q “ 2

Rubalcaba ([email protected]) Sample Final Questions 47 / 162

Page 48: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F14. Are these two graphs isomorphic?

Hv

3v

2v

10v

4v

5v6v

7v

8v

9v

1u 2u

3u

4u

5u

6u7u

8u

9u

10u

G 1

NO, χpG q “ 3 and χpHq “ 2, therefore they are not isomorphic.You can also say that H is bipartite, but G has an odd cycle (the 9-cyclearound the outside v1, v2, ..., v9).

Rubalcaba ([email protected]) Sample Final Questions 48 / 162

Page 49: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Let’s first redraw the graph on the right.

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Rubalcaba ([email protected]) Sample Final Questions 49 / 162

Page 50: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Let’s first redraw the graph on the right.

u

v1v 3v

6v5v4v

1u3u

4u 6

2 HG

2u

5u

Rubalcaba ([email protected]) Sample Final Questions 50 / 162

Page 51: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Let’s first redraw the graph on the right.

uv1v 3v

6v5v4v4u 6u

3u12 H

G2u

5u

Rubalcaba ([email protected]) Sample Final Questions 51 / 162

Page 52: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Let’s first redraw the graph on the right.

u

v1v 3v

6v5v4v

1u

4u

3u

6

2 HG

2u

5u

Rubalcaba ([email protected]) Sample Final Questions 52 / 162

Page 53: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Let’s first redraw the graph on the right.

u

v1v 3v

6v5v4v

1u

4u 6u

3

2 HG

2u

5u

Rubalcaba ([email protected]) Sample Final Questions 53 / 162

Page 54: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Let’s first redraw the graph on the right.

u

v1v 3v

6v5v4v

1u

4u 6u3

2 HG

2u

5u

Rubalcaba ([email protected]) Sample Final Questions 54 / 162

Page 55: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Let’s first redraw the graph on the right.

u

v1v 3v

6v5v4v

1u4u 6u3

2 HG

2u

5u

Rubalcaba ([email protected]) Sample Final Questions 55 / 162

Page 56: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

u

v1v 3v

6v5v4v

3u

4u 5u 6

2 HG

1u 2u

Let’s first redraw the graph on the right.

uv1v 3v

6v5v4v

4u

1u 3u

62 HG

2u

5u

Rubalcaba ([email protected]) Sample Final Questions 56 / 162

Page 57: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

4

v1v 3v

6v5v

2

v

u

1u 3u

6uHG

2u

5u

4

There are two symmetries...

Rubalcaba ([email protected]) Sample Final Questions 57 / 162

Page 58: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

4

v1v 3v

6v5v

2

v

u

1u 3u

6uHG

2u

5u

4

There are two symmetries...

Rubalcaba ([email protected]) Sample Final Questions 58 / 162

Page 59: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F15. In two line notation, list all isomorphisms from G to

H

uv1v 3v

6v5v4v

4u

1u 3u

62 HG

2u

5u

Do one, both or neither of the symmetries - this gives you fourisomorphisms.ˆ

v1 v2 v3 v4 v5 v6u4 u2 u6 u1 u5 u3

˙ ˆ

v1 v2 v3 v4 v5 v6u1 u5 u3 u4 u2 u6

˙

ˆ

v1 v2 v3 v4 v5 v6u6 u2 u4 u3 u5 u1

˙ ˆ

v1 v2 v3 v4 v5 v6u3 u5 u1 u6 u2 u4

˙

Rubalcaba ([email protected]) Sample Final Questions 59 / 162

Page 60: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F16. Are these two graphs isomorphic?

Hv

3v

2v

10v

4v

5v6v

7v

8v

9v

10u

1u

4u7u

3u

2u

8u

9u

5u 6u

G 1

YES, here is an isomorphism (verified in F18.)ˆ

v1 v2 v3 v4 v5 v6 v7 v8 v9 v10u1 u2 u3 u4 u5 u6 u7 u8 u9 u10

˙

Rubalcaba ([email protected]) Sample Final Questions 60 / 162

Page 61: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F17. Explain why the YES / NO question is in NP:

“Are the two graphs G and H isomorphic?”

Look at the example of F16.

Hv

3v

2v

10v

4v

5v6v

7v

8v

9v

10u

1u

4u7u

3u

2u

8u

9u

5u 6u

G 1

Here is a YES answer, a bijection which takes edges to edges andnon-edges to non-edges - which can be verified to do so in polynomial

time:

ˆ

v1 v2 v3 v4 v5 v6 v7 v8 v9 v10u1 u2 u3 u4 u5 u6 u7 u8 u9 u10

˙

Since a YES answer can be verified fast, this problem is in NP

Rubalcaba ([email protected]) Sample Final Questions 61 / 162

Page 62: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F18. Verify that this is an isomorphism between G and H .

φ “

ˆ

v1 v2 v3 v4 v5 v6 v7 v8 v9 v10u1 u2 u3 u4 u5 u6 u7 u8 u9 u10

˙

Hv

3v

2v

10v

4v

5v6v

7v

8v

9v

10u

1u

4u7u

3u

2u

8u

9u

5u 6u

G 1

All 15 edges in G go to edges in H and all non-edges in G go to non-edgesin H. For example, pv1, v2q is an edge in G and pφpv1q, φpv2qq “ pu1, u2q isan edge in H

Rubalcaba ([email protected]) Sample Final Questions 62 / 162

Page 63: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F19. Given these five websites and links between them,

how would you model this as a graph or a directed graph?

Links to websites:

webwork.cse.ucsd.edu/webwork2/CSE21_Spring2014

Links to websites:

vlsicad.ucsd.edu/courses/cse−s14/

webwork.cse.ucsd.edu/webwork2/CSE21_Spring2014 https://piazza.com/ucsd/spring2014/cse21/home

vlsicad.ucsd.edu/courses/cse−s14/

Links to websites:

webwork.cse.ucsd.edu/webwork2/CSE21_Spring2014

https://piazza.com/ucsd/spring2014/cse21/home

Links to websites:

www.soundcloud.com/ProfessorShadow

www.instagram.com/ProfessorShadow

www.soundcloud.com/ProfessorShadow

Links to websites:

www.soundcloud.com/ProfessorShadow

Rubalcaba ([email protected]) Sample Final Questions 63 / 162

Page 64: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F20. Using the greedy algorithm, find the minimum weight

spanning tree.

E

F GD G

122345

G Z 6B F 7

8E H9A H

D Z 1011E F12J Z13A B14F I15F H1617

I JF J

18G J18B

A

72

6

B C D

E F G

H I J

Z4

3

2321

16

1415

9

2

18

1 11

10

12

5

8

13

17 18

A EH IC FC G

Rubalcaba ([email protected]) Sample Final Questions 64 / 162

Page 65: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F21. What is the total weight of the minimum spanning

tree?

E

F GD G

122345

G Z 6B F 7

8E H9A H

D Z 1011E F12J Z13A B14F I15F H1617

I JF J

18G J18B

A

72

6

B C D

E F G

H I J

Z4

3

2321

16

1415

9

2

18

1 11

10

12

5

8

13

17 18

A EH IC FC G

1 ` 2 ` 2 ` 3 ` 5 ` 6 ` 7 ` 8 ` 11 ` 12 “ 57

Rubalcaba ([email protected]) Sample Final Questions 65 / 162

Page 66: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F22. Using the sorted edges method, find the length of the

tour going through all six cities.

D

C 4B C 5E F 6A E 7B D 8

9E D 10D F 11

12BFA B 13

14A FC D 15

A

1

3

2

4

5

6

7

8

9

10

11

1213

14

CB

A

EF

D

15

EB 1C F 2C E 3A

1 ` 2 ` 3 ` 8 ` 9 ` 14 “ 37

Rubalcaba ([email protected]) Sample Final Questions 66 / 162

Page 67: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F23. Using the nearest neighbor method, find the length of

the tour going through all six cities.

15

14

CB

A

EF

D

1

3

2

4

5

6

7

8

9

10

11

1213

4 ` ...

Rubalcaba ([email protected]) Sample Final Questions 67 / 162

Page 68: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F23. Using the nearest neighbor method, find the length of

the tour going through all six cities.

1513

14

CB

A

EF

D

1

3

2

4

5

6

7

8

9

10

11

12

4 ` 2 ` ...

Rubalcaba ([email protected]) Sample Final Questions 68 / 162

Page 69: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F23. Using the nearest neighbor method, find the length of

the tour going through all six cities.

151213

14

CB

A

EF

D

1

3

2

4

5

6

7

8

9

10

11

4 ` 2 ` 6 ` ...

Rubalcaba ([email protected]) Sample Final Questions 69 / 162

Page 70: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F23. Using the nearest neighbor method, find the length of

the tour going through all six cities.

15

11

1213

14

CB

A

EF

D

1

3

2

4

5

6

7

8

9

10

4 ` 2 ` 6 ` 1...

Rubalcaba ([email protected]) Sample Final Questions 70 / 162

Page 71: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F23. Using the nearest neighbor method, find the length of

the tour going through all six cities.

15

10

11

1213

14

CB

A

EF

D

1

3

2

4

5

6

7

8

9

4 ` 2 ` 6 ` 1 ` 8 ` ...

Rubalcaba ([email protected]) Sample Final Questions 71 / 162

Page 72: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F23. Using the nearest neighbor method, find the length of

the tour going through all six cities.

15

9

10

11

1213

14

CB

A

EF

D

1

3

2

4

5

6

7

8

4 ` 2 ` 6 ` 1 ` 8 ` 9

Rubalcaba ([email protected]) Sample Final Questions 72 / 162

Page 73: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F24. rp1, 2, 3, 4q ˝ p1, 2qp3, 5qs´1

Let f “ p1, 2, 3, 4q, g “ p1, 2qp3, 5q. First we computef ˝ g “ p1, 2, 3, 4q ˝ p1, 2qp3, 5q (remember apply the map g first)

3 Ðf 2 Ðg 1

2 Ðf 1 Ðg 2

5 Ðf 5 Ðg 3

1 Ðf 4 Ðg 4

4 Ðf 3 Ðg 5

3 Ðf ˝g 1

2 Ðf ˝g 2

5 Ðf ˝g 3

1 Ðf ˝g 4

4 Ðf ˝g 5

In cycle notation this is p1, 3, 5, 4q, it’s inverse isp1, 3, 5, 4q´1 “ p4, 5, 3, 1q “ p1, 4, 5, 3q

Rubalcaba ([email protected]) Sample Final Questions 73 / 162

Page 74: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F25. Decrypt this message that was encrypted with the

cipher:

ˆ

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

˙

Decrypt this message that was encrypted with the above cipher:S U R J U D P P L Q J L Q W K H E D V H P H Q W V W L Q N V

P

Rubalcaba ([email protected]) Sample Final Questions 74 / 162

Page 75: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F25. Decrypt this message that was encrypted with the

cipher:

ˆ

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

˙

Decrypt this message that was encrypted with the above cipher:S U R J U D P P L Q J L Q W K H E D V H P H Q W V W L Q N V

P R

Rubalcaba ([email protected]) Sample Final Questions 75 / 162

Page 76: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F25. Decrypt this message that was encrypted with the

cipher:

ˆ

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

˙

Decrypt this message that was encrypted with the above cipher:S U R J U D P P L Q J L Q W K H E D V H P H Q W V W L Q N V

P R O

Rubalcaba ([email protected]) Sample Final Questions 76 / 162

Page 77: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F25. Decrypt this message that was encrypted with the

cipher:

ˆ

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

˙

Decrypt this message that was encrypted with the above cipher:S U R J U D P P L Q J L Q W K H E D V H P H Q W V W L Q N V

P R O G R A M M I N G I N T H E B A S E M E N T S T I N K S

Rubalcaba ([email protected]) Sample Final Questions 77 / 162

Page 78: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F26. What is the probability that a random permutation

on five letters is a derangement?

The function !N counts the number of derangements on N letters. Youcan compute !5 using the recursive formula (where !0 “ 1 and !1 “ 0).

!N “ pN ´ 1qp!pN ´ 1q`!pN ´ 2qq

!5 “ p5 ´ 1qp!p5 ´ 1q`!p5 ´ 2qq “ 4p!4`!3q

!4 “ p4 ´ 1qp!p4 ´ 1q`!p4 ´ 2qq “ 3p!3`!2q

!3 “ p3 ´ 1qp!p3 ´ 1q`!p3 ´ 2qq “ 2p!2`!1q

!2 “ p2 ´ 1qp!p2 ´ 1q`!p2 ´ 2qq “ 1p!1`!0q

Rubalcaba ([email protected]) Sample Final Questions 78 / 162

Page 79: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F26. What is the probability that a random permutation

on five letters is a derangement?

The function !N counts the number of derangements on N letters. Youcan compute !5 using the recursive formula (where !0 “ 1 and !1 “ 0).

!N “ pN ´ 1qp!pN ´ 1q`!pN ´ 2qq

!5 “ p5 ´ 1qp!p5 ´ 1q`!p5 ´ 2qq “ 4p!4`!3q “

!4 “ p4 ´ 1qp!p4 ´ 1q`!p4 ´ 2qq “ 3p!3 ` !2q “ 3p!3 ` 1q “

!3 “ p3 ´ 1qp!p3 ´ 1q`!p3 ´ 2qq “ 2p!2`!1q “ 2p1 ` 0q “ 2

!2 “ p2 ´ 1qp!p2 ´ 1q`!p2 ´ 2qq “ 1p!1`!0q “ 1p0 ` 1q “ 1

Rubalcaba ([email protected]) Sample Final Questions 79 / 162

Page 80: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F26. What is the probability that a random permutation

on five letters is a derangement?

The function !N counts the number of derangements on N letters. Youcan compute !5 using the recursive formula (where !0 “ 1 and !1 “ 0).

!N “ pN ´ 1qp!pN ´ 1q`!pN ´ 2qq

!5 “ p5 ´ 1qp!p5 ´ 1q`!p5 ´ 2qq “ 4p!4 ` !3q “ 4p!4 ` 2q “

!4 “ p4 ´ 1qp!p4 ´ 1q`!p4 ´ 2qq “ 3p!3`!2q “ 3p2 ` 1q “

!3 “ p3 ´ 1qp!p3 ´ 1q`!p3 ´ 2qq “ 2p!2`!1q “ 2p1 ` 0q “ 2

!2 “ p2 ´ 1qp!p2 ´ 1q`!p2 ´ 2qq “ 1p!1`!0q “ 1p0 ` 1q “ 1

Rubalcaba ([email protected]) Sample Final Questions 80 / 162

Page 81: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F26. What is the probability that a random permutation

on five letters is a derangement?

The function !N counts the number of derangements on N letters. Youcan compute !5 using the recursive formula (where !0 “ 1 and !1 “ 0).

!N “ pN ´ 1qp!pN ´ 1q`!pN ´ 2qq

!5 “ p5 ´ 1qp!p5 ´ 1q`!p5 ´ 2qq “ 4p!4`!3q “ 4p!4 ` 2q “ 4p9 ` 2q “ 44

!4 “ p4 ´ 1qp!p4 ´ 1q`!p4 ´ 2qq “ 3p!3`!2q “ 3p2 ` 1q “ 9

!3 “ p3 ´ 1qp!p3 ´ 1q`!p3 ´ 2qq “ 2p!2`!1q “ 2p1 ` 0q “ 2

!2 “ p2 ´ 1qp!p2 ´ 1q`!p2 ´ 2qq “ 1p!1`!0q “ 1p0 ` 1q “ 1

Rubalcaba ([email protected]) Sample Final Questions 81 / 162

Page 82: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F26. What is the probability that a random permutation

on five letters is a derangement?

The function !N counts the number of derangements on N letters. Youcan compute !5 using the recursive formula (where !0 “ 1 and !1 “ 0).

!N “ pN ´ 1qp!pN ´ 1q`!pN ´ 2qq

!5 “ p5 ´ 1qp!p5 ´ 1q`!p5 ´ 2qq “ 4p!4`!3q “ 4p9 ` 2q “ 44

!4 “ p4 ´ 1qp!p4 ´ 1q`!p4 ´ 2qq “ 3p!3`!2q “ 3p2 ` 1q “ 9

!3 “ p3 ´ 1qp!p3 ´ 1q`!p3 ´ 2qq “ 2p!2`!1q “ 2p1 ` 0q “ 2

!2 “ p2 ´ 1qp!p2 ´ 1q`!p2 ´ 2qq “ 1p!1`!0q “ 1p0 ` 1q “ 1

There are 5! permutations on five letters, so the probability that a randompermutation on five letters is a derangement is

!5

5!“

44

120« 0.3667

Rubalcaba ([email protected]) Sample Final Questions 82 / 162

Page 83: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F27. Draw an example of a random bipartite graph with

independent sets of sizes 3 and 5.

Let B be a random bipartite graph with independent sets of sizes |X | “ 3and |Y | “ 5. Each edge px , yq of B has probability 1

5 .

1/5

X Y

Each edge has probability 1/5 of appearing.Rubalcaba ([email protected]) Sample Final Questions 83 / 162

Page 84: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F27. Draw an example of a random bipartite graph with

independent sets of sizes 3 and 5.

Let B be a random bipartite graph with independent sets of sizes |X | “ 3and |Y | “ 5. Each edge px , yq of B has probability 1

5 .

YX

Rubalcaba ([email protected]) Sample Final Questions 84 / 162

Page 85: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F27. Draw an example of a random bipartite graph with

independent sets of sizes 3 and 5.

Let B be a random bipartite graph with independent sets of sizes |X | “ 3and |Y | “ 5. Each edge px , yq of B has probability 1

5 .

X Y

Rubalcaba ([email protected]) Sample Final Questions 85 / 162

Page 86: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F28. What is the maximum number of edges in B?

Let B be a random bipartite graph with independent sets of sizes |X | “ 3and |Y | “ 5. Each edge px , yq of B has probability 1

5 .

X Y

The maximum number of edges for a bipartite graph with independentsets of sizes |X | and |Y | is |X | ¨ |Y | “ 3 ¨ 5 “ 15

Rubalcaba ([email protected]) Sample Final Questions 86 / 162

Page 87: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F29. What is the probability that B has 5 edges?

Let B be a random bipartite graph with independent sets of sizes |X | “ 3and |Y | “ 5. Each edge px , yq of B has probability 1

5 .

1/5

X Y

ˆ

15

5

˙ ˆ

1

5

˙5 ˆ

4

5

˙p15´5q

« 0.1032

Rubalcaba ([email protected]) Sample Final Questions 87 / 162

Page 88: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F30. What is the expected number of edges of B?

Let B be a random bipartite graph with independent sets of sizes |X | “ 3and |Y | “ 5. Each edge px , yq of B has probability 1

5 .

Edges are formed by independent coin tosses which are binomialdistrubuted (with n=15 and p=0.2), so the expected value (where X isthe random variable # of edges).

E pX q “ 15 ¨ 15 “ 3

You can also use linearity of expectation.

Rubalcaba ([email protected]) Sample Final Questions 88 / 162

Page 89: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F31. How many solutions using positive integers are there

to the equation x1 ` x2 ` x3 ` x4 ` x5 “ 15?

This is a stars and bars problem, with 15 stars and four bars, but witheach variable starting with 1 star.x1 x2 x3 x4 x5‹ ‹ ‹ ‹ ‹

Now we have 10 stars left: here is one possible

solutionx1 x2 x3 x4 x5

‹ ‹ ‹‹ ‹ ‹ ‹ ‹‹ ‹corresponding to the original

problem:x1 x2 x3 x4 x5

‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹‹ ‹ ‹ ‹ ‹‹ ‹

So we have 10 stars and 5-1= 4 bars, this is C p10 ` 4, 4q or

ˆ

stars + bars

bars

˙

ˆ

10 ` 4

4

˙

ˆ

14

4

˙

“ 1001

Rubalcaba ([email protected]) Sample Final Questions 89 / 162

Page 90: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F32. How many possible surjections are there from

t1, 2, 3, 4u ÞÑ tA,Bu?

One solution is using Sterling numbers of the second kind.

Sp4, 2q ¨ 2! “ 7 ¨ 2 “ 14.

For this example you can also easily count the number of functions thatare not onto. For a function with codomain of size two to not be onto, allof the elements must be sent to A or B (the image should have only oneelement). There are only two such functions, either everything is sent to A

or everything is sent to B . There are 24 possible functions, so

24 ´ 2 “ 14 are surjective.

Rubalcaba ([email protected]) Sample Final Questions 90 / 162

Page 91: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F33. How many possible injections are there from

t1, 2, 3, 4u ÞÑ tA,Bu?

Four things can not be mapped to two without one of A or B being hitmore than once.

0

Rubalcaba ([email protected]) Sample Final Questions 91 / 162

Page 92: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F34. How many possible injections are there from

tA,Bu ÞÑ t1, 2, 3, 4u?

There are 4 choices of where to send A and 3 choices where to send B .

Pp4, 2q “ 4 ¨ 3 “ 12

Rubalcaba ([email protected]) Sample Final Questions 92 / 162

Page 93: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F35. N “ 210 “ 2 ˆ 3 ˆ 5 ˆ 7. How many ways can you

write this as a product of non-negative integers?

(Hint: The number 30 has five ways: 2 ˆ 3 ˆ 5 “ 2 ˆ 15 “ 6 ˆ 5 “ 3 ˆ 10 “ 30)

The four factors can be partitioned in how many ways?

N “ 210 “ 2 ˆ 3 ˆ 5 ˆ 7 “ p2 ˆ 3q ˆ 5 ˆ 7 “ ...

The number of partitions of a set of four elements is the Bell numberBp4q “ Sp4, 1q ` Sp4, 2q ` Sp4, 3q ` Sp4, 4q “ 15.

Rubalcaba ([email protected]) Sample Final Questions 93 / 162

Page 94: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F36. PpAq “ 0.3,PpA Y Bq “ 0.7, and PpBqc “ 0.6. Are

A and B independent events?

Let’s see if PpA X Bq “ PpAqPpBq.

PpA X Bq “ PpAq ` PpBq ´ PpA Y Bq

PpA X Bq “ 0.3 ` p1 ´ 0.6q ´ 0.7

PpA X Bq “ 0.3 ` 0.4 ´ 0.7 “ 0

No. A and B are not independent events.

Rubalcaba ([email protected]) Sample Final Questions 94 / 162

Page 95: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F37.

Rubalcaba ([email protected]) Sample Final Questions 95 / 162

Page 96: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F38.

Rubalcaba ([email protected]) Sample Final Questions 96 / 162

Page 97: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F40. “Is it just me or is there no F39?”

Rubalcaba ([email protected]) Sample Final Questions 97 / 162

Page 98: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F41. Blah blah blah, Matrix determinants, blah blah blah,

Recursion!

Rpnq “ n ` n ´ 1 ` n ¨ Rpn ´ 1q = n ¨ Rpn ´ 1q ` 2n ´ 1, with Rp1q “ 0

Rpnq “ Opn!q

Rubalcaba ([email protected]) Sample Final Questions 98 / 162

Page 99: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F42.`

N2

˘

is Op?q

ˆ

N

2

˙

“NpN ´ 1q

2“

1

2N2 ´

1

2N

ˆ

N

2

˙

“ OpN2q

Rubalcaba ([email protected]) Sample Final Questions 99 / 162

Page 100: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F43. !N (which counts the number of derangements on N

letters) is Op?q

You can compute !N using the recursive formula (where !0 “ 1 and!1 “ 0).

!N “ pN ´ 1qp!pN ´ 1q`!pN ´ 2qq

!N “ OpN!qRubalcaba ([email protected]) Sample Final Questions 100 / 162

Page 101: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F44. Finding thee shortest tour through N cities (for the

traveling salesman problem) is Op?q

To find thee shortest tour of N cities, you would need to check allpN ´ 1q!{2 tours. For the homework problem you had with just 5 cities,this would be 12 tours to check, see the piazza post 678 for an example offinding thee shortest tour. (Solution forthcoming, but work on it now).This is OpN!q

Rubalcaba ([email protected]) Sample Final Questions 101 / 162

Page 102: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F45. Roadtrip! You just joined a band and you are on a

tour of the following six cities.

Note that not all cities are connected by roads. Find the absolute shortesttour while visiting each city exactly once, starting and returning to SanDiego.

2San Diego

Los Angeles San Francisco

Phoenix

Fresno

Yuma

1

9

4

6

7

5

8

3

What happens if we add the edge Los Angeles to Yuma (take the roadfrom LA to Yuma).

Rubalcaba ([email protected]) Sample Final Questions 102 / 162

Page 103: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F45. Roadtrip! You just joined a band and you are on a

tour of the following six cities.

If we add the edge Los Angeles to Yuma, how do we get to San Francisco?Remember the answer will be a cycle on six vertices.

3

2

6

San Diego

Los Angeles San Francisco

Phoenix

Fresno

1

Yuma

4

9

7

5

8

Rubalcaba ([email protected]) Sample Final Questions 103 / 162

Page 104: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F45. Roadtrip! You just joined a band and you are on a

tour of the following six cities.

Since our answer will be a cycle on six vertices, let’s look at how manycycles on six vertices there are. Note all of them must use these threeedges:

2San Diego

Los Angeles San Francisco

Phoenix

Fresno

Yuma

1

9

4

6

7

5

8

3

Rubalcaba ([email protected]) Sample Final Questions 104 / 162

Page 105: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F45. Roadtrip! You just joined a band and you are on a

tour of the following six cities.

Since our answer will be a cycle on six vertices, let’s look at how manycycles on six vertices there are:

2San Diego

Los Angeles San Francisco

Phoenix

Fresno

Yuma

1

9

4

6

7

5

8

3

Rubalcaba ([email protected]) Sample Final Questions 105 / 162

Page 106: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F45. Roadtrip! You just joined a band and you are on a

tour of the following six cities.

Since our answer will be a cycle on six vertices, let’s look at how manycycles on six vertices there are:

2San Diego

Los Angeles San Francisco

Phoenix

Fresno

Yuma

1

9

4

6

7

5

8

3

Rubalcaba ([email protected]) Sample Final Questions 106 / 162

Page 107: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F45. Roadtrip! You just joined a band and you are on a

tour of the following six cities.

This tour costs 9 ` 2 ` 4 ` 5 ` 7 ` 8 “ 35

2San Diego

Los Angeles San Francisco

Phoenix

Fresno

Yuma

1

9

4

6

7

5

8

3

Rubalcaba ([email protected]) Sample Final Questions 107 / 162

Page 108: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F45. Roadtrip! You just joined a band and you are on a

tour of the following six cities.

This tour costs 3 ` 4 ` 5 ` 7 ` 6 ` 9 “ 34

2San Diego

Los Angeles San Francisco

Phoenix

Fresno

Yuma

1

9

4

6

7

5

8

3

Rubalcaba ([email protected]) Sample Final Questions 108 / 162

Page 109: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F45. Roadtrip! You just joined a band and you are on a

tour of the following six cities.

This tour costs 3 ` 4 ` 5 ` 7 ` 6 ` 9 “ 34

2San Diego

Los Angeles San Francisco

Phoenix

Fresno

Yuma

1

9

4

6

7

5

8

3

which is cheaper than the other tour, so San Diego to Los Angeles to SanFrancisco to Fresno to Yuma to Phoenix back to San Diego is the shortest

tour through all six cities (note that the reverse tour has the same cost)!Rubalcaba ([email protected]) Sample Final Questions 108 / 162

Page 110: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Rubalcaba ([email protected]) Sample Final Questions 109 / 162

Page 111: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Go east on Date St,

Rubalcaba ([email protected]) Sample Final Questions 110 / 162

Page 112: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Go east on Date St, then turn right on Granada Ave,

Rubalcaba ([email protected]) Sample Final Questions 111 / 162

Page 113: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Go east on Date St, then turn right on Granada Ave, make a U turn,

Rubalcaba ([email protected]) Sample Final Questions 112 / 162

Page 114: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Go east on Date St, then turn right on Granada Ave, make a U turn, turnright on Date St.

Rubalcaba ([email protected]) Sample Final Questions 113 / 162

Page 115: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Then turn right on 29th Street,

Rubalcaba ([email protected]) Sample Final Questions 114 / 162

Page 116: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Make a U turn,

Rubalcaba ([email protected]) Sample Final Questions 115 / 162

Page 117: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Turn Right on Date St.

Rubalcaba ([email protected]) Sample Final Questions 116 / 162

Page 118: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Turn Right on Dale Street (not labeled on this map)

Rubalcaba ([email protected]) Sample Final Questions 117 / 162

Page 119: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Make a U turn

Rubalcaba ([email protected]) Sample Final Questions 118 / 162

Page 120: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Right on Date St

Rubalcaba ([email protected]) Sample Final Questions 119 / 162

Page 121: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

turn Right on 30th Street

Rubalcaba ([email protected]) Sample Final Questions 120 / 162

Page 122: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Make a U turn,

Rubalcaba ([email protected]) Sample Final Questions 121 / 162

Page 123: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Turn right on Dale, turn right on Fern, turn right on Ash St.

Rubalcaba ([email protected]) Sample Final Questions 122 / 162

Page 124: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Turn right on 28th St.

Rubalcaba ([email protected]) Sample Final Questions 123 / 162

Page 125: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Turn right on Beech Street

Rubalcaba ([email protected]) Sample Final Questions 124 / 162

Page 126: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Make a U turn,

Rubalcaba ([email protected]) Sample Final Questions 125 / 162

Page 127: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park.

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Turn right on 28th St, turn right on Cedar St,

Rubalcaba ([email protected]) Sample Final Questions 126 / 162

Page 128: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F46. Street Sweeping in South Park. - Euler Tour

If the street sweeper starts at the corner of Date and 28th Street, is itpossible for the street sweeper to clean each side of the street and returnto 28th and Date, without diving down any side of the street more thanonce?

Make a U turn, turn right on 28th St, stop when you reach the corner ofDate where you started.

Rubalcaba ([email protected]) Sample Final Questions 127 / 162

Page 129: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F47. Mail Delivery in South Park. - Euler Tour

If the mail carrier starts at the corner of Date and 28th Street, is it possiblefor the mail carrier to deliver mail to each house and business and returnto 28th and Date, without walking down a any sidewalk more than once?

The same solution (Euler tour) for the directed graph works for thisundirected graph.

Rubalcaba ([email protected]) Sample Final Questions 128 / 162

Page 130: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F48. Map coloring. - Proper Coloring (with χpG q colors)

Color the map of the following countries so that no two countries thatshare a border get colored with the same color. Model this as a graphproblem, solve the graph problem, then solve the original map coloringquestion.

Venezuela

Argentina

Uruguay

Brazil

French Guiana

Suriname

GuyanaColumbia

Equador

Peru

Chile

Paraguay

Bolivia

Rubalcaba ([email protected]) Sample Final Questions 129 / 162

Page 131: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F48. Map coloring. - Proper Coloring (with χpG q colors)

Color the map of the following countries so that no two countries thatshare a border get colored with the same color. Model this as a graphproblem, solve the graph problem, then solve the original map coloringquestion. There is a complete graph on four vertices All countires mustget a different color.

Uruguay

French Guiana

Suriname

GuyanaVenezuela

Columbia

Equador

Peru

Chile

Argentina

Paraguay

BoliviaBrazil

Rubalcaba ([email protected]) Sample Final Questions 130 / 162

Page 132: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F48. Map coloring.- Proper Coloring (with χpG q colors)

Color the map of the following countries so that no two countries thatshare a border get colored with the same color. Model this as a graphproblem, solve the graph problem, then solve the original map coloringquestion.

Bolivia

Argentina

Uruguay

Brazil

French Guiana

Suriname

GuyanaVenezuela

Columbia

Equador

Peru

Chile

Paraguay

Rubalcaba ([email protected]) Sample Final Questions 131 / 162

Page 133: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F48. Map coloring. - Proper Coloring (with χpG q colors)

Color the map of the following countries so that no two countries thatshare a border get colored with the same color. Model this as a graphproblem, solve the graph problem, then solve the original map coloringquestion.

Bolivia

Argentina

Uruguay

Brazil

French Guiana

Suriname

GuyanaVenezuela

Columbia

Equador

Peru

Chile

Paraguay

Rubalcaba ([email protected]) Sample Final Questions 132 / 162

Page 134: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F48. Map coloring. - Proper Coloring (with χpG q colors)

Color the map of the following countries so that no two countries thatshare a border get colored with the same color. Model this as a graphproblem, solve the graph problem, then solve the original map coloringquestion.

Bolivia

Argentina

Uruguay

Brazil

French Guiana

Suriname

GuyanaVenezuela

Columbia

Equador

Peru

Chile

Paraguay

Rubalcaba ([email protected]) Sample Final Questions 133 / 162

Page 135: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F48. Map coloring. - Proper Coloring (with χpG q colors)

Color the map of the following countries so that no two countries thatshare a border get colored with the same color. Model this as a graphproblem, solve the graph problem, then solve the original map coloringquestion.

Bolivia

Argentina

Uruguay

Brazil

French Guiana

Suriname

GuyanaVenezuela

Columbia

Equador

Peru

Chile

Paraguay

Rubalcaba ([email protected]) Sample Final Questions 134 / 162

Page 136: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F48. Map coloring - Proper Coloring (with χpG q colors)

Color the map of the following countries so that no two countries thatshare a border get colored with the same color. Model this as a graphproblem, solve the graph problem, then solve the original map coloringquestion.

Bolivia

Argentina

Uruguay

Brazil

French Guiana

Suriname

GuyanaVenezuela

Columbia

Equador

Peru

Chile

Paraguay

Rubalcaba ([email protected]) Sample Final Questions 135 / 162

Page 137: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F49. High speed network. - Minimum Spanning Tree

In a new housing development the internet service provider needs toprovide high speed access to each home tA,B ,C ,Du using the fewestunderground cables. This network needs to be connected. Find thecheapest high speed network that connects all of the homes tA,B ,C ,Du,using the fewest underground cables given the following underground cablecosts:

A B C DA 70 10 3B 70 7 5C 10 7 2D 3 5 2

5

70

3 7

2

B

CD

A

10

Rubalcaba ([email protected]) Sample Final Questions 136 / 162

Page 138: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F49. High speed network - Minimum Spanning Tree

In a new housing development the internet service provider needs toprovide high speed access to each home tA,B ,C ,Du using the fewestunderground cables. This network needs to be connected. Find thecheapest high speed network that connects all of the homes tA,B ,C ,Du,using the fewest underground cables given the following underground cablecosts:

A B C DA 70 10 3B 70 7 5C 10 7 2D 3 5 2

5

70

3 7

2

B

CD

A

10

Rubalcaba ([email protected]) Sample Final Questions 137 / 162

Page 139: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F49. High speed network - Minimum Spanning Tree

In a new housing development the internet service provider needs toprovide high speed access to each home tA,B ,C ,Du using the fewestunderground cables. This network needs to be connected. Find thecheapest high speed network that connects all of the homes tA,B ,C ,Du,using the fewest underground cables given the following underground cablecosts:

A B C DA 70 10 3B 70 7 5C 10 7 2D 3 5 2

5

A

10

70

3 7

2

B

CD

Rubalcaba ([email protected]) Sample Final Questions 138 / 162

Page 140: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F49. High speed network - Minimum Spanning Tree

In a new housing development the internet service provider needs toprovide high speed access to each home tA,B ,C ,Du using the fewestunderground cables. This network needs to be connected. Find thecheapest high speed network that connects all of the homes tA,B ,C ,Du,using the fewest underground cables given the following underground cablecosts:

A B C DA 70 10 3B 70 7 5C 10 7 2D 3 5 2

5

D

A

10

70

3 7

2

B

C

Rubalcaba ([email protected]) Sample Final Questions 139 / 162

Page 141: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F50. Find a way of communicating this graph to a

computer

v1v 3v

6v5v4v

2v

4v

1v

5v

6v

3v

1v 2v 3v 4v 5v 6v2G

1

1

Rubalcaba ([email protected]) Sample Final Questions 140 / 162

Page 142: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F50. Find a way of communicating this graph to a

computer

1

v1v 3v

6v5v4v

2v

4v

1v

5v

6v

3v

1v 2v 3v 4v 5v 6vG

1

1

1

2

Rubalcaba ([email protected]) Sample Final Questions 141 / 162

Page 143: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F50. Find a way of communicating this graph to a

computer

1

v1v 3v

6v5v4v

2v

4v

1v

5v

6v

3v

1v 2v 3v 4v 5v 6v

1

1

1

1

11

2G

1

Rubalcaba ([email protected]) Sample Final Questions 142 / 162

Page 144: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F50. Find a way of communicating this graph to a

computer

0

v1v 3v

6v5v4v00

0 0 0

2G

1

1

1

1

1

1

1

1

1

1

1

1

1

10 0 0 0

000

0 0 0 0

0 0 0 0

0

Rubalcaba ([email protected]) Sample Final Questions 143 / 162

Page 145: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F51. Traveling Salesman Problem

You are in a band on tour with shows at: San Diego, CA, Topeka, KS,Washington D.C., Seattle, WA and Auburn, AL. Using the milage betweenthe cities, model this as a graph problem where you need to visit each cityexactly once, starting and returning to your home in Auburn, AL.

San Diego Auburn Seattle Washington D.C. TopekaSan Diego 0 2059 1255 2614 1492Auburn 2059 0 2631 748 860Seattle 1255 2631 0 2764 1818

Washington D.C. 2614 748 2764 0 1117Topeka 1492 860 1818 1117 0

2631

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

2059

Rubalcaba ([email protected]) Sample Final Questions 144 / 162

Page 146: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F52. Traveling Salesman Problem - Nearest Neighbor

2631

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

Using Nearest neighbor, starting at Auburn, AL (first visit WashingtonD.C, then Topeka, (not back to Auburn), then San Diego, then Seattle,then back to Auburn. Our total cost is

748 ` 1117 ` 1492 ` 1255 ` 2631 “ 7243

Rubalcaba ([email protected]) Sample Final Questions 145 / 162

Page 147: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F53. Traveling Salesman Problem - Sorted Edges

2631

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

2059

Using sorted edges our tour cost is

748 ` 860 ` 1255 ` 1492 ` 2764 “ 7119

Note that 1117 is next after 760 and 860, but adding it would create apremature cycle! Next is 1255, 1492,...

Rubalcaba ([email protected]) Sample Final Questions 146 / 162

Page 148: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem - Finding thee shortest

path - only way is brute force through all possibilities

2631

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255111726

142059

There are p5 ´ 1q!{2 “ 12 possible tours, lets find them all and add up thetotal distances (cost). We will keep track and update the minimum value.

Rubalcaba ([email protected]) Sample Final Questions 147 / 162

Page 149: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

748 ` 860 ` 1255 ` 1492 ` 2764 “ 7119 Min “ 7119 Max “ 7119

Rubalcaba ([email protected]) Sample Final Questions 148 / 162

Page 150: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

748`2764`1818`1492`2059 “ 8881 Min “ 7119 Max “ 8881

Rubalcaba ([email protected]) Sample Final Questions 149 / 162

Page 151: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

2059

748`1117`1492`1255`2631 “ 7243 Min “ 7119 Max “ 8881

Rubalcaba ([email protected]) Sample Final Questions 150 / 162

Page 152: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

2631`2764`1117`1492`2059 “ 10063 Min “ 7119 Max “ 10063

Rubalcaba ([email protected]) Sample Final Questions 151 / 162

Page 153: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2614

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

1117

2059`1255`2764`1117`860 “ 8055 Min “ 7119 Max “ 10063

Rubalcaba ([email protected]) Sample Final Questions 152 / 162

Page 154: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

2059`748`1117`1818`1255 “ 6997 Min “ 6997 Max “ 10063

Rubalcaba ([email protected]) Sample Final Questions 153 / 162

Page 155: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

748`2614`1255`1818`860 “ 7259 Min “ 6997 Max “ 10063

Rubalcaba ([email protected]) Sample Final Questions 154 / 162

Page 156: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

2059`2614`2764`1818`860 “ 10115 Min “ 6997 Max “ 10115

Rubalcaba ([email protected]) Sample Final Questions 155 / 162

Page 157: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

2631`1818`1117`2614`2059 “ 10239 Min “ 6997 Max “ 10239

Rubalcaba ([email protected]) Sample Final Questions 156 / 162

Page 158: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2614

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

1117

2631`2764`2614`1492`860 “ 10311 Min “ 6997 Max “ 10311

Rubalcaba ([email protected]) Sample Final Questions 157 / 162

Page 159: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2614

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

1117

2631`1255`2614`1117`860 “ 8447 Min “ 6997 Max “ 10311

Rubalcaba ([email protected]) Sample Final Questions 158 / 162

Page 160: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

2631

2059

1492

860

7482764

1818

Auburn

TopekaSan Diego

Seattle

Washington D.C.

1255

11172614

2631`1818`1492`2614`748 “ 9303 Min “ 6997 Max “ 10311

Rubalcaba ([email protected]) Sample Final Questions 159 / 162

Page 161: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F54. Traveling Salesman Problem

Min “ 6997 Max “ 10311

Rubalcaba ([email protected]) Sample Final Questions 160 / 162

Page 162: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F55. Traveling Salesman Problem Find the shortest and

longest tours

Min “ 6997 Max “ 10311

San Diego, Auburn, Washington D.C., Topeka, Seattle, San Diego for6997 miles.San Diego, Washington D.C., Seattle, Auburn, Topeka, San Diego for10311 miles.

Rubalcaba ([email protected]) Sample Final Questions 161 / 162

Page 163: Sample Final Questions for RRR - Complexity Zoo and …vlsicad.ucsd.edu/courses/cse21-s14/slides/RubalcabaSampleFinal... · Sample Final Questions for RRR - Complexity Zoo and Counting

F55. Consider the problem: ”Is there a tour through all

five cities that uses less than 7000 miles?” Is this problemin NP?

This problem is in NP. It is a YES/NO question and YES claimed

answers can be verified fast (poly time).

Here is a YES answer: San Diego, Auburn, Washington D.C., Topeka,Seattle, San Diego for 6997 miles, that can be verified in polynomial time.

Verification: 2059+748+1117+1818+1255=6997 and all cities visited.—————————————————————————————

Note this not the same thing as asking for the best answer, if 7000 waschanged to 10000, ”Is there a tour through all five cities that uses lessthan 10000 miles?” there are many YES answers.

Rubalcaba ([email protected]) Sample Final Questions 162 / 162