Found 7346 Articles for C++

C++ Program to Implement Wagner and Fisher Algorithm for online String Matching

Nitya Raut
Updated on 30-Jul-2019 22:30:25

310 Views

In this section we will see how to compare two strings using Wagner and Fisher algorithm. Using this algorithm, we can find how many minimum changes are required to match those strings.This is a dynamic programming approach. Here we measure the Levenshtein distance from two strings.Input: Two strings “Support” & “Suppose” Output: Minimum number of required changes: 2AlgorithmWagnwe_Fisher(str1, str2)Input: Two strings str1 and str2Output: The minimum number of changesl1 := length of str1, and l2 = length of str2 define a matrix d of order (l1 * l2) fill first row of d with numbers from 0 to l1 – ... Read More

C/C++ Macro for string concatenation

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

4K+ Views

In this program we will see how the macros are used to concatenate two strings. We can create two or more than two strings in macro, then simply write them one after another to convert them into a concatenated string. The syntax is like below:#define STR1 "str1" #define STR2 " str2" #define STR3 STR1 STR2 //it will concatenate str1 and str2Input: Take two stringsOutput: Return concatenated string.AlgorithmStep 1:Take two strings Step 2: Use macro to concatenate the strings Step 3: EndExample Code Live Demo#include #define STR1 "Hello" #define STR2 "World" #define STR3 STR1 STR2 main() { printf("%s", STR3); ... Read More

C++ Program to Check the Connectivity of Undirected Graph Using DFS

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

3K+ Views

To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any node, which is not visited, then the graph is not connected.For the undirected graph, we will select one node and traverse from it.In this case the traversal algorithm is recursive DFS traversal.Input − Adjacency matrix of a graph0110010110110110110100110Output − The Graph is connected.Algorithmtraverse(u, visited)Input − The start node u and the visited node to mark which node is visited.Output: Traverse all connected vertices.Begin mark u as visited for all ... Read More

C++ Program to Check the Connectivity of Directed Graph Using BFS

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

595 Views

To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any node, which is not visited, then the graph is not connected.For the directed graph, we will start traversing from all nodes to check connectivity. Sometimes one edge can have the only outward edge but no inward edge, so that node will be unvisited from any other starting node.In this case the traversal algorithm is recursive BFS traversal.Input − Adjacency matrix of a graph0100000100000111000001000Output − The Graph is connected.Algorithmtraverse(s, visited)Input: The start node s and the ... Read More

C++ Program to Check the Connectivity of Undirected Graph Using BFS

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any node, which is not visited, then the graph is not connected.For the undirected graph, we will select one node and traverse from it.In this case the traversal algorithm is recursive BFS traversal.Input − Adjacency matrix of a graph0110010110110110110100110Output − The Graph is connected.Algorithmtraverse(s, visited)Input − The start node s and the visited node to mark which node is visited.Output − Traverse all connected vertices.Begin mark s as visited insert ... Read More

C++ Program to Represent Graph Using Linked List

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

The incidence matrix of a graph is another representation of a graph to store into the memory. This matrix is not a square matrix. The order of the incidence matrix is V x E. Where V is the number of vertices and E is the number of edges in the graph.In each row of this matrix we are placing the vertices, and in each column the edges are placed. In this representation for an edge e {u, v}, it will be marked by 1 for the place u and v of column e.The complexity of Adjacency Matrix representationThe incidence matrix ... Read More

C++ Program to Represent Graph Using Adjacency List

Nitya Raut
Updated on 30-Jul-2019 22:30:25

3K+ Views

The adjacency list representation of a graph is linked list representation. In this representation we have an array of lists The array size is V. Here V is the number of vertices. In other words, we can say that we have an array to store V number of different lists. If a list header is vertex u, then it signifies that it will hold all of the adjacent vertices of u.The complexity of Adjacency List representationThis representation takes O(V+2E) for undirected graph, and O(V+E) for directed graph. If the number of edges are increased, then the required space will also ... Read More

C++ Program to Represent Graph Using Incidence Matrix

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

1K+ Views

The incidence matrix of a graph is another representation of a graph to store into the memory. This matrix is not a square matrix. The order of the incidence matrix is V x E. Where V is the number of vertices and E is the number of edges in the graph.In each row of this matrix we are placing the vertices, and in each column the edges are placed. In this representation for an edge e {u, v}, it will be marked by 1 for the place u and v of column e.The complexity of Adjacency Matrix representationThe incidence matrix ... Read More

C++ Program to Represent Graph Using Adjacency Matrix

Nitya Raut
Updated on 30-Jul-2019 22:30:25

3K+ Views

The adjacency matrix of a graph is a square matrix of size V x V. The V is the number of vertices of the graph G. In this matrix in each side V vertices are marked. If the graph has some edges from i to j vertices, then in the adjacency matrix at ith row and jth column it will be 1 (or some non-zero value for weighted graph), otherwise that place will hold 0.The complexity of Adjacency Matrix representationThe adjacency matrix representation takes O(V2) amount of space while it is computed. When graph has maximum number of edges and ... Read More

C++ Program to Implement Merge Sort Algorithm on Linked List

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

The merge sort technique is based on divide and conquer technique. We divide the while data set into smaller parts and merge them into a larger piece in sorted order. It is also very effective for worst cases because this algorithm has lower time complexity for worst case also.Linked list can be sorted using merge-sort very efficiently. For the linked list the merging task is very simple. We can simply update the links to merge them. In this section we will see how to sort the linked list using this approach.The complexity of Merge Sort TechniqueTime Complexity − O(n log ... Read More

Advertisements