Binary Search in C Programming - Amino.dk
på Amino
Bliv gratis medlem på Amino
 

Køb et Amino Sponsorlink

 

Nye ekspertblog-indlæg Hjælp & support til Amino services

Læs flere ekspertindlæg
 

Top karmaliste (30 dage)

De flinkeste Amino’er der hjælper mest med "Information om & fra Amino "

 

Binary Search in C Programming

Side 1 ud af 1 (3 indlæg)
Amino-karma 13
Tilmeldt 24. maj 19
Indlæg ialt: 3


Skrevet 16-09-2019 kl. 11:30

Hello Everyone,

I want to know how exactly binary search works in C programming and what the exact pros are. When I was searching on Google ye have found this binary search in C . where clearly defined about the whole process but I am confused about If I select 1 to 10 numbers and find the position of 7th number. So what is the exact step by step process of binary search work to find the position of 7th number?

Amino-karma 1.207
Fra Esbjerg
Tilmeldt 2. jul 12
Indlæg ialt: 268

Anders Jytzler
Fra Hype Media
Skrevet 16-09-2019 kl. 11:46

I don't think this is the most relevant forum to ask such a question. I think you would get more help if you tried the most relevant stack echange forum: https://stackexchange.com/sites

Anders Jytzler fra webbureau www.hype-media.dk

Amino-karma 1.603
Fra Frederiksberg
Tilmeldt 5. nov 12
Indlæg ialt: 363

Nicolai Lundgaard
Skrevet 16-09-2019 kl. 13:10

How it's done depends on the data structure. It can be a sorted array or a binary tree. The trick is, that you rule out half of the search space for each iteration, hence you will get a time complexity of Log(N).

If your data is stored in a sorted array then you read the value in the middle of the array. If your search value is higher than the middle value, you can discard the left part of the array, and repeat the function on the right side of the middle. Continue until you find the element, or no elements are left meaning the value is not present.

For binary trees each node has up to 2 child nodes. If it is structured in a way where e.g. the left sub tree only contains nodes that are smaller than the value, end the right side only contains nodes with higher values, you can discard half of the tree in each iteration.

Side 1 ud af 1 (3 indlæg)

RSS-feed
 
Besøg vores samarbejdspartnere :