Searching
§ Searching
is the process of finding the location of the specified element in the list.
§
The specified element is called the search
key.
§
F the process of searching finds a match
of the search key with a list element value, the search is said to be
successful; otherwise it is unsuccessful.
§
The two most commonly used search
techniques are:
o
Sequential search / Linear search
o
Binary search
§
Sequential
Search / Linear Search
Sorting
§ Sorting
is the process of arranging elements in the list according to their values, in
ascending or descending order.
§
A sorted list is called an ordered list.
§
Sorted list are especially important in
list searching because they facilitate rapid search operations. Many sorting
techniques are available and among them, the three most important are:
o
Bubble sort
o
Selection sort
o
Insertion sort
§
Bubble
Sort
o
In bubble sort, each element is compared
with its adjacent elements. If the first element is larger than the second one
then the positions of the elements are interchanged, otherwise it is not
changed.
o
Then the next element is compared with its
adjacent element and the same process is repeated for all the elements of the
array.
o
Example: List (26,39,6,35,9)
Key
number
|
Swapping
|
number
|
No swap
|
Pass
1
|
26
|
26
|
26
|
26
|
39
|
6
|
6
|
6
|
|
6
|
39
|
35
|
35
|
|
35
|
35
|
39
|
9
|
|
9
|
9
|
9
|
39
|
Pass
2
|
6
|
6
|
6
|
6
|
26
|
26
|
26
|
26
|
|
35
|
35
|
9
|
9
|
|
9
|
9
|
35
|
35
|
|
39
|
39
|
39
|
39
|
Pass
3
|
6
|
6
|
6
|
6
|
26
|
9
|
9
|
9
|
|
9
|
26
|
26
|
26
|
|
35
|
35
|
35
|
35
|
|
39
|
39
|
39
|
39
|
Pass
4
|
6
|
6
|
6
|
6
|
9
|
9
|
9
|
9
|
|
26
|
26
|
26
|
26
|
|
35
|
35
|
35
|
35
|
|
39
|
39
|
39
|
39
|
Pass
5
|
6
|
6
|
6
|
6
|
9
|
9
|
9
|
9
|
|
26
|
26
|
26
|
26
|
|
35
|
35
|
35
|
35
|
|
39
|
39
|
39
|
39
|
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.