Sei sulla pagina 1di 14

Section 10.2 6.

How many weighings of a balance scale are needed to find a lighter counterfeit coin among four coins? Describe an algorithm to find the lighter coin using this number of weighings. Solution:
1
4

2
4

3
4

4
4

Lighter 1 or 2 Balance 3 or 4Lighter

1
4

2
4

Impossible

3
4

4
4

1 Lighter

Balance 2 Lighter

3Lighter

Balance

4 Lighter

Impossible

Impossible

There are three possibilities for each weighing on a balance scale. The two pans can have equal weight, the first pan can be heavier, or the second pan can be heavier. Consequently, the decision tree for the sequence of weighings is a 3-ary tree. There are at least four leaves in the decision tree because there are four possible outcomes (because each of the four coins can be the counterfeit lighter coin), and each possible outcome must be represented by at least one leaf. The largest number of weighings needed to determine the counterfeit coin is the height of the decision tree. From Corollary 1 of Section 10.1 it follows that the height of the decision tree is at least upper bound of log3 4 = 2. Hence, at least two weighings are needed. It is possible to determine the counterfeit coin using two weighings. The decision tree that illustrates how this is done is shown in above Figure.

22. Given the coding scheme a : 001 , b: 0001 , e: 1 , r : 0000, s: 0100, t: 011 , x: 01010, find the word represented by

a) 011 1 0100 011 Answer: test b) 0001 1 1 0000 Answer: beer c) 0100101010 Answer: sex d) 01100101010 Answer: tax

Part 2 Written Assignment 5

Section 10.1 2. Which of these graphs are trees?

Answer: a) No b) Yes c) No d) Yes e) No f) No

8. What is the level of each vertex of the rooted tree in Exercise 4?

Solution: The root a is at level 0. Vertices b, c, and d are at level 1. Vertices e, f, g, h and i are at level 2. Vertices j, k, l, m, n, o, and p are at level 3. Finally, vertex q, r, s is at level 4. Because the largest level of any vertex is 4, this tree has height 4. 10. Draw the subtree of the tree in Exercise 4 that i s rooted at a) a b) c c) e Solution: a)

b)

c)

12. a) How many nonisomorphic unrooted trees are there with four vertices? b) How many nonisomorphic rooted trees are there with four vertices (using isomorphism for directed graphs)? Solution: a) Two

b) Four

20. How many leaves do a full 3 -ary tree with 100 vertices have? Solution: (m 1)n 1 A full mary tree with n vertices has leaves l= m

So number of leaves =

(3 1)100 1 leaves =
3

67 leaves

22. A chain letter starts when a person sends a letter to five others. Each person who receives the letter either sends it to five other people who have never received it or does not send it to anyone. Suppose that 10,000 people send out the letter before the chain ends and that no one receives more than one letter. How many people receive the letter, and how many do not send it out? Solution: The chain letter can be represented using a full 5-ary tree. The internal vertices correspond to people who sent out the letter, and the leaves correspond to people who did not send it out.

So the number of people who received the letter n = mk+1 ; where k is no of internal vertices of full m-ary tree So number of people who received the letter n = 5*10000 +1= 50001 Also number of people who did not send letter will be equal to the number of leave of 5-1ry tree. So number of people who did not send letter = (m-1)k+1 = (5-1)*10000 +1 = 40001 36. a) Draw the complete binary tree with 15 vertices that represents a tree-connected network of 15processors. b) Show how 16 numbers can be added using the 15processors in part (a) using four steps. Solution: a)

b) Step -1: Add x1 and x2 using P8, x3 and x4 using P9 , x5 and x6 using P10, x7 and x8 using P11, x9 and x10 using P12, x11 and x12 using P13, x13 and x14 using P14, x15 and x16 using P15 Step -2: Add x1 + x2 and x3 + x4 using P4, x5 + x6 and x7 + x8 using P5, x9 + x10 and x11 + x12 using P6, x13 + x14 and x15 + x16 using P7 Step -3: Add x1 + x2+ x3 + x4 and x5 + x6 + x7 + x8 using P2, x9 + x10 + x11 + x12 and x13 + x14 + x15 + x16 using P3 Step -4: Finally, in the fourth step, we add x1 + x2+ x3 + x4 + x5 + x6 + x7 + x8 and x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 using P1.

Section 10.2 2. Build a binary search tree for the words oenology, phrenology, campanology, ornithology, ichthyology, limnology, alchemy, and astrology using alphabetical order. Solution: Oenology campanology alchemy astrology ichthyology limnology phrenology ornithology

4. How many comparisons are needed to locate or to add each of the words in the search tree for Exercise 2, starting fresh each time? a) palmistry = 3 (oenology, phenology, X) b) etymology = 4 (oenology, campanology, ichthyology, X) c) paleontology = 3 (oenology, phenology, X) d) glaciology = 4 (oenology, campanology, icthnology, X)

8. How many weighings of a balance scale are needed to find a counterfeit coin among eight coins if the counterfeit coins either heavier or lighter than the others? Describe an algorithm to find the counterfeit coin using this number of weighings. Solution: From Corollary 1 of Section 10.1 it follows that the height of the decision tree is at least upper bound of log3 4 = 2. Hence, at least two weighings are needed. It is possible to determine the counterfeit coin using three weighings. The algorithm that illustrates how this is done is shown in below Table. First Weighing 123=456 Second Weighing 1=7 Third Weighing 1=8 => not possible 1<8 => 8 is odd and heavy 1>8 => 8 is odd and light 7 is odd and heavy

1<7

123>456

1>7 1 4=2 7

14<27

14>27

123<456

1 4=2 7

14<27

14>27

7 is odd and light 5=6 => 3 is odd and heavy 5<6 => 5 is odd and light 5>6 => 6 is odd and light 2=7 => 4 is odd and light 2<7 => not possible 2>7 => 2 is odd and heavy 1=4 => not possible 1>4 => 1 is odd and heavy 1<4 => not possible 5=6 => 3 is odd and light 5<6 => 6 is odd and heavy 5>6 => 5 is odd and heavy 2=7 => 1 is odd and light 2<7 => not possible 2>7 => not possible 1=4 => 2 is odd and light 1>4 => not possible 1<4 => 4 is odd and heavy

12. Find the least number of comparisons needed to sort five elements and devise an algorithm that sorts these elements using this number of comparisons. Solution: There are 5! = 120 possible outcomes. Therefore a binary tree for the sorting procedure will have at least 7 levels. Because the height of a binary tree with n! leaves is at least upper bound of log2n! or, 2h 120 implies h 7, But 7 comparisons is not enough. The least number of comparisons needed to sort (order) five elements is 8. 14. Use the tournament sort to sort the list 17, 4, 1, 5, 13, 10, 14, 6. Solution: Step-1

Step-2

Step -3

Step -4

Step-5

Step -6

Step -7

Step -8

Section 10.3 2. Construct the universal address system for the given ordered rooted tree. Then use this to order its vertices using the lexicographic order of their labels.

Solution:

The lexicographic ordering is: 0 < 1 < 1.1 < 1.1.1 < 1.1.1.1 < 1.1.1.2 < 1.1.2 < 1.2 < 2

8. Determine the order in which a preorder traversal visits the vertices of the given ordered rooted tree.

Solution: Preorder traversal: a, b, d, e, i, j, m, n, o, c, f, g, h, k, l, p 12. In which order are the vertices of the ordered rooted tree in Exercise 9 visited using an inorder traversal?

Solution: Inorder traversal: k, e, l, m, b, f, r, n, s, g, a, c, o, h, d, i, p, j, q Section 10.4 4. Find a spanning tree for the graph shown by removing edges in simple circuits.

Solution: Spanning tree

10. Draw all the spanning trees of the given simple graphs.

Solution:

All Spanning tree:

12. How many nonisomorphic spanning trees does each of these simple graphs have? a) K3 Answer: One

b) K4 Answer: Four

c) K5 Answer: Five

30. Use backtracking to find a subset, if it exists, of the set {27, 24, 19, 14, 11, 8} with sum a) 20 b) 41 c) 60 Solution: a) No subset exists for sum 20. b) Subset is {27, 14}

c) Subset is {27, 19, 14}, {27, 14, 11, 8}

Potrebbero piacerti anche