SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Java Programming: From Problem Analysis to Program Design, 5e Chapter 14 Searching and Sorting
Chapter Objectives ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
List Processing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
Search ,[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
Search (continued) Java Programming: From Problem Analysis to Program Design, 5e ,[object Object],[object Object],[object Object]
Search (continued) Java Programming: From Problem Analysis to Program Design, 5e ,[object Object],[object Object],[object Object]
Selection Sort ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
Selection Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Selection Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Selection Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Selection Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e public static void  selectionSort( int [] list,  int  listLength) { int  index; int  smallestIndex; int  minIndex; int  temp; for  (index = 0; index < listLength – 1; index++) { smallestIndex = index;  for  (minIndex = index + 1;  minIndex < listLength; minIndex++) if  (list[minIndex] < list[smallestIndex]) smallestIndex = minIndex;  temp = list[smallestIndex]; list[smallestIndex] = list[index]; list[index] = temp; } }
Java Programming: From Problem Analysis to Program Design, 5e ,[object Object],[object Object],Selection Sort (continued)
Insertion Sort Java Programming: From Problem Analysis to Program Design, 5e ,[object Object]
Insertion Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Insertion Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Insertion Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Insertion Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e public static void  insertionSort( int [] list,  int  listLength) { int  firstOutOfOrder, location; int  temp; for  (firstOutOfOrder = 1; firstOutOfOrder < listLength; firstOutOfOrder++) if  (list[firstOutOfOrder] < list[firstOutOfOrder - 1]) { temp = list[firstOutOfOrder]; location = firstOutOfOrder; do { list[location] = list[location - 1]; location--; }  while(location  > 0 && list[location - 1] > temp); list[location] = temp; } }  //end insertionSort
Insertion Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e ,[object Object],[object Object]
Binary Search Algorithm ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
Binary Search Algorithm (continued) Java Programming: From Problem Analysis to Program Design, 5e ,[object Object]
Binary Search Algorithm (continued) Java Programming: From Problem Analysis to Program Design, 5e
Java Programming: From Problem Analysis to Program Design, 5e public static int  binarySearch( int [] list,  int  listLength,  int  searchItem) { int  first = 0; int  last = listLength - 1; int  mid; boolean  found =  false ; while  (first <= last && !found) { mid = (first + last) / 2; if  (list[mid] == searchItem) found =  true ; else if  (list[mid] > searchItem) last = mid - 1; else first = mid + 1; } if  (found)  return  mid; else return  –1; }  //end binarySearch
Binary Search Algorithm (continued) Java Programming: From Problem Analysis to Program Design, 5e
Binary Search Algorithm (continued) Java Programming: From Problem Analysis to Program Design, 5e
Performance of the Binary Search  Java Programming: From Problem Analysis to Program Design, 5e ,[object Object],[object Object],[object Object]
Performance of the Binary Search (continued) ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
Programming Example:  Election Results ,[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
Programming Example:  Election Results (continued) ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
Programming Example: Election Results (Solution) ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
Programming Example: Election Results (Solution) (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e
Programming Example:  Election Results Java Programming: From Problem Analysis to Program Design, 5e
Programming Example:  Election Results (continued) Java Programming: From Problem Analysis to Program Design, 5e
Chapter Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 5e

Weitere ähnliche Inhalte

Was ist angesagt?

9781111530532 ppt ch10
9781111530532 ppt ch109781111530532 ppt ch10
9781111530532 ppt ch10
Terry Yoast
 
Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8
dplunkett
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5
dplunkett
 

Was ist angesagt? (20)

Chapter 13
Chapter 13Chapter 13
Chapter 13
 
9781111530532 ppt ch10
9781111530532 ppt ch109781111530532 ppt ch10
9781111530532 ppt ch10
 
Ppt chapter06
Ppt chapter06Ppt chapter06
Ppt chapter06
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
Ppt chapter11
Ppt chapter11Ppt chapter11
Ppt chapter11
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
 
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
 
Ppt chapter05
Ppt chapter05Ppt chapter05
Ppt chapter05
 
Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8
 
Ppt chapter09
Ppt chapter09Ppt chapter09
Ppt chapter09
 
Pptchapter04
Pptchapter04Pptchapter04
Pptchapter04
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Method of java
Method of javaMethod of java
Method of java
 
Actors model in gpars
Actors model in gparsActors model in gpars
Actors model in gpars
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Operators In Java Part - 8
Operators In Java Part - 8Operators In Java Part - 8
Operators In Java Part - 8
 

Andere mochten auch

AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
Amazon Web Services Korea
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
maheshm1206
 

Andere mochten auch (20)

Chap01
Chap01Chap01
Chap01
 
9781285852744 ppt ch16
9781285852744 ppt ch169781285852744 ppt ch16
9781285852744 ppt ch16
 
Data Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedData Structures- Part9 trees simplified
Data Structures- Part9 trees simplified
 
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
 
Data Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesData Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queues
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
 
Applying Design Patterns in Practice
Applying Design Patterns in PracticeApplying Design Patterns in Practice
Applying Design Patterns in Practice
 
AWS ECS Quick Introduction
AWS ECS Quick IntroductionAWS ECS Quick Introduction
AWS ECS Quick Introduction
 
Lecture 2a arrays
Lecture 2a arraysLecture 2a arrays
Lecture 2a arrays
 
Web Database
Web DatabaseWeb Database
Web Database
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Java 8 Support at the JVM Level
Java 8 Support at the JVM LevelJava 8 Support at the JVM Level
Java 8 Support at the JVM Level
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
 
Building Digital Transaction Systems in the new Banking World
Building Digital Transaction Systems in the new Banking WorldBuilding Digital Transaction Systems in the new Banking World
Building Digital Transaction Systems in the new Banking World
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
Running Microservices on Amazon ECS - AWS April 2016 Webinar Series
Running Microservices on Amazon ECS - AWS April 2016 Webinar SeriesRunning Microservices on Amazon ECS - AWS April 2016 Webinar Series
Running Microservices on Amazon ECS - AWS April 2016 Webinar Series
 

Ähnlich wie 9781111530532 ppt ch14 (20)

Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chap10
Chap10Chap10
Chap10
 
Chapter 11 ds
Chapter 11 dsChapter 11 ds
Chapter 11 ds
 
9781111530532 ppt ch14_quick_sort
9781111530532 ppt ch14_quick_sort9781111530532 ppt ch14_quick_sort
9781111530532 ppt ch14_quick_sort
 
9781111530532 ppt ch14_quick_sort
9781111530532 ppt ch14_quick_sort9781111530532 ppt ch14_quick_sort
9781111530532 ppt ch14_quick_sort
 
9781111530532 ppt ch13
9781111530532 ppt ch139781111530532 ppt ch13
9781111530532 ppt ch13
 
Arrays.pdf
Arrays.pdfArrays.pdf
Arrays.pdf
 
9781439035665 ppt ch02
9781439035665 ppt ch029781439035665 ppt ch02
9781439035665 ppt ch02
 
9781111530532 ppt ch03
9781111530532 ppt ch039781111530532 ppt ch03
9781111530532 ppt ch03
 
9781111530532 ppt ch03
9781111530532 ppt ch039781111530532 ppt ch03
9781111530532 ppt ch03
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
 
9781439035665 ppt ch07
9781439035665 ppt ch079781439035665 ppt ch07
9781439035665 ppt ch07
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
9 Arrays
9 Arrays9 Arrays
9 Arrays
 
9781111530532 ppt ch02
9781111530532 ppt ch029781111530532 ppt ch02
9781111530532 ppt ch02
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
9781111530532 ppt ch07
9781111530532 ppt ch079781111530532 ppt ch07
9781111530532 ppt ch07
 
9781439035665 ppt ch03
9781439035665 ppt ch039781439035665 ppt ch03
9781439035665 ppt ch03
 
9781111530532 ppt ch04
9781111530532 ppt ch049781111530532 ppt ch04
9781111530532 ppt ch04
 

Mehr von Terry Yoast

Mehr von Terry Yoast (20)

9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
 
9781305078444 ppt ch03
9781305078444 ppt ch039781305078444 ppt ch03
9781305078444 ppt ch03
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
 
9781305078444 ppt ch01
9781305078444 ppt ch019781305078444 ppt ch01
9781305078444 ppt ch01
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13
 
9781337102087 ppt ch18
9781337102087 ppt ch189781337102087 ppt ch18
9781337102087 ppt ch18
 
9781337102087 ppt ch17
9781337102087 ppt ch179781337102087 ppt ch17
9781337102087 ppt ch17
 
9781337102087 ppt ch16
9781337102087 ppt ch169781337102087 ppt ch16
9781337102087 ppt ch16
 
9781337102087 ppt ch15
9781337102087 ppt ch159781337102087 ppt ch15
9781337102087 ppt ch15
 
9781337102087 ppt ch14
9781337102087 ppt ch149781337102087 ppt ch14
9781337102087 ppt ch14
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
 
9781337102087 ppt ch11
9781337102087 ppt ch119781337102087 ppt ch11
9781337102087 ppt ch11
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

9781111530532 ppt ch14

  • 1. Java Programming: From Problem Analysis to Program Design, 5e Chapter 14 Searching and Sorting
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Selection Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 9. Selection Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 10. Selection Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 11. Selection Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e public static void selectionSort( int [] list, int listLength) { int index; int smallestIndex; int minIndex; int temp; for (index = 0; index < listLength – 1; index++) { smallestIndex = index; for (minIndex = index + 1; minIndex < listLength; minIndex++) if (list[minIndex] < list[smallestIndex]) smallestIndex = minIndex; temp = list[smallestIndex]; list[smallestIndex] = list[index]; list[index] = temp; } }
  • 12.
  • 13.
  • 14. Insertion Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 15. Insertion Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 16. Insertion Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 17. Insertion Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e public static void insertionSort( int [] list, int listLength) { int firstOutOfOrder, location; int temp; for (firstOutOfOrder = 1; firstOutOfOrder < listLength; firstOutOfOrder++) if (list[firstOutOfOrder] < list[firstOutOfOrder - 1]) { temp = list[firstOutOfOrder]; location = firstOutOfOrder; do { list[location] = list[location - 1]; location--; } while(location > 0 && list[location - 1] > temp); list[location] = temp; } } //end insertionSort
  • 18.
  • 19.
  • 20.
  • 21. Binary Search Algorithm (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 22. Java Programming: From Problem Analysis to Program Design, 5e public static int binarySearch( int [] list, int listLength, int searchItem) { int first = 0; int last = listLength - 1; int mid; boolean found = false ; while (first <= last && !found) { mid = (first + last) / 2; if (list[mid] == searchItem) found = true ; else if (list[mid] > searchItem) last = mid - 1; else first = mid + 1; } if (found) return mid; else return –1; } //end binarySearch
  • 23. Binary Search Algorithm (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 24. Binary Search Algorithm (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. Programming Example: Election Results Java Programming: From Problem Analysis to Program Design, 5e
  • 32. Programming Example: Election Results (continued) Java Programming: From Problem Analysis to Program Design, 5e
  • 33.