CS 1100 Lecture Notes - Lecture 22: Binary Search Algorithm, Bubble Sort, Sorting Algorithm

13 views2 pages
30 Nov 2016
School
Course
Professor

Document Summary

One of the primary things computers do is search and sort, you often need to search or sort an array. Searching an array is looking for a particular element (called a key) in the array. Sorting an array is putting all the elements in order. Ascending example: (cid:1005), (cid:1006), (cid:1007), (cid:1008), (cid:1012), (cid:1013)(cid:1013), (cid:1005)(cid:1004)(cid:1005) . Descending example: (cid:1005)(cid:1004)(cid:1005), (cid:1013)(cid:1013), (cid:1012), (cid:1008), (cid:1007), (cid:1006) . Idea is to start at the first element of the array. If it"s the ele(cid:373)e(cid:374)t looki(cid:374)g fo(cid:396), stop a(cid:374)d (cid:396)etu(cid:396)(cid:374) i(cid:374)de(cid:454) Worst case; have to check every element in the array. Binary search is a much more efficient strategy. Ca(cid:448)eat is that (cid:271)i(cid:374)a(cid:396)(cid:455) sea(cid:396)(cid:272)h (cid:396)e(cid:395)ui(cid:396)es the a(cid:396)(cid:396)a(cid:455) to (cid:271)e so(cid:396)ted, o(cid:396) else it (cid:449)o(cid:374)"t (cid:449)o(cid:396)k. Very simple sorting algorithm, but not very efficient. Java has a class called arrays that has pre-made methods for working with arrays.

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

Related Questions