diff --git a/annotated.html b/annotated.html index bae880eaa..e9c061d05 100644 --- a/annotated.html +++ b/annotated.html @@ -103,6 +103,7 @@ $(document).ready(function(){initNavTree('annotated.html',''); initResizable();
Implementation of Hopcroft–Karp algorithm.
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.
-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.
-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.
-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.
-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.
-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.
-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.
diff --git a/d1/def/classdata__structures_1_1linked__list_1_1list.html b/d1/def/classdata__structures_1_1linked__list_1_1list.html index 5349c6c8c..ceac35048 100644 --- a/d1/def/classdata__structures_1_1linked__list_1_1list.html +++ b/d1/def/classdata__structures_1_1linked__list_1_1list.html @@ -97,12 +97,19 @@ $(document).ready(function(){initNavTree('d1/def/classdata__structures_1_1linkedPublic Member Functions | |
| list () | |
| bool | isEmpty () |
| Utility function that checks if the list is empty. More... | |
| void | push_back (int new_elem) |
| void | reverse () |
| list () | |
| +bool | isEmpty () |
| void | insert (int32_t new_elem) |
| Utility function that adds a new element at the end of the list. More... | |
| void | reverseList () |
| Utility function for reversing a list. More... | |
| +void | display () |
| int32_t | top () |
| Utility function to find the top element of the list. More... | |
| +int32_t | last () |
| int32_t | traverse (int32_t index) |
| Utility function to find the i th element of the list. More... | |
Private Attributes | first |
| link before the actual first element | |
| -std::shared_ptr< link > | last |
| last link on the list | |
| std::shared_ptr< link > | last |
| last link on the list More... | |
| +Node * | head |
A list class containing a sequence of links
+
|
+ +inline | +
| void list::insert | +( | +int32_t | +n | ) | ++ |
Utility function that adds a new element at the end of the list.
+| new_elem | element be added at the end of the list |
Utility function that checks if the list is empty.
function checks if list is empty
| void list::reverseList | +( | +) | ++ |
Utility function for reversing a list.
+Using the current, previous, and next pointer.
| int32_t list::top | +( | +) | ++ |
Utility function to find the top element of the list.
+| int32_t list::traverse | +( | +int32_t | +index | ) | ++ |
Utility function to find the i th element of the list.
+
+
|
+ +private | +
last link on the list
+Utility function to find the last element of the list.
+two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j
Time Complexity --> O(n.log n)
Space Complexity --> O(n) ; additional array temp[1..n]
An implementation of LRU Cache. Lru is a part of cache algorithms (also frequently called cache replacement algorithms or cache replacement policies).
-For a cache of page frame x:
Every time a requested page is not found in cache, that is a miss or page fault, and if the page is present in cache, then its a hit.
-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.
-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:
diff --git a/d4/d0e/classdata__structures_1_1linked__list_1_1_node.html b/d4/d0e/classdata__structures_1_1linked__list_1_1_node.html new file mode 100644 index 000000000..5100af35a --- /dev/null +++ b/d4/d0e/classdata__structures_1_1linked__list_1_1_node.html @@ -0,0 +1,131 @@ + + + + + + + +|
+ Algorithms_in_C++ 1.0.0
+
+ Set of algorithms implemented in C++.
+ |
+
+Public Attributes | |
| +int32_t | val |
| +Node * | next |
| value of the current link | |
A Node class containing a value and pointer to another link
+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.
-* 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.
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.
-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
Implementation of Jarvis’s algorithm.
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.
-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”.
diff --git a/d4/d9f/selection__sort__recursive_8cpp.html b/d4/d9f/selection__sort__recursive_8cpp.html index ca4ed0805..b734a1992 100644 --- a/d4/d9f/selection__sort__recursive_8cpp.html +++ b/d4/d9f/selection__sort__recursive_8cpp.html @@ -139,7 +139,7 @@ FunctionsImplementation 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.
-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.
Gram Schmidt Orthogonalisation Process
Takes the input of Linearly Independent Vectors, returns vectors orthogonal to each other.
-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)}
diff --git a/d5/d3c/namespacedata__structures.html b/d5/d3c/namespacedata__structures.html index 4d2650aea..ceebb6d2e 100644 --- a/d5/d3c/namespacedata__structures.html +++ b/d5/d3c/namespacedata__structures.html @@ -127,10 +127,13 @@ constexpr floatfor std::to_string
for IO operations
Data-structure algorithms.
+for managing dynamic storage
Algorithms with data structures.
for assert
for io operations for std::array
Algorithms with data structures
+for assert for I/O operations for dynamic memory
+Data Structures algorithms
for std::array for assert
Data Structures algorithms
for std::array for assert for std::ofstream for std::cout for std::unique_ptr for std::queue
diff --git a/d5/d3c/namespacedata__structures.js b/d5/d3c/namespacedata__structures.js index 08c17b89e..8c996addf 100644 --- a/d5/d3c/namespacedata__structures.js +++ b/d5/d3c/namespacedata__structures.js @@ -3,6 +3,7 @@ var namespacedata__structures = [ "linked_list", null, [ [ "link", "de/d9d/classdata__structures_1_1linked__list_1_1link.html", "de/d9d/classdata__structures_1_1linked__list_1_1link" ], [ "list", "d1/def/classdata__structures_1_1linked__list_1_1list.html", "d1/def/classdata__structures_1_1linked__list_1_1list" ], + [ "Node", "d4/d0e/classdata__structures_1_1linked__list_1_1_node.html", "d4/d0e/classdata__structures_1_1linked__list_1_1_node" ], [ "isDigit", "da/dc3/linked__list_8cpp.html#ab1a372fe1e605bc0e0987dcdd7361180", null ] ] ], [ "list_array", null, [ diff --git a/d5/d45/sublist__search_8cpp.html b/d5/d45/sublist__search_8cpp.html index 4479501ff..d4d314da3 100644 --- a/d5/d45/sublist__search_8cpp.html +++ b/d5/d45/sublist__search_8cpp.html @@ -148,14 +148,14 @@ FunctionsImplementation of the Sublist Search Algorithm
-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
-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
diff --git a/d5/ddb/bogo__sort_8cpp.html b/d5/ddb/bogo__sort_8cpp.html index 5f7fd920d..a632165e0 100644 --- a/d5/ddb/bogo__sort_8cpp.html +++ b/d5/ddb/bogo__sort_8cpp.html @@ -135,7 +135,7 @@ FunctionsImplementation of Bogosort algorithm
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.
-Shuffle the array untill array is sorted.
diff --git a/d6/d05/reverse__a__linked__list_8cpp.html b/d6/d05/reverse__a__linked__list_8cpp.html new file mode 100644 index 000000000..9cadc86be --- /dev/null +++ b/d6/d05/reverse__a__linked__list_8cpp.html @@ -0,0 +1,255 @@ + + + + + + + +|
+ Algorithms_in_C++ 1.0.0
+
+ Set of algorithms implemented in C++.
+ |
+
Implementation of Reversing a single linked list +More...
+#include <cassert>#include <iostream>#include <memory>#include <new>+Classes | |
| class | data_structures::linked_list::Node |
| class | data_structures::linked_list::list |
+Namespaces | |
| namespace | data_structures |
| Data Structures algorithms. | |
| namespace | linked_list |
| Functions for singly linked list algorithm. | |
+Functions | |
| static void | test () |
| Self-test implementations. More... | |
| int | main () |
| Main function. More... | |
Implementation of Reversing a single linked list
+The linked list is a data structure used for holding a sequence of values, which can be added, displayed, reversed, or removed.
+Values can be added by iterating to the end of a list (by following the pointers) starting from the first link. Whichever link points to null is considered the last link and is pointed to the new value.
+Linked List can be reversed by using 3 pointers: current, previous, and next_node; we keep iterating until the last node. Meanwhile, before changing to the next of current, we store it in the next_node pointer, now we store the prev pointer in the current of next, this is where the actual reversal happens. And then we move the prev and current pointers one step forward. Then the head node is made to point to the last node (prev pointer) after completion of an iteration.
+A graphic explanation and view of what's happening behind the scenes
+| int main | +( | +void | +) | ++ |
+
|
+ +static | +
Self-test implementations.
+Implementation of cutting a rod problem.
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.
-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.
a's lowercase letters.a.The idea is in the problem statement itself: iterate through characters of string a and b (for character indexes i and j respectively):
a[i] and b[j] are equal, then move to next positionSimple C++ implementation of the SHA-1 Hashing Algorithm
SHA-1 is a cryptographic hash function that was developped by the NSA 1995. SHA-1 is not considered secure since around 2010.
-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
Iterative version of Preorder, Postorder, and preorder Traversal of the 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 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.
-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.
-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.
The Disjoint union is the technique to find connected component in graph efficiently.
-In Graph, if you have to find out the number of connected components, there are 2 options
This is the complete list of members for data_structures::linked_list::list, including all inherited members.
Implementation of Minimum Edit Distance using Dynamic Programing.
Given two strings str1 & str2 and we have to calculate the minimum number of operations (Insert, Remove, Replace) required to convert str1 to str2.
-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.
Implementation of 0-1 Knapsack Problem
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)
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.
a-z a-z 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.
-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.
Documentation of Algorithms in C++ by The Algorithms Contributors is licensed under CC BY-SA 4.0
As a community developed and maintained repository, we welcome new un-plagiarized quality contributions. Please read our Contribution Guidelines.