Algorithms are step-by-step procedures or formulas for solving problems or performing tasks. In computer science and mathematics, algorithms are used to manipulate data, perform calculations, and automate reasoning.
Types of Algorithms:
- Cipher
- Caesar - shifts the letters in the plaintext by a fixed number.
- Character Frequency - uses the frequency of characters in the plaintext to encrypt it.
- Distributed Secret - uses a secret key to encrypt the plaintext.
- Playfair - uses a 5x5 grid of letters to encrypt the plaintext.
- Simple Replacement - replaces each letter in the plaintext with another letter.
- Hamming Code (with UI) - detects and corrects errors in the transmitted data.
- Search
- Linear -
O(n)- iterates through each element in the array from the start to the end. - Binary -
O(log n)- searches for an element in a sorted array by dividing the array in half at each step.
- Linear -
- Sort
- Selection -
O(n^2)- selects the smallest (or biggest) element from the unsorted portion of the array and swaps it with the first (or last) unsorted element. - Insertion -
O(n^2)- builds the sorted array one element at a time by comparing each element with the rest of the array. - Bubble -
O(n^2)- compares each element with the next one and swaps them if they are in the wrong order. - Quick -
O(n log n)- divides the array into two subarrays and sorts them recursively. - Merge -
O(n log n)- divides the array into two subarrays and merges them recursively.
- Selection -