The Hopcroft–Karp algorithm is an algorithm that takes as input a bipartite graph and produces as output a maximum cardinality matching, it runs in O(E√V) time in worst case.
-
+
Bipartite graph
A bipartite graph (or bigraph) is a graph whose vertices can be divided into two disjoint and independent sets U and V such that every edge connects a vertex in U to one in V. Vertex sets U and V are usually called the parts of the graph. Equivalently, a bipartite graph is a graph that does not contain any odd-length cycles.
-
+
Matching and Not-Matching edges
Given a matching M, edges that are part of matching are called Matching edges and edges that are not part of M (or connect free nodes) are called Not-Matching edges.
-
+
Maximum cardinality matching
Given a bipartite graphs G = ( V = ( X , Y ) , E ) whose partition has the parts X and Y, with E denoting the edges of the graph, the goal is to find a matching with as many edges as possible. Equivalently, a matching that covers as many vertices as possible.
-
+
Augmenting paths
Given a matching M, an augmenting path is an alternating path that starts from and ends on free vertices. All single edge paths that start and end with free vertices are augmenting paths.
-
+
Concept
A matching M is not maximum if there exists an augmenting path. It is also true other way, i.e, a matching is maximum if no augmenting path exists.
-
+
Algorithm
1) Initialize the Maximal Matching M as empty. 2) While there exists an Augmenting Path P Remove matching edges of P from M and add not-matching edges of P to M (This increases size of M by 1 as P starts and ends with a free vertex i.e. a node that is not part of matching.) 3) Return M.
An implementation of a median calculation of a sliding window along a data stream.
Given a stream of integers, the algorithm calculates the median of a fixed size window at the back of the stream. The leading time complexity of this algorithm is O(log(N), and it is inspired by the known algorithm to [find median from (infinite) data stream](https://www.tutorialcup.com/interview/algorithm/find-median-from-data-stream.htm), with the proper modifications to account for the finite window size for which the median is requested
-
+
Algorithm
The sliding window is managed by a list, which guarantees O(1) for both pushing and popping. Each new value is pushed to the window back, while a value from the front of the window is popped. In addition, the algorithm manages a multi-value binary search tree (BST), implemented by std::multiset. For each new value that is inserted into the window, it is also inserted to the BST. When a value is popped from the window, it is also erased from the BST. Both insertion and erasion to/from the BST are O(logN) in time, with N the size of the window. Finally, the algorithm keeps a pointer to the root of the BST, and updates its position whenever values are inserted or erased to/from BST. The root of the tree is the median! Hence, median retrieval is always O(1)
Time complexity: O(logN). Space complexity: O(N). N - size of window
The working principle of the Bubble sort algorithm.
Bubble sort is a simple sorting algorithm used to rearrange a set of ascending or descending order elements. Bubble sort gets its name from the fact that data "bubbles" to the top of the dataset.
-
+
Algorithm
What is Swap?
Swapping two numbers means that we interchange their values. Often, an additional variable is required for this operation. This is further illustrated in the following:
An implementation for finding the Inorder successor of a binary search tree Inorder successor of a node is the next node in Inorder traversal of the Binary Tree. Inorder Successor is NULL for the last node in Inorder traversal.
-
+
Case 1: The given node has the right node/subtree
* In this case, the left-most deepest node in the right subtree will
come just after the given node as we go to left deep in inorder.
Go deep to left most node in right subtree. OR, we can also say in case if BST, find the minimum of the subtree for a given node.
-
+
Case 2: The given node does not have a right node/subtree
-
+
Method 1: Use parent pointer (store the address of parent nodes)
If a node does not have the right subtree, and we already visited the node itself, then the next node will be its parent node according to inorder traversal, and if we are going to parent from left, then the parent would be unvisited.
In other words, go to the nearest ancestor for which given node would be in left subtree.
-
+
Method 2: Search from the root node
In case if there is no link from a child node to the parent node, we need to walk down the tree starting from the root node to the given node, by doing so, we are visiting every ancestor of the given node.
Implementation to check whether a number is a power of 2 or not.
This algorithm uses bit manipulation to check if a number is a power of 2 or not.
-
+
Algorithm
Let the input number be n, then the bitwise and between n and n-1 will let us know whether the number is power of 2 or not
For Example, If N= 32 then N-1 is 31, if we perform bitwise and of these two numbers then the result will be zero, which indicates that it is the power of 2 If N=23 then N-1 is 22, if we perform bitwise and of these two numbers then the result will not be zero , which indicates that it is not the power of 2
Note
This implementation is better than naive recursive or iterative approach.
Given a set of points in the plane. the convex hull of the set is the smallest convex polygon that contains all the points of it.
-
+
Algorithm
The idea of Jarvis’s Algorithm is simple, we start from the leftmost point (or point with minimum x coordinate value) and we keep wrapping points in counterclockwise direction.
The idea is to use orientation() here. Next point is selected as the point that beats all other points at counterclockwise orientation, i.e., next point is q if for any other point r, we have “orientation(p, q, r) = counterclockwise”.
Implementation of the Selection sort implementation using recursion.
The selection sort algorithm divides the input list into two parts: a sorted sublist of items which is built up from left to right at the front (left) of the list, and a sublist of the remaining unsorted items that occupy the rest of the list. Initially, the sorted sublist is empty, and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on the sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.
-
+
Implementation
FindMinIndex This function finds the minimum element of the array(list) recursively by simply comparing the minimum element of array reduced size by 1 and compares it to the last element of the array to find the minimum of the whole array.
SelectionSortRecursive Just like selection sort, it divides the list into two parts (i.e.: sorted and unsorted) and finds the minimum of the unsorted array. By calling the FindMinIndex function, it swaps the minimum element with the first element of the list, and then solves recursively for the remaining unsorted list.
Takes the input of Linearly Independent Vectors, returns vectors orthogonal to each other.
-
+
Algorithm
Take the first vector of given LI vectors as first vector of Orthogonal vectors. Take projection of second input vector on the first vector of Orthogonal vector and subtract it from the 2nd LI vector. Take projection of third vector on the second vector of Othogonal vectors and subtract it from the 3rd LI vector. Keep repeating the above process until all the vectors in the given input array are exhausted.
For Example: In R2, Input LI Vectors={(3,1),(2,2)} then Orthogonal Vectors= {(3, 1),(-0.4, 1.2)}
Sublist search is used to detect a presence of one list in another list.
Suppose we have a single-node list (let's say the first list), and we want to ensure that the list is present in another list (let's say the second list), then we can perform the sublist search to find it.
For instance, the first list contains these elements: 23 -> 30 -> 41, and the second list contains these elements: 10 -> 15 -> 23 -> 30 -> 41 -> 49. At a glance, we see that the first list presents in the second list.
-
+
Working
The sublist search algorithm works by comparing the first element of the first list with the first element of the second list.
However MD5 has be know to be cryptographically weak for quite some time, yet it is still widely used. This weakness was exploited by the Flame Malware in 2012
-
+
Algorithm
First of all, all values are expected to be in little endian. This is especially important when using part of the bytestring as an integer.
The first step of the algorithm is to pad the message for its length to be a multiple of 64 (bytes). This is done by first adding 0x80 (10000000) and then only zeroes until the last 8 bytes must be filled, where then the 64 bit size of the input will be added
In computer science, bogosort (also known as permutation sort, stupid sort, slowsort, shotgun sort, random sort, monkey sort, bobosort or shuffle sort) is a highly inefficient sorting algorithm based on the generate and test paradigm. Two versions of this algorithm exist: a deterministic version that enumerates all permutations until it hits a sorted one, and a randomized version that randomly permutes its input.Randomized version is implemented here.
Given a rod of length n inches and an array of prices that contains prices of all pieces of size<=n. Determine the maximum profit obtainable by cutting up the rod and selling the pieces.
-
+
Algorithm
The idea is to break the given rod into every smaller piece as possible and then check profit for each piece, by calculating maximum profit for smaller pieces we will build the solution for larger pieces in bottom-up manner.
SHA-1 is a cryptographic hash function that was developped by the NSA 1995. SHA-1 is not considered secure since around 2010.
-
+
Algorithm
The first step of the algorithm is to pad the message for its length to be a multiple of 64 (bytes). This is done by first adding 0x80 (10000000) and then only zeroes until the last 8 bytes must be filled, where then the 64 bit size of the input will be added
Once this is done, the algo breaks down this padded message into 64 bytes chunks. Each chunk is used for one round, a round breaks the chunk into 16 blocks of 4 bytes. These 16 blocks are then extended to 80 blocks using XOR operations on existing blocks (see code for more details). The algorithm will then update its 160-bit state (here represented used 5 32-bits integer) using partial hashes computed using special functions on the blocks previously built. Please take a look at the wikipedia article for more precision on these operations
Note
This is a simple implementation for a byte string but some implmenetations can work on bytestream, messages of unknown length.
Create a Stack that will store the Node of Tree. Push the root node into the stack. Save the root into the variabe named as current, and pop and elemnt from the stack. Store the data of current into the result array, and start traversing from it. Push both the child node of the current node into the stack, first right child then left child. Repeat the same set of steps untill the Stack becomes empty. And return the result array as the preorder traversal of a tree.
-
+
Iterative Postorder Traversal of a tree
Create a Stack that will store the Node of Tree. Push the root node into the stack. Save the root into the variabe named as current, and pop and elemnt from the stack. Store the data of current into the result array, and start traversing from it. Push both the child node of the current node into the stack, first left child then right child. Repeat the same set of steps untill the Stack becomes empty. Now reverse the result array and then return it to the calling function as a postorder traversal of a tree.
-
+
Iterative Inorder Traversal of a tree
Create a Stack that will store the Node of Tree. Push the root node into the stack. Save the root into the variabe named as current. Now iterate and take the current to the extreme left of the tree by traversing only to its left. Pop the elemnt from the stack and assign it to the current. Store the data of current into the result array. Repeat the same set of steps until the Stack becomes empty or the current becomes NULL. And return the result array as the inorder traversal of a tree.
Given two strings str1 & str2 and we have to calculate the minimum number of operations (Insert, Remove, Replace) required to convert str1 to str2.
-
+
Algorithm
We will solve this problem using Naive recursion. But as we are approaching with a DP solution. So, we will take a DP array to store the solution of all sub-problems so that we don't have to perform recursion again and again. Now to solve the problem, We can traverse all characters from either right side of the strings or left side. Suppose we will do it from the right side. So, there are two possibilities for every pair of characters being traversed.
If the last characters of two strings are the same, Ignore the characters and get the count for the remaining string. So, we get the solution for lengths m-1 and n-1 in a DP array.
Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. In other words, given two integer arrays val[0..n-1] and wt[0..n-1] which represent values and weights associated with n items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item or don’t pick it (0-1 property)
-
+
Algorithm
The idea is to consider all subsets of items and calculate the total weight and value of all subsets. Consider the only subsets whose total weight is smaller than W. From all such subsets, pick the maximum value subset.
Kadane algorithm is used to find the maximum sum subarray in an array and maximum sum subarray problem is the task of finding a contiguous subarray with the largest sum
-
+
Algorithm
The simple idea of the algorithm is to search for all positive contiguous segments of the array and keep track of maximum sum contiguous segment among all positive segments(curr_sum is used for this) Each time we get a positive sum we compare it with max_sum and update max_sum if it is greater than curr_sum
Given a recurrence relation; evaluate the value of nth term. For e.g., For fibonacci series, recurrence series is f(n) = f(n-1) + f(n-2) where f(0) = 0 and f(1) = 1. Note that the method used only demonstrates recurrence relation with one variable (n), unlike nCr problem, since it has two (n, r)
-
+
Algorithm
This problem can be solved using matrix exponentiation method.
vector< tuple< S, T, E, double, double, double > > FCFS< S, T, E >::scheduleForFcfs
+
(
+
)
+
+
+
+
+
+inline
+
+
+
+
+
Algorithm for scheduling CPU processes according to the First Come First Serve(FCFS) scheduling algorithm.
+
FCFS is a non-preemptive algorithm in which the process which arrives first gets executed first. If two or more processes arrive together then the process with smaller process ID runs first (each process has a unique proces ID).
+
I used a min priority queue of tuples to accomplish this task. The processes are ordered by their arrival times. If arrival times of some processes are equal, then they are ordered by their process ID.
+
Returns
void
+
154 {
+
155// Variable to keep track of time elapsed so far
Priority queue of schedules(stored as tuples) of processes. In each tuple 1st element: Process ID 2nd element: Arrival Time 3rd element: Burst time 4th element: Completion time 5th element: Turnaround time 6th element: Waiting time
+
+
+
+The documentation for this class was generated from the following file:
FCFS is a non-preemptive CPU scheduling algorithm in which whichever process arrives first, gets executed first. If two or more processes arrive simultaneously, the process with smaller process ID gets executed first. https://bit.ly/3ABNXOCPratyush Vatsa
Function to be used for testing purposes. This function guarantees the correct solution for FCFS scheduling algorithm.
+
Parameters
+
+
input
the input data
+
+
+
+
Sorts the input vector according to arrival time. Processes whose arrival times are same get sorted according to process ID For each process, completion time, turnaround time and completion time are calculated, inserted in a tuple, which is added to the vector result.
Returns
A vector of tuples consisting of process ID, arrival time, burst time, completion time, turnaround time and waiting time for each process.
The direction ratios (DR) are calculated as follows: 1st DR, J: (b * z) - (c * y) 2nd DR, A: -((a * z) - (c * x)) 3rd DR, N: (a * y) - (b * x)
Therefore, the direction ratios of the cross product are: J, A, N The following C++ Program calculates the direction ratios of the cross products of two vector. The program uses a function, cross() for doing so. The direction ratios for the first and the second vector has to be passed one by one seperated by a space character.
Magnitude of a vector is the square root of the sum of the squares of the direction ratios.
-
+
Example:
An example of a running instance of the executable program:
Pass the first Vector: 1 2 3
Pass the second Vector: 4 5 6 The cross product is: -3 6 -3 Magnitude: 7.34847
diff --git a/dir_000002_000016.html b/dir_000002_000017.html
similarity index 100%
rename from dir_000002_000016.html
rename to dir_000002_000017.html
diff --git a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.map b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.map
index 623879934..72fef3963 100644
--- a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.map
+++ b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.map
@@ -1,5 +1,5 @@
diff --git a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.md5 b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.md5
index 5fd2b3301..257e4dba0 100644
--- a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.md5
+++ b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.md5
@@ -1 +1 @@
-92fa4d7ae23a16161aeff73e457c6e1f
\ No newline at end of file
+76e5d78bae3066db57a72fde536d8c2e
\ No newline at end of file
diff --git a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.svg b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.svg
index d7d51943b..7af541bfb 100644
--- a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.svg
+++ b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.svg
@@ -32,7 +32,7 @@
dir_4d6e05837bf820fb089a8a8cdf2f42b7->dir_9c6faab82c22511b50177aa2e38e2780
-
+1
diff --git a/dir_cc8e79ed9d2b7756c78e8d0c87c6c0c7.html b/dir_cc8e79ed9d2b7756c78e8d0c87c6c0c7.html
new file mode 100644
index 000000000..7068e3381
--- /dev/null
+++ b/dir_cc8e79ed9d2b7756c78e8d0c87c6c0c7.html
@@ -0,0 +1,113 @@
+
+
+
+
+
+
+
+Algorithms_in_C++: cpu_scheduling_algorithms Directory Reference
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Reduced all possibilities of a number which cannot be prime. Eg: No even number, except 2 can be a prime number, hence we will increment our loop with i+2 jumping on all odd numbers only. If number is <= 1 or if it is even except 2, break the loop and return false telling number is not prime
A simple program to check if the given number is a magic number or not. A number is said to be a magic number, if the sum of its digits are calculated till a single digit recursively by adding the sum of the digits after every addition. If the single digit comes out to be 1,then the number is a magic number
An implementation for finding the Inorder successor of a binary search tree Inorder successor of a node is the next node in Inorder traversal of the Binary Tree. Inorder Successor is NULL for the last node in Inorder traversal
Reduced all possibilities of a number which cannot be prime. Eg: No even number, except 2 can be a prime number, hence we will increment our loop with i+2 jumping on all odd numbers only. If number is <= 1 or if it is even except 2, break the loop and return false telling number is not prime
A simple program to check if the given number is a magic number or not. A number is said to be a magic number, if the sum of its digits are calculated till a single digit recursively by adding the sum of the digits after every addition. If the single digit comes out to be 1,then the number is a magic number
An implementation for finding the Inorder successor of a binary search tree Inorder successor of a node is the next node in Inorder traversal of the Binary Tree. Inorder Successor is NULL for the last node in Inorder traversal
diff --git a/hierarchy.html b/hierarchy.html
index 6cdc2a251..15fb8a93a 100644
--- a/hierarchy.html
+++ b/hierarchy.html
@@ -104,92 +104,94 @@ This inheritance list is sorted roughly, but not completely, alphabetically:
Trie class, implementation of trie using hashmap in each trie node for all the characters of char16_t(UTF-16)type with methods to insert, delete, search, start with and to recommend words based on a given prefix
Trie class, implementation of trie using hashmap in each trie node for all the characters of char16_t(UTF-16)type with methods to insert, delete, search, start with and to recommend words based on a given prefix
This repository is a collection of open-source implementation of a variety of algorithms implemented in C++ and licensed under MIT License. These algorithms span a variety of topics from computer science, mathematics and statistics, data science, machine learning, engineering, etc.. The implementations and the associated documentation are meant to provide a learning resource for educators and students. Hence, one may find more than one implementation for the same objective but using a different algorithm strategies and optimizations.
-
+
Features
The repository provides implementations of various algorithms in one of the most fundamental general purpose languages - C++.
@@ -109,12 +109,12 @@ Features
Self-checks within programs ensure correct implementations with confidence.
Modular implementations and OpenSource licensing enable the functions to be utilized conveniently in other applications.
-
+
Documentation
Online Documentation is generated from the repository source codes directly. The documentation contains all resources including source code snippets, details on execution of the programs, diagrammatic representation of program flow, and links to external resources where necessary. The documentation also introduces interactive source code with links to documentation for C++ STL library functions used. Click on Files menu to see the list of all the files documented with the code.