badge icon

Bu içerik Türkçe olarak yazılmış olup yapay zeka ile otomatik olarak İngilizceye çevrilmiştir.

Madde

Binary Search Algorithm

Math

+1 Daha

Alıntıla

Binary Search is a search algorithm used to find the position of an element in a sorted array. In this approach, the element is searched at the midpoint of a segment of the array.


Binary search can only be applied to a sorted list of elements. If the elements are not already sorted, they must be sorted first.


Working Principle

The Binary Search algorithm can be implemented in two ways.

  • Recursive Approach
  • Iterative Approach


Although the recursive approach adopts the divide and conquer logic, both methods generally follow these steps:

Step 1:

The array is in sorted order and the target element is 4.


Step 2:

The smallest and largest elements of the array are identified.


Step 3:

The middle element of the array is determined.

middle element = (smallest element + largest element) / 2


Step 4: If the target element is equal to the middle element, the element has been found. If not, the found element is compared with the target element.


Step 5: If the target element is greater than the middle element, the search continues among the elements to the right of the middle element. In this case, the smallest element is set to middle element + 1.


Step 6: If the target element is smaller than the middle element, the search continues among the elements to the left of the middle element. In this case, the largest element is set to middle element - 1.


Step 7: The search continues until there is only one element (the target) remaining between the smallest and largest elements.


Binary Search Algorithm Iterative Approach Pseudocode


Binary Search Algorithm Recursive Approach Pseudocode



Binary Search Algorithm with Java Code

Kaynakça

Kızıltan, M. Ç. *Binary Search (İkili Arama).* Accessed January 16, 2025.

Programiz. "Binary Search." Accessed January 16, 2025. https://www.programiz.com/dsa/binary-search

Tutorials Point. "Binary Search Algorithm." Accessed January 16, 2025.

W3Schools. "DSA Binary Search." Accessed January 16, 2025.

Yazar Bilgileri

Avatar
YazarBeyza Nur Türkü3 Ocak 2026 12:24

Tartışmalar

Henüz Tartışma Girilmemiştir

"Binary Search Algorithm" maddesi için tartışma başlatın

Tartışmaları Görüntüle

İçindekiler

  • Working Principle

  • Binary Search Algorithm Iterative Approach Pseudocode

  • Binary Search Algorithm Recursive Approach Pseudocode

  • Binary Search Algorithm with Java Code