Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
cds-unit6-sorting

cds-unit6-sorting

Ratings: (0)|Views: 142|Likes:
Published by api-19957208

More info:

Published by: api-19957208 on Dec 03, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

UNIT \u2013 VI
Searching Techniques
Linear and binary search methods.
Sorting Methods

Exchange Sort
Selection Sort
Quick Sort
Tree Sort

Searching
Finding a given element in a list of elements.
Methods

Linear/Sequential Search
Binary/Logarithmic Search
Linear/Sequential Search
Simplest technique for searching, for a given
element in an unordered list of elements.
Scan each entry in the list in a sequential manner
until the desired element is found.
Function linear \u2013 search (K, N, X)
K Unloaded list with N elements.
X Element to be found
I Index
S1. [Initialise Search]
I\u21901

S2. [Search the list]
while (K[I]\u2260 X & I\u2264 N)
I\u2190 I+1 repeat S2

S3. [Successful Search?]

if I=N+1 then
print (\u2018Element found at positions\u2019)
return (0)

else print (\u2018Element found at positions\u2019)
return (I).
Time Complexity
Worst case
n+1 comparisons
Average case
(n+1)/2 comparisons
Time complexity is O(x).
Binary/Logarithmic Search
Prerequisite:
Ordered list of elements as the key on which search
is being made.
The middle entry of the list is located, and its key
value is examined.
If this value is same as the given element, search is
successful and stop.

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->