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
- Summer '10
- Graph Theory, Harshad number, Ai Weiwei