An algorithm is a finite collection of well defined steps
to solve
A particular problem. An algorithm Is a finite sequence
of instructions,
Logic, step by step process for solving a problem.
Sorting technique to arranging data in a
particular format. Sorting algorithm specifies
the
Way to arrange data in a particular order. Most
common are numerical or lexicograpical order.
Sorting is also used to represent data in more
readable formats.
Telephone Directory – Telephone directory keeps
telephone No. of people sorted on their
Names. So that names can be searched.
Dictionary – Dictionary keeps words in
alphabetical order so that searching of any work
becomes easy.
Bubble Sort is a simple sorting algorithm. This
sorting algorithm is comparison
Based algorithm in which each pair of
adjacent elements is compared & elements
Are swapped if they are not in order. This
algorithm is not suitable for large data
Sets as its average and worst case complexity.
We take an unsorted array for our example:
14 33 27 35 10
14
14
14
14
14
14
14
14
1433
33
33
27 33
27
27
27
35
35
35
35
10
10
10
10
27
27
27
27
27
33
33
33
33
10
35
35
35
10
35
10
10
10
35
33
14
14
10
10
27
27 33
33
35
35
This is a in-place comparison based sorting
algorithm. Here, a sub-list is always sorted.
For example, the lower part of an array is
maintained to be sorted. The array is
searched
Sequentially and unsorted items are moved
and inserted into sorted sub-list.
14 33 27 3510
14
14
14
14
14
14
14
14
1433
33
33
33 27
27
27
27
10
10
10
10
35
35
35
35
27
27
27
27
27
33
33
33
10
10
10
10
10
33
35
35
35
35
35
33
We take an unsorted array for our example.
14
14
14
10
10
10
27
27
27
33
33
33
35
35
35
Selection sort is a simple sorting algorithm .
This sorting algorithm is a in-place
Comparison based algorithm in which the
list is divided into two parts, sorted
Part at left end and unsorted part at right
end. intially end sorted part is empty
And unsorted part is entire list.
We take the depicted array for our example :
14 33 27 10 35
14
10
10
10
10
10
10
10
1033
33
33
33 27
27
27
27
10
14
14
14
35
35
35
35
14
14
14
14
14
27
27
27
19
19
33
33
33
33
35
35
35
35
35
33
19 19
19
19
27
27
19
19
19
19
10
10
10
10
10
14
14
14
14
14
19
19
19
19
19
27
27
27
27
33
35
35
35
33
27
33
33
33
35
35
Merge Sort is a sorting technique based
on divide & conquer technique. With
worst case time complexity being
respected algorithms. Merge Sort first
divides the array into equal halves &
Then combines them in a sorted manner.
To understand merge sort, we take an unsorted array as depicted below.
14 33 27 10 35 19 42 44
35 19 42 4414 33 27 10
14 33 27 10 35 19 42 44
14 33 27 10 35 19 42 44
14 33 10 27 19 35 42 44
Combine Them into another list
10 14 33 27 19 35 42 44
After final merging, the list should look like this :
10 14 19 27 33 35 42 44
Quick sort is a highly efficient sorting
algorithm and is based on partitioning of array
Of data into smaller arrays. The quick sort
partitions an array and then calls itself
recursively twice to sort the resulting two sub
arrays. This algorithm is quite efficient for
large size data sets its average & worst case
complexity are of 0.
The below given image representation explains how to find
pivot value in the way.
10 42 35 33 31 27 26 19 14 44
10 14 19 26 27 31 33 35 42 44
Linear search is a very simple search algorithm. In
this type search, a sequential
search is made over all items one by one. Every
items is checked & if a match founds them
Particular item is returned otherwise search
continues till the end of the data collection.
Suppose that we find 33 in array element
Linear Search
10 14 19 26 27 31 33 35 42 44
=
33
10 14 19 26 27 31 33 35 42 44
Binary search is a fast search algorithm
with run-time complexity of 0 (log n) .
This search algorithm works on the
principle of divide & compare. For this
algorithm to work properly the data
collection should be in sorted form.
The below given is our sorted array and assume that we need to search location
Of value 31 using binary search.
10 14 19 26 27 31 33 35 42 44
0 1 2 3 4 5 6 7 8 9
First, we shall determine the half of the array by using this formula-
Mid = low + (high – low) / 2
Here it is, 0+(9-0) / 2 = 4(integer value of 4.5). So 4 is the mid of array.
10 14 19 26 27 31 33 35 42 44
0 1 2 3 4 5 6 7 8 9
We change our low to mid + 1 and final the new value again.
Low = mid + 1
Mid = low + (high – low) / 2
Our new mid 7 now. We compare the value stored at location 7 with our target value 31.
10 14 19 26 27 31 33 35 42 44
0 1 2 3 4 5 6 7 8 9
The value stored at location 7 is not match, rather it is less that what we are looking for.
So the value must be in lower part from this location.
10 14 19 26 27 31 33 35 42 44
0 1 2 3 4 5 6 7 8 9
So we calculate the mid again. This time is 5.
10 14 19 26 27 31 33 35 42 44
0 1 2 3 4 5 6 7 8 9
We compare the value stored ad location 5 with our target value. We find
that is a match.
10 14 19 26 27 31 33 35 42 44
0 1 2 3 4 5 6 7 8 9
We conclude that the target value 31 is stored at location 5.
End Of The Moment

PPT On Sorting And Searching Concepts In Data Structure | In Programming Language |

  • 2.
    An algorithm isa finite collection of well defined steps to solve A particular problem. An algorithm Is a finite sequence of instructions, Logic, step by step process for solving a problem.
  • 5.
    Sorting technique toarranging data in a particular format. Sorting algorithm specifies the Way to arrange data in a particular order. Most common are numerical or lexicograpical order. Sorting is also used to represent data in more readable formats.
  • 6.
    Telephone Directory –Telephone directory keeps telephone No. of people sorted on their Names. So that names can be searched. Dictionary – Dictionary keeps words in alphabetical order so that searching of any work becomes easy.
  • 7.
    Bubble Sort isa simple sorting algorithm. This sorting algorithm is comparison Based algorithm in which each pair of adjacent elements is compared & elements Are swapped if they are not in order. This algorithm is not suitable for large data Sets as its average and worst case complexity.
  • 8.
    We take anunsorted array for our example: 14 33 27 35 10 14 14 14 14 14 14 14 14 1433 33 33 27 33 27 27 27 35 35 35 35 10 10 10 10 27 27 27 27 27 33 33 33 33 10 35 35 35 10 35 10 10 10 35 33
  • 9.
  • 10.
    This is ain-place comparison based sorting algorithm. Here, a sub-list is always sorted. For example, the lower part of an array is maintained to be sorted. The array is searched Sequentially and unsorted items are moved and inserted into sorted sub-list.
  • 11.
    14 33 273510 14 14 14 14 14 14 14 14 1433 33 33 33 27 27 27 27 10 10 10 10 35 35 35 35 27 27 27 27 27 33 33 33 10 10 10 10 10 33 35 35 35 35 35 33 We take an unsorted array for our example.
  • 12.
  • 13.
    Selection sort isa simple sorting algorithm . This sorting algorithm is a in-place Comparison based algorithm in which the list is divided into two parts, sorted Part at left end and unsorted part at right end. intially end sorted part is empty And unsorted part is entire list.
  • 14.
    We take thedepicted array for our example : 14 33 27 10 35 14 10 10 10 10 10 10 10 1033 33 33 33 27 27 27 27 10 14 14 14 35 35 35 35 14 14 14 14 14 27 27 27 19 19 33 33 33 33 35 35 35 35 35 33 19 19 19 19 27 27 19 19 19 19
  • 15.
  • 16.
    Merge Sort isa sorting technique based on divide & conquer technique. With worst case time complexity being respected algorithms. Merge Sort first divides the array into equal halves & Then combines them in a sorted manner.
  • 17.
    To understand mergesort, we take an unsorted array as depicted below. 14 33 27 10 35 19 42 44 35 19 42 4414 33 27 10 14 33 27 10 35 19 42 44 14 33 27 10 35 19 42 44 14 33 10 27 19 35 42 44 Combine Them into another list
  • 18.
    10 14 3327 19 35 42 44 After final merging, the list should look like this : 10 14 19 27 33 35 42 44
  • 19.
    Quick sort isa highly efficient sorting algorithm and is based on partitioning of array Of data into smaller arrays. The quick sort partitions an array and then calls itself recursively twice to sort the resulting two sub arrays. This algorithm is quite efficient for large size data sets its average & worst case complexity are of 0.
  • 20.
    The below givenimage representation explains how to find pivot value in the way. 10 42 35 33 31 27 26 19 14 44 10 14 19 26 27 31 33 35 42 44
  • 22.
    Linear search isa very simple search algorithm. In this type search, a sequential search is made over all items one by one. Every items is checked & if a match founds them Particular item is returned otherwise search continues till the end of the data collection.
  • 23.
    Suppose that wefind 33 in array element Linear Search 10 14 19 26 27 31 33 35 42 44 = 33 10 14 19 26 27 31 33 35 42 44
  • 24.
    Binary search isa fast search algorithm with run-time complexity of 0 (log n) . This search algorithm works on the principle of divide & compare. For this algorithm to work properly the data collection should be in sorted form.
  • 25.
    The below givenis our sorted array and assume that we need to search location Of value 31 using binary search. 10 14 19 26 27 31 33 35 42 44 0 1 2 3 4 5 6 7 8 9 First, we shall determine the half of the array by using this formula- Mid = low + (high – low) / 2 Here it is, 0+(9-0) / 2 = 4(integer value of 4.5). So 4 is the mid of array. 10 14 19 26 27 31 33 35 42 44 0 1 2 3 4 5 6 7 8 9
  • 26.
    We change ourlow to mid + 1 and final the new value again. Low = mid + 1 Mid = low + (high – low) / 2 Our new mid 7 now. We compare the value stored at location 7 with our target value 31. 10 14 19 26 27 31 33 35 42 44 0 1 2 3 4 5 6 7 8 9 The value stored at location 7 is not match, rather it is less that what we are looking for. So the value must be in lower part from this location. 10 14 19 26 27 31 33 35 42 44 0 1 2 3 4 5 6 7 8 9
  • 27.
    So we calculatethe mid again. This time is 5. 10 14 19 26 27 31 33 35 42 44 0 1 2 3 4 5 6 7 8 9 We compare the value stored ad location 5 with our target value. We find that is a match. 10 14 19 26 27 31 33 35 42 44 0 1 2 3 4 5 6 7 8 9 We conclude that the target value 31 is stored at location 5.
  • 29.
    End Of TheMoment