Sentinel linear search - Basic Algorithms Fast (23)

Опубликовано: 16 Октябрь 2024
на канале: Begin Coding Fast
65
0

The sentinel linear search process replaces the final element of an array with the target. The index of the array would be incremented until the target is met. Because the target is in the array now, the index would stop incrementing finally. The original final element would be put back to the array. If the stopping index is less than the length of the array minus 1, or if the final element equals the target, then the target is found. Else, the target is not found.

The advantage of the sentinel linear search process is that we don't need to spend time on checking whether the index would go out of bounds.

1:29 - Advantage of sentinel linear search
2:10 - Case when the target exists before the final element of the array
5:08 - Case when the target exists as the final element of the array
7:58 - Case when the target does not exist

Playlist of my Algorithm walkthrough
   • Algorithms and data structures | DSA ...  

Basic Python Fast
   • Python tutorial for beginners | Pytho...  

Playlist of my Python examples
   • Python projects for beginners with fu...  

Playlist of my Java course
   • [14 hours] Java tutorial for beginner...  

Playlist of my Java examples
   • Java projects for beginners | Java pr...  

#sentinelsearch #algorithm #begincodingfast #algorithmvisualization