Discrete Mathematics with Graph Theory (3rd Edition) 221

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

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

View Full Document Right Arrow Icon
Section 8.1 219 V153 ~ 12.3693 as shown. 12. 3 3 1 153. 0 0 0 0 12 144 243 9 0 0 7 2 9 2466 1 7 1 0 0 1 4 7 9 6 24729 2 3 0 4 0 0 2 2 2 5 6 1 247383 7 8 3 9 0 0 7 4 2 1 4 9 2473861 4 1 7 5 1 0 0 2 4 7 3 8 7 1 1 7 0 1 2 3 9 8. [BB] We find the sum of the numbers and divide by n. Thus, to find the average of n numbers Step 1: set S = 0; Step 2: for i = 1 to n, replace S by S + ai; Step 3: output *. 9. [BB] To find the maximum of n numbers alo a2, ... , an, Step 1: let M = al; Step 2: for i = 2 to n, if ai > M, replace M by ai; Step 3: output M. The value of M output in Step 3 is the maximum of the ai. 10. We establish a counter, T, which is initially set to 0 and is increased by 1 each time an occurrence of x is found in the list. To determine how many times the element
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x appears in the list aI, a2, ... , an, Step 1: set T = 0; Step 2: for i = 1 to n, if ai = x, replace T by T + 1; Step 3: output T. The output value of T is the number of times x appears in the list. 11. To determine how many elements from among aI, a2, ... ,an lie in the range 85 ::; x ::; 90, Step 1: set t = 0; Step 2: for i = 1 to n, if ai ~ 85 and ai ::; 90, replace t by t + 1; Step 3: output t. The value of t output in Step 3 is the desired number. 12. [BB] If x::; aI, we wish to output x, aI, a2, ... ,an. If al < x ::; a2, we wish to output al, x, a2,·· . ,an, and so on. If x ~ an, we wish to output al, a2, ... ,an, x. Here is one suitable algorithm. To insert x into its correct position in the ordered list al ::; a2 ::; ... ::; an,...
View Full 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