10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

step 2: [element not found]<br />

return (0)<br />

exit<br />

EXAMPLE OF LINEAR SEARCH<br />

Consider an array ‘A’ (15, 11, 14, 13, 18, and 21)<br />

Here X=13 to be searched<br />

BINARY SEARCH<br />

Is x=A [1] = False<br />

Is x=A [2] = False<br />

Is x=A [3] = False<br />

Is x=A [4] = True<br />

Element x=13 found at position<br />

The Binary Search algorithm is a method of searching an ordered array for a<br />

single element by cutting the array in half with each pass. The trick is to pick a<br />

midpoint near the center of the array, compare the data at that point with the<br />

data being searched and then responding to one of three possible conditions:<br />

the data is found, the data at the midpoint is greater than the data being<br />

searched for, or the data at the midpoint is less than the data being searched<br />

for.<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 154 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!