06b-binarysearch - CSE 143 Lecture 6(b Binary Search...

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 143 Lecture 6 (b) Binary Search reading: 13.1 slides created by Marty Stepp http://www.cs.washington.edu/143/ 2 Sequential search • sequential search : Locates a target value in an array/list by examining each element from start to finish. – How many elements will it need to examine? – Example: Searching the array below for the value 42 : – Notice that the array is sorted. Could we take advantage of this? 7 2 10 3 15 4 20 5 22 6 25 7 30 8 36 9 42 10 50 11 56 12 68 13 85 14 103 92 2-4 value 16 15 1 index i 3 Binary search (13.1) • binary search : Locates a target value in a sorted array/list by successively eliminating half of the array from consideration. – How many elements will it need to examine? – Example: Searching the array below for the value 42 : 7 2 10 3 15 4 20 5 22 6 25 7 30 8 36 9 42 10 50 11 56 12 68 13 85 14 103 92 2-4 value 16 15 1 index min mid max 4 The Arrays class • Class Arrays in java.util has many useful array methods: • Syntax: Arrays. methodName...
View Full Document

{[ snackBarMessage ]}

Page1 / 6

06b-binarysearch - CSE 143 Lecture 6(b Binary Search...

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

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