《JAVA OOP开发》英文版 Chapter 10 Sorting and Searching

Chapter 10 Sorting and Searching 2000 McGraw-Hl‖ Introduction to Object-Oriented Programming with Java-Wu Chapter 10-1
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 1 Chapter 10 Sorting and Searching

Chapter 10 Objectives After you have read and studied this chapter, you should be able to e Perform linear and binary search algorithms on small arrays. e Determine whether a linear or binary search is more effective for a given situation Perform selection and bubble sort algorithms e Describe the heapsort algorithm and show how its performance is superior to the other two algorithms e Apply basic sorting algorithms to sort an array of objects C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10-2
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 2 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

Searching r When we maintain a collection of data, one of the operations we need is a search routine to locate desired data quickly r We will use an array of integers to present searching algorithms Here's the problem statement: Given a value X return the index of X in the array if suchX exists. Otherwise, return NOT_ FOUND(1). We assume there are no duplicate entries in the array r 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 r Two separate performance analyses are normally done, one for successful search and another for unsuccessful search C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10-3
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 3 Searching When we maintain a collection of data, one of the operations we need is a search routine to locate desired data quickly. We will use an array of integers to present searching algorithms. 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

Search result Unsuccessful search: search( 45 NOT FOUND Successful search: search( 12 4 number 0 234567 8 23175901244388477 C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 10-4
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 4 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: search( 45 ) NOT_FOUND search( 12 ) 4

Linear search r Search the array from the first to the last position in linear progression public int linearSearch int[] number, int searchvalue int loc hile( loc number length & number [loc searchvalue) i 1oc++; number length)[ //Not found eturn NOT FOUND else return loc; //Found, return the position C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10-5
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 5 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 < number.length && number[loc] != searchValue ) { loc++; } if ( loc == number.length) { //Not found return NOT_FOUND; } else { return loc; //Found, return the position } }

Linear search performance r We analyze the successful and unsuccessful searches separately. We count how many times the search value is compared against the array elements r Successful Search o Best Case-1 comparison o Worst Case-N comparisons(N-array size) r Unsuccessful search Best case Worst Case-N comparisons C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 6 Linear Search Performance We analyze the successful and unsuccessful searches separately. We count how many times the search value is compared against the array elements. Successful Search Best Case – 1 comparison Worst Case – N comparisons (N – array size) Unsuccessful Search Best Case = Worst Case – N comparisons

Binary search r If the array is sorted then we can apply the binary search technique number 012345678 5 1217233844778490 r The basic idea is straightforward. First search the value in the middle position. If X is less than this value, then search the middle of the left half next. If X is greater than this value, then search the middle of the right half next Continue in this manner. C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 7 Binary Search If the array is sorted, then we can apply the binary search technique. number 5 12 17 23 38 44 77 0 1 2 3 4 5 6 7 8 84 90 The basic idea is straightforward. First search the value in the middle position. If X is less than this value, then search the middle of the left half next. If X is greater than this value, then search the middle of the right half next. Continue in this manner

Sequence of Successful Search-1 low high mid search( 44) #10 8 4 low+ high 2 2 345678 5 1217233844778490 o W mid hi 38<44→Iow=mid+1=5 C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 10-8
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 8 Sequence of Successful Search - 1 5 12 17 23 38 44 77 0 1 2 3 4 5 6 7 8 84 90 low high mid search( 44 ) #1 0 8 low high + = 2 low high mid 38 < 44 low = mid+1 = 5 mid 4

Sequence of Successful Search -2 low high mid search( 44) #1 #2 05 8 4 8 6 low+ high 2 2345678 44778490 o mid hi high= mid-15+44<77 C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 10-9
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 9 Sequence of Successful Search - 2 5 12 17 23 38 44 77 0 1 2 3 4 5 6 7 8 84 90 low high mid search( 44 ) #1 0 8 + = 2 low high mid high = mid-1=5 44 < 77 4 mid 6 low high #2 5 8

Sequence of Successful Search -3 low high mid search( 44) #10 8 4 #25 8 low+ high #35 5 5 2 2 3 4 56 7 8 44 Successful search! ow high 44=44「mid C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10-10
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 10 - 10 Sequence of Successful Search - 3 5 12 17 23 38 44 77 0 1 2 3 4 5 6 7 8 84 90 low high mid search( 44 ) #1 0 8 + = 2 low high mid 44 == 44 4 #2 5 8 6 low high #3 5 5 mid 5 Successful Search!!
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《JAVA OOP开发》英文版 Chapter 9 objectives.ppt
- 《JAVA OOP开发》英文版 Chapter 8 Characters and strings.ppt
- 《JAVA OOP开发》英文版 Chapter 7 Repetition Statements.ppt
- 《JAVA OOP开发》英文版 Chapter 6 Selection statements.ppt
- 《JAVA OOP开发》英文版 Chapter 5 Processing Input with Applets.ppt
- 《JAVA OOP开发》英文版 Chapter 4 Defining Instantiable Classes.ppt
- 《JAVA OOP开发》英文版 Chapter 3 Numerical Data.ppt
- 《JAVA OOP开发》英文版 Chapter 2 Java Programming Basics.ppt
- 《JAVA OOP开发》英文版 Chapter 1 Introduction to Object-oriented Programming and Software Development.ppt
- 《JAVA OOP开发》英文版 Introduction to Computers and Programming Languages.ppt
- 《Windows DNA应用程式》 面向对象分析与设计讲义.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第四章 第四讲 分支结构.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十二章 文件.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十一章 复杂数据类型及排序.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第六讲 数组.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第六讲 数组.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第七章(7-2)指针与指针变量.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第五章 循环结构.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第二章 数据类型与运算符.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第二讲 数据类型与算术运算.doc
- 《JAVA OOP开发》英文版 Chapter 11 File Input and Output.ppt
- 《JAVA OOP开发》英文版 Chapter 12 Reusable classes and packages.ppt
- 《JAVA OOP开发》英文版 Chapter 13 GUI Objects and Event-Driven Programming.ppt
- 《JAVA OOP开发》英文版 Chapter 14 Inheritance and Polymorphism.ppt
- 《JAVA OOP开发》英文版 Chapter 15 Case Study Class Roster Maintenance program.ppt
- 《JAVA OOP开发》英文版 Chapter 16 Chapter 16 Recursive algorithms.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第一章 绪论.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第七章 牛行接与应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第三章 MCS-51单片机指令系统.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第九章 A/D、D/A转换接口.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第二章 MCS-51学机组成理.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第五章 输入/输出与中断.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第八章 并行接口与应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第六章 定时器/计数器及应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第十章 单片机应用系统设计与开发.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第四章 MCS-51单片机存储器的扩展.ppt
- 《网络安全设计》 第一章 安全设计简介.ppt
- 《网络安全设计》 第二章 创建网络安全计划.ppt
- 《网络安全设计》 第三章 确定网络安全威胁.ppt
- 《网络安全设计》 第四章 分析安全风险.ppt