Searches

Searches - Searches linear/sequential search important to...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Searches linear/sequential search important to know what is the best/worst time for success and failure - misses vs hits for success worst case: O(n) best case: O(1) for failure worst case: O(n) best case: O(n) what is being counted for running time -- comparison of target against item in array number of comparisons Best case Worst case Success 1 n failure n n can you make failures go faster? Yes, if you have a sorted list best: O(1), worst: O(n) only practical if the upfront cost can be amortized over searches until next sort quicksort average: O(n log n) worst case: O(n 2 ) average running time # comparisons on average? for success o summation of 1 to n / n C 1 +C 2 +…C n / n for linear search, C 1 is 1, C 2 is 2, etc o assumption: match is equally likely at all spots; probably of 1/n if this is not true, then you have unequal probability; put the more probable items in the front - “static” approach, which only works if array changes rarely summation of 1 to n, number of comparisons * probably of match
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Searches - Searches linear/sequential search important to...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online