Discrete Mathematics with Graph Theory (3rd Edition) 233

Discrete Mathematics with Graph Theory (3rd Edition) 233 -...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Section 8.3 231 Since 4 = n #- 1 and n 2, we set f = L~J = 1 and m = L~J = 2. Since 30 = x > am, we replace n by n - m = 2 and change the list to 30,31. Since n = 2, x a1 and x = a2, we output "true" and stop. This search required four comparisons of x with an element in the list; a linear search would have used ten comparisons. (c) Since n = 11 1 and n 2, the algorithm sets f = L 1i J = 3 and m = L 2; J = 7. Since 7 = a3 < x = 16 ~ a7 = 17, the algorithm replaces n by m - f = 4 and changes the list to 10, 12, 15, 17. Since 4 = n 1 and n 2, the algorithm sets f = L~J = 1 and m = L~ = 2. Since x = 16 > a2 = 12, the algorithm replaces n with n - m = 2 and changes the list to 15, 17. Since n = 2 and x and x the algorithm outputs "false" and stops. This search required five comparisons of x with other elements; a linear search would have re- quired eleven. 6. (a) [BB] To find the complement of the set A = {a1, a2, ... , ad withrespectto U = {I, ... , 100}, Step 1: For i
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/08/2010 for the course MATH discrete m taught by Professor Any during the Summer '10 term at FSU.

Ask a homework question - tutors are online