Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Web Security TippsNew manual calculation setting in Google Sheets(21.09.2026 um 20:54 Uhr)
Videos & KonferenzenTechquickie: The Steam Frame Shouldn't Work - Here's Why It Does(21.09.2026 um 21:17 Uhr)
Sichere ProgrammierungHow to Build a Production-Ready iOS App With AI-Generated Code(21.09.2026 um 21:00 Uhr)
Sichere ProgrammierungAfriex Integrations: Sandbox, Idempotency, and Webhook Simulation(21.09.2026 um 21:50 Uhr)
Sichere ProgrammierungBridging Local and Cloud Databases for Centralized Data Management(21.09.2026 um 21:51 Uhr)
Web Security TippsNew manual calculation setting in Google Sheets(21.09.2026 um 20:54 Uhr)
Videos & KonferenzenTechquickie: The Steam Frame Shouldn't Work - Here's Why It Does(21.09.2026 um 21:17 Uhr)
Sichere ProgrammierungHow to Build a Production-Ready iOS App With AI-Generated Code(21.09.2026 um 21:00 Uhr)
Sichere ProgrammierungAfriex Integrations: Sandbox, Idempotency, and Webhook Simulation(21.09.2026 um 21:50 Uhr)
Sichere ProgrammierungBridging Local and Cloud Databases for Centralized Data Management(21.09.2026 um 21:51 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Binary Search in Java

What is binary search: It is an efficient algorithm which is used to find the position of a target value within a sorted array or list. This works by repeatedly dividing the search range in half, hence it is also known as two parts. The…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

What is binary search: It is an efficient algorithm which is used to find the position of a target value within a sorted array or list. This works by repeatedly dividing the search range in half, hence it is also known as two parts.

The data should be stored in ascending or descending order.



Linear search: This is the simplest searching algorithm that checks each element in the list one by one until the target element is found.

For large data, linear search is not suitable.



Ex: To find birthday date of a person:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31




  1. minimum value = 1, maximum value = 31
    mid = (1+31)/2 = 16

  2. Then, consider minimum value as 17 (min = max+1)
    mid = (17+31)/2 = 24

  3. Now we should consider minimum value as 17, maximum value = mid - 1, then max = 23.



Ex 1: To find the key value




class Book{
public static void main(String[] args){
int [] array = {10,12,28,41,66,72,89};
int Key = 72;
int min = 0;
int max = array.length - 1;
while (min<=max){
int mid = (min+max)/2;
if (Key == array[mid]){
System.out.println("Key found at" + mid);
break;
}
else if (Key < array[mid]){
max = mid - 1;
}

else {
min = mid + 1;
}
}
}
}






Output:




Key found at 5







Why to use break statement: If the first condition itself satisfied, the a break statement can be used.



Ex 2: To check whether a given number is double digit




class Book{
public static void main(String[] args) {
int num = 1;

if (num >= 10 && num <= 99) {
System.out.println(" double-digit number.");
} else {
System.out.println("not a double-digit number.");
}
}
}






Output: not a double-digit number

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Binary Search in Java

Thematisch verwandte Begriffe: Binary, Search, Java · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94497 | jshERP through 3.6 fails to validate object ownership in by-id info, upd…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick