Found 422 Questions for Algorithms

Difference Between Algorithm and Pseudocode

Kiran Kumar Panigrahi
Updated on 24-Nov-2022 12:37:35
Algorithm and Pseudocode are the two related terms in computer programming. The basic difference between algorithm and pseudocode is that an algorithm is a step-by-step procedure developed to solve a problem, while a pseudocode is a technique of developing an algorithm. In this article, we will discuss the other important differences between an algorithm and a pseudocode. Let's start with some basic concepts of algorithm and pseudocode. What is an Algorithm? A sequence of steps to solve a given problem is called as algorithm. Thus, an algorithm is a step-by-step procedure developed for solving a given problem. An ... Read More

Difference Between Greedy Method and Dynamic Programming

Updated on 02-Mar-2021 05:04:41
In this post, we will understand the differences between the greedy algorithm and dynamic programming methods.Greedy algorithmIt is an algorithmic paradigm that builds up on a solution in parts, step by step. The next step is chosen such that it gives the most obvious and immediate benefit.Problems that involve choosing local optimal values will help in choosing the global optimal values/solution to the problem. Such ate the problems associated with greedy algorithm.There is no surety that a greedy algorithm would lead to an optimal solution.An optimal choice is made at every stage of the problem, i.e the local optimal solution.It ... Read More

Difference Between Prim’s and Kruskal’s Algorithm

Updated on 02-Mar-2021 05:02:09
In this post, we will understand the differences between Prim's and Kruskal's algorithms.Kruskal's algorithm for Mininum Spanning Tree (MST)When a connected and undirected graph is given, a spanning tree of such a graph is the subgraph which is a tree that connects all of the vertices.A single graph can have multiple spanning trees.A minimum spanning tree (MST) (also known as minimum weight spanning tree) for a weighted, connected and undirected graph is a spanning tree that weighs less than or equal to the weight of every other spanning tree.The weight of a spanning tree is determined by adding the weights ... Read More

Yen's k-Shortest Path Algorithm in Data Structure

Dev Prakash Sharma
Updated on 23-Feb-2021 06:35:29
Instead of giving a single shortest path, Yen’s k-shortest path algorithm gives k shortest paths so that we can get the second shortest path and the third shortest path and so on.Let us consider a scenario that we have to travel from place A to place B and there are multiple routes available between place A and place B, but we have to find the shortest path and neglect all the paths that are less considered in terms of its time complexity in order to reach the destination.Let us understand with an example-Consider the given example as the bridge which ... Read More

Algorithm to construct an Expression Tree in Data Structure

Dev Prakash Sharma
Updated on 23-Feb-2021 18:11:51
Expression treesExpression trees are those in which the leaf nodes have the values to be operated, and internal nodes contain the operator on which the leaf node will be performed.Example4 + ((7 + 9) * 2) will have an expression tree as followsAlgorithm to Construct an Expression TreeLet T be the expression tree.If T is not NULL:   If T->data is an operand:      return   A = solve(T.left)   B = solve(T.right)   --> Calculate operator for '' on A and B, and call recursively,       return calculate(A, B, to construct an expression tree?To construct an Expression Tree for ... Read More

Shortest Path algorithm in Computer Network

Updated on 22-Feb-2021 11:55:17
In computer networks, the shortest path algorithms aim to find the optimal paths between the network nodes so that routing cost is minimized. They are direct applications of the shortest path algorithms proposed in graph theory.ExplanationConsider that a network comprises of N vertices (nodes or network devices) that are connected by M edges (transmission lines). Each edge is associated with a weight, representing the physical distance or the transmission delay of the transmission line. The target of shortest path algorithms is to find a route between any pair of vertices along the edges, so the sum of weights of edges ... Read More

Dijkstra’s algorithm to compute the shortest path through a graph

Updated on 22-Feb-2021 11:38:19
DefinitionThe Dijkstra’s algorithm finds the shortest path from a particular node, called the source node to every other node in a connected graph. It produces a shortest path tree with the source node as the root. It is profoundly used in computer networks to generate optimal routes with the aim of minimizing routing costs.Dijkstra’s AlgorithmInput − A graph representing the network; and a source node, sOutput − A shortest path tree, spt[], with s as the root node.Initializations −An array of distances dist[] of size |V| (number of nodes), where dist[s] = 0 and dist[u] = ∞ (infinite), where u ... Read More

Flooding versus Fixed Routing Algorithms

Updated on 22-Feb-2021 11:25:54
Flooding and fixed routing are methods to transmit data packets from the source to the destination through a number of intermediate routers connected by transmission lines.Flooding is a non-adaptive routing technique following this simple method − when a data packet arrives at a router, it is sent to all the outgoing links except the one it has arrived on.Fixed routing algorithm is a procedure that lays down a fixed route or path to transfer data packets from source to the destination. The route is a mathematically computed best path, i.e. “least–cost path” that the packet can be routed through. The ... Read More

Insertion in the Red Black Tree in Data Structure

Dev Prakash Sharma
Updated on 05-Feb-2021 12:42:32
Red Black Tree is a Self-Balanced Binary Search Tree in which each node of the tree is colored with either Red or Black. There are three types of operations we can perform on a Red Black Tree – Searching, Insertion and Deletion.Let us suppose we have to insert an element in the following Red Black Tree.To insert an element in a red-black tree the idea is very simple − we perform insertion just like we insert in a regular binary tree. We start off from the root node by checking the color of the node and insert it into a ... Read More

Floyd Cycle Detection Algorithm to detect the cycle in a linear Data Structure

Dev Prakash Sharma
Updated on 05-Feb-2021 12:22:42
Floyd Cycle is one of the cycle detection algorithms to detect the cycle in a given singly linked list.In the Floyd Cycle algorithm, we have two pointers that initially point at the head. In Hare and Tortoise’s story, Hare moves twice as fast as Tortoise, and whenever the hare reaches the end of the path, the tortoise reaches the middle of the path.AlgorithmInitialize Hare and Tortoise at the head node of the List.Initially, the hare moves twice as fast as the tortoise.Move the hare and tortoise both and find if the hare reaches the end of the Linked List, return ... Read More