Join Raghavendra Dixit for an in-depth discussion in this video Searching elements in an ordered array continued, part of Introduction to Data Structures & Algorithms in Java.
- [Narrator] To find an element in an ordered array…or an ordered list, we use a similar approach.…So let's say we are supposed to find the number 60…in this sorted array.…So we start from the midpoint of the array,…that is we find the middle index of the array.…Now, the array may have even number of elements…in which case, we will not find the exact middle…middle index of the array.…So we can find the middle index as the max array index…which is seven, plus minimum array index which is zero…and divide it by two,…and take the floor of the result, to get an integer…because this division may give us a real number.…
So we get the number three, which is the first index…we look at.…We check out what element is at that index…and see if it is equal to the number we are searching for.…in this case 32 is less than 60…hence we are at least sure that if present,…the number must be at the right side of the array.…So we just ignore the elements which are at the left…of the index three.…And now we need to find which index should we look at.…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Why study data structures and algorithms?
- How to calculate the time complexity
- Using Big O notation
- Using basic sorting and search algorithms
- Searching elements in unordered arrays and ordered arrays
- Implementing a linked list in Java
- Implementing stacks using arrays
- Queues using arrays
- Binary search trees
- Representing heaps using arrays
Skill Level Intermediate
1. Introduction to Algorithms
2. Analysis of Algorithms
3. Basic Sorting and Search Algorithms
4. Linked Lists
5. Stacks and Queues
7. Binary Search Trees
8. More Sorting Algorithms
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.