2. SEARCHING
Searching is the process of determining whether or
not a given value exists in a data structure or a
storage media.
linear search and binary search.
3. LINEAR SEARCH
The linear (or sequential) search algorithm on an
array is:
Sequentially scan the array, comparing each array item with the searched
value.
If a match is found; return the index of the matched element; otherwise
return –1.
Note: linear search can be applied to both sorted and
unsorted arrays.
4. FEATURES OF LINEAR SEARCH
It is used for unsorted and unordered small list of
elements.
It has a time complexity of O(n), which means the
time is linearly dependent on the number of
elements, which is not bad, but not that good too.
It has a very simple implementation.
6. APPLICATIONS OF LINEAR SEARCH
Used to find the desired element from the collection
of data when the dataset is small
The searching operations is less than 100 items
7. BINARY SEARCH
An algorithm to solve this task looks at the
middle of the array or array segment first
If the value looked for is smaller than the
value in the middle of the array
Then the second half of the array or array
segment can be ignored
This strategy is then applied to the first half of the
array or array segment
8. BINARY SEARCH (CONT.,)
If the value looked for is larger than the value in the
middle of the array or array segment
Then the first half of the array or array segment can be
ignored
This strategy is then applied to the second half of the array
or array segment
If the value looked for is at the middle of the array
or array segment, then it has been found
If the entire array (or array segment) has been
searched in this way without finding the value, then
it is not in the array
9. EFFICIENCY OF BINARY SEARCH
The binary search algorithm is extremely fast
compared to an algorithm that tries all array
elements in order
About half the array is eliminated from consideration
right at the start
Then a quarter of the array, then an eighth of the array,
and so forth
11. APPLICATIONS OF BINARY SEARCH
The binary search algorithm is used in the libraries
of Java, C++, etc
It is used in another additional program like finding
the smallest element or largest element in the array
It is used to implement a dictionary
12. SORTING METHODS
Sorting Algorithms are methods of reorganizing a
large number of items into some specific order such
as highest to lowest, or vice-versa, or even in some
alphabetical order.
These algorithms take an input list, processes it
(i.e, performs some operations on it) and produce
the sorted list.
The most common example we experience every
day is sorting clothes or other items on an e-
commerce website either by lowest-price to highest,
or list by popularity, or some other order.
14. BUBBLE SORT
Bubble sort, also referred to as comparison sort
It is a simple sorting algorithm that repeatedly goes
through the list, compares adjacent elements and
swaps them if they are in the wrong order.
This is the most simplest algorithm and inefficient at
the same time.
https://www.interviewbit.com/tutorial/bubble-sort/
15. SELECTION SORT
Selection sort is a simple comparison-based sorting
algorithm
Steps to be followed
Pick the minimum element from the unsorted
subarray.
Swap it with the leftmost element of the unsorted
subarray.
Now the leftmost element of unsorted subarray
becomes a part (rightmost) of sorted subarray and
will not be a part of unsorted subarray.
https://www.interviewbit.com/tutorial/selection-sort/
16. INSERTION SORT
Insertion sort is the sorting mechanism where the
sorted array is built having one item at a time.
The array elements are compared with each other
sequentially and then arranged simultaneously in
some particular order.
This sort works on the principle of inserting an
element at a particular position, hence the name
Insertion Sort.
https://www.interviewbit.com/tutorial/insertion-sort-
algorithm/
17. SHELL SORT
Shell sort is a highly efficient sorting algorithm and is
based on insertion sort algorithm.
This algorithm avoids large shifts as in case of insertion
sort, if the smaller value is to the far right and has to be
moved to the far left.
Steps to be followed
Step 1 − Initialize the value of h.
Step 2 − Divide the list into smaller sub-list of equal
interval h.
Step 3 − Sort these sub-lists using insertion sort.
Step 3 − Repeat until complete list is sorted.
https://www.tutorialspoint.com/data_structures_algorith
ms/shell_sort_algorithm.htm
18. RADIX SORT
Radix sort is one of the sorting algorithms used
to sort a list of integer numbers in order.
In radix sort algorithm, a list of integer numbers will
be sorted based on the digits of individual numbers.
Sorting is performed from least significant digit to
the most significant digit.
20. QUICK SORT
It is one of the most efficient sorting algorithms and
is based on the splitting of an array (partition) into
smaller ones and swapping (exchange) based on
the comparison with 'pivot' element selected.
Due to this, quick sort is also called as "Partition
Exchange" sort.
Steps to be followed:
Step 1 − Make any element as pivot
Step 2 − Partition the array on the basis of pivot
Step 3 − Apply quick sort on left partition
recursively
Step 4 − Apply quick sort on right partition
recursively
22. HEAP SORT
Heap sort is a comparison-based sorting
technique based on Binary Heap data structure
https://www.youtube.com/watch?v=MtQL_ll5KhQ
There are two kinds of heaps: min-heap and max-
heap.
In min-heap parents nodes are smaller than
children nodes (the root node is smallest), while in
max-heap it is opposite (the root node is largest).
23. MERGE SORT
Merge sort is one of the most efficient sorting
algorithms. It works on the principle of Divide and
Conquer.
Merge sort repeatedly breaks down a list into
several sublists until each sublist consists of a
single element and merging those sublists in a
manner that results into a sorted list.
https://www.interviewbit.com/tutorial/merge-sort-
algorithm/
24. COMPARISON OF SORTING ALOGORITHMS
In a comparison based sorting algorithms, we
compare elements of an array with each other to
determines which of two elements should occur first
in the final sorted list.
All comparison-based sorting algorithms have a
complexity lower bound of nlogn.