正在加载图片...
Example: Sequential search ALGORITHM SequentialSearch(A[0.n-1, K) //Searches for a given value in a given array by sequential search //Input: An array A[O n-1 and a search key K //Output: The index of the first element of A that matches K or-1 if there are no matching elements ←0 while i< n and a[i]≠kdo ←-i+1 if i<n return i else return-1 口 Worst case n key comparisons 口 Best case comparisons D Average case (n+1)/2, assuming K is in A Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2 2-6Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-6 Example: Sequential search Worst case Best case Average case n key comparisons 1 comparisons (n+1)/2, assuming K is in A
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有