Lesson 45 Arrays Part 6 - Binary search on Integer, Character, Floating point Arrays

Опубликовано: 01 Январь 1970
на канале: JavaJourneyWithMadhavi
33
4

Link to the Book - Essentials of Computer Applications:

https://www.amazon.in/Essentials-Comp...

Link to Time complexity:
https://en.wikipedia.org/wiki/Time_co...

Link to lesson 16 if-construct:

   • Lesson 16 if - else statements -Decis...  

Practice Exercise 2:

Dry run of the following search elements in the following array using Binary search algorithm.

emp
1 3 8 10 15 16 92 100


1. Search 1
2. Search 3
3. Search 15
4. Search -5
5. Search 92

Practice Exercise 3 - Binary search on integers, characters, and floating numbers.

1. Read an array of five grades (characters) of students in a sorted order using a method called read (). Read a search element from the user in a method called search () and find the element using binary search. Declare array and length as instance variables. Call the methods in main method.
2. Initialize an array with 45.6,67.8, 89.3, 90.5. Create three methods: Linear search (), binary search () and main.
1. Search for 67.8 and display its position (using linear search).
2. Search for 45.6 and display its position. (using binary search)
3. Search for 100 using linear search and note the message. (output should be: “not found”)