In Segment 18.7, we said that a sequential search of an array will examine on average about half of the n entries. Lets look a little more carefully at this computation. A sequential search is either successful or not. Let be the probability that we will find the desired value in the array and 1 - be the probability that we will not. We further assume that the value, if found, is equally likely to be in each of the locations of the array. We need to consider each possibility. For each case, we count the comparisons and determine its probability of occurrence. To find the average number of comparisons made by the search, we first multiply each probability by the number of comparisons in each case. The following table summarizes these results: Probability Number of Comparisons Product Found at index 0 Found at index 1 Found at index 2 ... Found at index n - 2 Found at index n - 1 Not found / n / n / n ... / n / n 1 1 2 3 ... n 1 n n / n 2 / n 3 / n ... (n 1) / n (1 ) n a. Compute the average number of comparisons by adding all the products in the last column of the table.b. What is the average number of comparisons if the search is guaranteed to be successful ( = 1)?c. What is the average number of comparisons if the search is guaranteed to be unsuccessful ( = 0)?d. What is the average number of comparisons if the search is successful half of the time ( = 0.5)?

Weekly ¥8 Notes Mondayarc21,2016 JoiPMF Marginal range JointMF Giv:n SkyofX&Y E@# )={0,014,014,1B circ,its onlyvalioutcomes Outcomarindependent 11£ , jointF ×=#aoa,tP(N=otlstrajeotiRnR -0.01- " Pxtx,y)=PK=X,y=y) ,=co .mil/RA.s8jEY*pE#T*stTAtRd-on ={ m:} 'D Y=ex)T