Server Side Programming Articles

Page 2101 of 2109

C++ Program to Implement Rolling Hash

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 1K+ Views

Rolling hash is a hash function in which the input is hashed in a window that moves through the input.Rabin-Karp is popular application of rolling hash. The rolling hash function proposed by Rabin and Karp calculates an integer value. For a string the integer value is numeric value of a string.The Rabin–Karp string search algorithm is often explained using a very simple rolling hash function that only uses multiplications and additions −H=c1ak-1+c2ak-2+….+ cka0.Where, a is a constant, and c1, c2….ck are the input characters. In order to manipulate Huge value of H, mod n is done.AlgorithmBegin    Declare a constant ...

Read More

C++ Program to Implement Queue

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 4K+ Views

QueueThe queue which is implemented as FIFO where insertions are done at one end (rear) and deletions are done from another end (front). The first element that entered is deleted first.Queue operations are −EnQueue (int data) − Insertion at rear endint DeQueue()− Deletion from front endThis is a C++ program to implement queue using array.AlgorithmBegin    function Enqueue() to insert elements in queue:       If queue is completely filled up then print “Overflow”.       Otherwise insert element at rear.       Update the value of rear End Begin    function Dequeue() to delete elements from ...

Read More

C++ Program to Construct Transitive Closure Using Warshall's Algorithm

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 983 Views

If a directed graph is given, determine if a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given graph. Reachable mean that there is a path from vertex i to j. This reach-ability matrix is called transitive closure of a graph. Warshall algorithm is commonly used to find the Transitive Closure of a given graph G. Here is a C++ program to implement this algorithm.AlgorithmBegin    1.Take maximum number of nodes as input.    2.For Label the nodes as a, b, c …..    3.To check if there any edge present between ...

Read More

C++ Program to Implement Expression Tree Algorithm

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 535 Views

An expression tree is basically a binary which is used to represent expressions. In expression tree, internal nodes correspond to operators and each leaf node corresponds to an operand. Here is a C++ Program to implement the Expression Tree Algorithm which takes the postfix expression as an input and generates the corresponding expression tree traversed in inorder.AlgorithmBegin    function construct_expression_tree():       Flag = 1 when it is operand.       Flag = -1 when it is operator.       S = suffix[0] means read the first operand from the expression.    For i = 0 and ...

Read More

C++ Program to Implement Dijkstra's Algorithm Using Set

Nancy Den
Nancy Den
Updated on 30-Jul-2019 739 Views

This is a C++ Program to Implement Dijkstra’s Algorithm using Set. Here we need to have two sets. We generate a shortest path tree with given source node as root. One set contains vertices included in shortest path tree and other set includes vertices not yet included in shortest path tree. At every step, we find a vertex which is in the other set (set of not yet included) and has minimum distance from source.Algorithm:Begin    function dijkstra() to find minimum distance:    1) Create a set Set that keeps track of vertices included in shortest    path tree, Initially, ...

Read More

C++ Program to Implement The Edmonds-Karp Algorithm

Daniol Thomas
Daniol Thomas
Updated on 30-Jul-2019 4K+ Views

This is a C++ Program to Implement the Edmonds-Karp algorithm to calculate maximum flow between source and sink vertex.Algorithm:Begin    function edmondsKarp() :       initiate flow as 0.       If there is an augmenting path from source to sink, add the path to flow.       Return flow. EndExample Code#include #include #include #include #include using namespace std; int c[10][10]; int flowPassed[10][10]; vector g[10]; int parList[10]; int currentPathC[10]; int bfs(int sNode, int eNode)//breadth first search {    memset(parList, -1, sizeof(parList));    memset(currentPathC, 0, sizeof(currentPathC));    queue q;//declare queue vector    q.push(sNode);    parList[sNode] = -1;//initialize parlist’s ...

Read More

C++ Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 2K+ Views

Topological sorting of DAG (Directed Acyclic Graph) is a linear ordering of vertices such that for every directed edge uv, where vertex u comes before v in the ordering. If the graph is not a DAG, Topological Sorting for a graph is not possible.Functions and pseudocodesBegin    function topologicalSort():    a) Mark the current node as visited.    b) Recur for all the vertices adjacent to this vertex.    c) Push current vertex to stack which stores result. End Begin    function topoSort() which uses recursive topological sort() function:    a) Mark all the vertices which are not visited.   ...

Read More

C++ Program to Check Whether a Hamiltonian Cycle or Path Exists in a Given Graph

Paul Richard
Paul Richard
Updated on 30-Jul-2019 1K+ Views

A Hamiltonian cycle is a Hamiltonian Path such that there is an edge (in graph) from the last vertex to the first vertex of the Hamiltonian Path. It is in an undirected graph is a path that visits each vertex of the graph exactly once.Functions and purposes:Begin    1.function isSafe() is used to check for whether it is adjacent to the previously added vertex and already not added.    2. function hamiltonianCycle() solves the hamiltonian problem.    3. function hamCycle() uses hamiltonianCycle() to solve the hamiltonian problem.       It returns false if there is no Hamiltonian Cycle possible, ...

Read More

C++ Program to Check Whether it is Weakly Connected or Strongly Connected for a Directed Graph

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 351 Views

Weakly or Strongly Connected for a given a directed graph can be find out using DFS. This is a C++ program of this problem.Functions usedBegin    Function fillorder() = fill stack with all the vertices.    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex    c) All vertices reachable from v are processed by now, push v to Stack End Begin    Function DFS() :    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex ...

Read More

C++ Program to Find SSSP (Single Source Shortest Path) in DAG (Directed Acyclic Graphs)

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 2K+ Views

This is a C++ program to find SSSP (Single Source Shortest Path) in DAG (Directed Acyclic Graphs) using Dijkstra Algorithm to find out from the first node in graph to every other node with the shortest path length showed beside each pair of vertices.AlgorithmBegin    Take the elements of the graph as input.    function shortestpath():    Initialize the variables    a[i] = 1    d[i] = 0    s[i].from = 0    Initialize a loop for i = 0 to 3 do       if b[0][i] == 0          continue       else   ...

Read More
Showing 21001–21010 of 21,090 articles
Advertisements