Search Algorithm
Joseph C. Lorilla
Linear Search - O(n)
Linear Search Code
Advantages of Linear Search
• Linear search can be used irrespective of whether the array is sorted
or not. It can be used on arrays of any data type.
• Does not require any additional memory.
• It is a well-suited algorithm for small datasets.
Drawbacks of Linear Search
• Linear search has a time complexity of O(N), which in turn makes it
slow for large datasets.
• Not suitable for large arrays.
Binary Search – O(log n)
Binary Search – O(log n)
Binary Search – O(log n)
Binary Search – O(log n)
Binary Search – O(log n)
Binary Search – O(log n)
Binary Search – O(log n)
Binary Search Code
Advantage of Binary Search
• Binary search is faster than linear search, especially for large arrays.
• More efficient than other searching algorithms with a similar time
complexity, such as interpolation search or exponential search.
• Binary search is well-suited for searching large datasets that are
stored in external memory, such as on a hard drive or in the cloud.
Disadvantage of Binary Search
• The array should be sorted.
• Binary search requires that the data structure being searched be
stored in contiguous memory locations.
• Binary search requires that the elements of the array be comparable,
meaning that they must be able to be ordered.
Application of Binary Search
• Binary search can be used as a building block for more complex
algorithms used in machine learning, such as algorithms for training
neural networks or finding the optimal hyperparameters for a model.
• It can be used for searching in computer graphics such as algorithms
for ray tracing or texture mapping.
• It can be used for searching a database.
Sorting Algorithm
Sorting Algorithm
Different Sorting Algorithms
• Bubble Sort
• Selection Sort
• Insertion Sort
• Merge Sort
• Quicksort
• Counting Sort
• Radix Sort
• Bucket Sort
• Heap Sort
• Shell Sort
Time Complexity of Sorting Algorithms
Stability of Sorting Algorithm
Stability of Sorting Algorithm
Stability of Sorting Algorithms
Bubble Sort
• Bubble sort is a sorting algorithm that compares two adjacent
elements and swaps them until they are in the intended order.
• Just like the movement of air bubbles in the water that rise up to the
surface, each element of the array move to the end in each iteration.
Therefore, it is called a bubble sort.
Bubble Sort Process
1. Starting from the first index, compare
the first and the second elements.
2. If the first element is greater than the
second element, they are swapped.
3. Now, compare the second and the
third elements. Swap them if they are
not in order
• The above process goes on until the last
element.
Bubble Sort

SearchAlgorithm.pdf

  • 1.
  • 2.
  • 3.
  • 4.
    Advantages of LinearSearch • Linear search can be used irrespective of whether the array is sorted or not. It can be used on arrays of any data type. • Does not require any additional memory. • It is a well-suited algorithm for small datasets.
  • 5.
    Drawbacks of LinearSearch • Linear search has a time complexity of O(N), which in turn makes it slow for large datasets. • Not suitable for large arrays.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
    Advantage of BinarySearch • Binary search is faster than linear search, especially for large arrays. • More efficient than other searching algorithms with a similar time complexity, such as interpolation search or exponential search. • Binary search is well-suited for searching large datasets that are stored in external memory, such as on a hard drive or in the cloud.
  • 15.
    Disadvantage of BinarySearch • The array should be sorted. • Binary search requires that the data structure being searched be stored in contiguous memory locations. • Binary search requires that the elements of the array be comparable, meaning that they must be able to be ordered.
  • 16.
    Application of BinarySearch • Binary search can be used as a building block for more complex algorithms used in machine learning, such as algorithms for training neural networks or finding the optimal hyperparameters for a model. • It can be used for searching in computer graphics such as algorithms for ray tracing or texture mapping. • It can be used for searching a database.
  • 17.
  • 18.
  • 19.
    Different Sorting Algorithms •Bubble Sort • Selection Sort • Insertion Sort • Merge Sort • Quicksort • Counting Sort • Radix Sort • Bucket Sort • Heap Sort • Shell Sort
  • 20.
    Time Complexity ofSorting Algorithms
  • 21.
  • 22.
  • 23.
  • 24.
    Bubble Sort • Bubblesort is a sorting algorithm that compares two adjacent elements and swaps them until they are in the intended order. • Just like the movement of air bubbles in the water that rise up to the surface, each element of the array move to the end in each iteration. Therefore, it is called a bubble sort.
  • 25.
    Bubble Sort Process 1.Starting from the first index, compare the first and the second elements. 2. If the first element is greater than the second element, they are swapped. 3. Now, compare the second and the third elements. Swap them if they are not in order • The above process goes on until the last element.
  • 26.