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.
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”.
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.
diff --git a/d5/d88/md__d_i_r_e_c_t_o_r_y.html b/d5/d88/md__d_i_r_e_c_t_o_r_y.html
index 6f7beabdb..de20372a4 100644
--- a/d5/d88/md__d_i_r_e_c_t_o_r_y.html
+++ b/d5/d88/md__d_i_r_e_c_t_o_r_y.html
@@ -170,6 +170,11 @@ Data Structures
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.
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 two strings in binary notation we want to multiply them and return the value Simple approach is to multiply bits one by one which will give the time complexity of around O(n^2). To make it more efficient we will be using Karatsuba' algorithm to find the product which will solve the problem O(nlogn) of time.
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.
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_000015.html b/dir_000002_000016.html
similarity index 100%
rename from dir_000002_000015.html
rename to dir_000002_000016.html
diff --git a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.map b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.map
index 0f7379b4e..623879934 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 3e485cd10..5fd2b3301 100644
--- a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.md5
+++ b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.md5
@@ -1 +1 @@
-7106d5e10343b80648da62761f872fb3
\ No newline at end of file
+92fa4d7ae23a16161aeff73e457c6e1f
\ No newline at end of file
diff --git a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.svg b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.svg
index aac3b2129..778ebdd08 100644
--- a/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.svg
+++ b/dir_4d6e05837bf820fb089a8a8cdf2f42b7_dep.svg
@@ -32,7 +32,7 @@
dir_4d6e05837bf820fb089a8a8cdf2f42b7->dir_9c6faab82c22511b50177aa2e38e2780
-
+1
diff --git a/dir_93bc990c5cceb745f78af6949e9ef947.html b/dir_93bc990c5cceb745f78af6949e9ef947.html
new file mode 100644
index 000000000..1d121d530
--- /dev/null
+++ b/dir_93bc990c5cceb745f78af6949e9ef947.html
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+
+Algorithms_in_C++: divide_and_conquer 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
The repository is a collection of open-source implementation of a variety of algorithms implemented in C++ and licensed under MIT License. The 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++.
@@ -110,12 +110,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.