Below you will find pages that utilize the taxonomy term “ALGORITHM”
Posts
Backtracking
INFO It’s an Algorithm to permute string. Usefull to find all the possible permutations
EXAMPLE Steps Create a function which take the string, the first index and the last index: If start and end index are the same, end of the algorithm (print or return depends on what you wants) Otherwise, loop on each index between start and end: Swap string at index start and string at index i of loop Call the function with as first index the first index + 1 Swap again string at index start and string at index i of loop Code #include <iostream> #include <string> void backtrack(std::string &s, int idx, int N) { if (idx == N) std::cout << s << std::endl; else { for (int i = idx; i <= N; i++) { std::swap(s[idx], s[i]); backtrack(s, idx + 1, N); // Reset std::swap(s[idx], s[i]); } } } int main(int ac, char *av[]) { std::string s = "ABC"; int n = s.
read morePosts
Binary Search
INFO Binary Search called “Recherche Dichotomique” in French is a searching algorithm used in a sorted array by repeatedly dividing the search interval in half.
APPROACH Find the Exact Value class Solution { public: int search(vector<int> &nums, int target) { int leftPtr = 0; int rightPtr = nums.size() - 1; while (leftPtr <= rightPtr) { int m = (leftPtr + rightPtr) / 2; if (nums[m] == target) return m; else if (nums[m] < target) leftPtr = m + 1; else rightPtr = m - 1; } return -1; } }; Find Upper bound class Solution { public: int search(vector<int> &nums, int target) { int leftPtr = 0; int rightPtr = nums.
read morePosts
Bitwise Operation
Logically, a bit-to-bit operation is a calculation manipulating the data directly at the level of the bits, according to a Boolean arithmetic
Use in Programming Advanced to be blazingly fast
OPERATORS
read morePosts
Breadth-first Search
INFO The width path algorithm allows the path of a graph or a tree as follows: we start by exploring a source node, then its successors, then the unexplored successors of successors, etc
read morePosts
Bucket Sort
BUCKET SORT Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm.
Pseudo Code function bucketSort(array, k) is buckets = new array of k empty lists M = 1 + the maximum key value in the array for i = 0 to length(array) do insert array[i] into buckets[floor(k × array[i] / M)] for i = 0 to k do nextSort(buckets[i]) return the concatenation of buckets[0], .
read morePosts
Depth-first Search
INFO The deep path algorithm is a tree path algorithm, and more generally a graph path. He naturally describes himself in a recursive way. Its simplest application is to determine if there is a path from one summit to another
read morePosts
Dynamic Programming
It’s an advanced Algorithm In computer science, dynamic programming is an algorithmic method for solving optimization problems. The concept was introduced in the early 1950s by Richard Bellman. At the time, the term « programming » means planning and scheduling
The most used techniques for dynamic programming are:
read morePosts
Two Pointers
INFO The two pointers is a searching algorithm if you want at the same time:
Search two elements in an array Search and do something in an array Keep in mind an index when moving another Ect…
read more