tailieunhanh - Lecture An Introduction to Object-Oriented Programming with Java (4/e): Chapter 11 - C. Thomas Wu

Chapter 11 - Sorting and searching. After you have read and studied this chapter, you should be able to: Perform linear and binary search algorithms on small arrays, determine whether a linear or binary search is more effective for a given situation, perform selection and bubble sort algorithms, describe the heapsort algorithm and show how its performance is superior to the other two algorithms, apply basic sorting algorithms to sort an array of objects. | Chapter 11 Sorting and Searching 4th Ed Chapter 11 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 10 Objectives After you have read and studied this chapter, you should be able to Perform linear and binary search algorithms on small arrays. Determine whether a linear or binary search is more effective for a given situation. Perform selection and bubble sort algorithms. Describe the heapsort algorithm and show how its performance is superior to the other two algorithms. Apply basic sorting algorithms to sort an array of objects. 4th Ed Chapter 11 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Searching When we maintain a collection of data, one of the operations we need is a search routine to locate desired data quickly. Here’s the problem statement: Given a value X, return the index of X in the array, if such X exists. Otherwise, return NOT_FOUND (-1). We assume there are no duplicate entries in the array. We will count the number of comparisons the algorithms make to analyze their performance. The ideal searching algorithm will make the least possible number of comparisons to locate the desired data. Two separate performance analyses are normally done, one for successful search and another for unsuccessful search. 4th Ed Chapter 11 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Search Result number 23 17 5 90 12 44 38 0 1 2 3 4 5 6 7 8 84 77 Unsuccessful Search: Successful Search: NOT_FOUND search( 45 ) search( 12 ) 4 4th Ed Chapter 11 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Linear Search Search the array from the first to the last position in linear progression. public int linearSearch ( int[] number, int searchValue ) { int loc = 0; while (loc 4th Ed Chapter 11 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 10 Objectives After you have read and studied this chapter, you should be able to Perform linear and binary search algorithms on small arrays. Determine whether a linear or binary search is more effective for a given situation. Perform selection and bubble sort algorithms. Describe the heapsort algorithm and show how its performance is superior to the other two algorithms. Apply basic sorting algorithms to sort an array of objects. 4th Ed Chapter 11 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Searching When we maintain a collection of data, one of the operations we need is a search routine to locate desired data quickly. Here’s the problem statement: Given a value X, return the index of X in the array, if such X exists. Otherwise, return NOT_FOUND (-1). We assume there are no duplicate entries in

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.