COMS W3134 Lecture Notes - Lecture 1: Linear Search, Binary Search Algorithm

50 views2 pages

Document Summary

Given array with int s a 121 index a. , decide method to search for a desired value within the array. Simple solution : use linear 1 sequential search. Idea : return - l if not found , return location of first instance public static int linearsearch(int x, int[]a){ int index = -1; Worst case scenario for linear search : (cid:8869: ( n ) item is the last element , when item is not ( we have to go through the entire list ) in the array. Best case scenario : when item is the first ( or one of first ) in array. * in and n are both linear son dominates for average. * in is a constant factor of n so i is not needed. * given that item might not be in array , more often than not we have to go through the entire array.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents