Overview
Learn algorithms with JavaScript.
Search Algorithms
Linear Search
An algorithm that compares data in a list or array sequentially from the beginning.
The process is repeated for the length of the array, and it stops when the target data is found. The further the target data is located towards the end, the slower the process becomes.
Binary Search
An algorithm that searches for data in a sorted list or array by narrowing down the search range based on comparisons with the median.
First, the median is calculated, and the comparison between the target data and the median is repeated until the start of the search range exceeds the end of the search range.
If the median is smaller than the target data, the start of the range is updated to median + 1. If the median is larger, the end of the range is updated to median - 1. It might seem confusing at first, but following the process step by step (1st iteration, 2nd iteration, 3rd iteration, etc.) will make it easier to understand.
Sorting Algorithms
Selection Sort
An algorithm that sorts data sequentially from the beginning.
This algorithm is also easier to understand if you follow the process step by step (1st iteration, 2nd iteration, 3rd iteration, etc.).
The process involves repeatedly comparing the first value with the values from the first + 1 to the last. If a smaller value is found, it replaces the first value. This process is repeated for the length of the array.
Bubble Sort
An algorithm that sorts data by comparing adjacent values and swapping them.