Articles for category: Data Structures and Algorithms

Bellman–Ford Algorithm

The Bellman-Ford algorithm is an example of Dynamic Programming. It starts with a starting vertex and calculates the distances of other vertices which can be reached by one edge. It then continues to find a path with two edges and so on. The Bellman-Ford algorithm follows the bottom-up approach. What is Bellman-Ford Algorithm? The Bellman-Ford ...

Space Complexity in Data Structure

Let’s take an example of sorting alogrithms like insertion and heap sort doesn’t creates a new array during sorting as they are in-place sorting techniques but merge sort creates an array during sorting of elements which takes an extra space so if there is a concern of space then obviously one will prefer the insertion ...

Shortest Path in Directed Acyclic Graph

In graph theory, identifying the shortest path from a single vertex to all others is essential. The Bellman-Ford algorithm accomplishes this in O(V×E) time. However, for Directed Acyclic Graphs (DAGs), topological sorting offers a more efficient approach. Before delving deeper, let’s understand what a Directed Acyclic Graph (DAG) is. Essentially, it’s a directed graph free ...

Strongly Connected Components

Strongly connected components (SCC's) are directed graph or a part of a directed graph in which each and every node is reachable from one another or in other words, there is a path between each and every vertex. There are many ways to find strongly connected components in any graph with the most efficient algorithm ...

Spanning Tree

A spanning tree in data structures is a sub-graph, that contains all the vertices of a graph. A spanning tree may or may not be weighted, a spanning tree does not have cycles and it cannot be disconnected. The spanning tree has a minimal set of edges. A single connected graph can have multiple spanning ...

Topological Sorting

Topological sorting arranges vertices in a Directed Acyclic Graph (DAG) linearly, ensuring for every edge u-v, u precedes v. Crucially, this sorting is exclusive to DAGs; cyclic graphs defy this ordering. Integral to graph theory, the Topological Sort Algorithm finds applications in project scheduling, dependency management, and compiling. This method’s exploration unveils its mechanics and ...

Bucket Sort Algorithm

Bucket sort efficiently organizes elements by distributing them into distinct buckets, facilitating subsequent sorting using alternative algorithms. This technique, pivotal in software engineering interviews, categorizes data into buckets based on uniform distribution. Once grouped, each bucket undergoes sorting, and the sorted elements are then amalgamated into a cohesive, ordered sequence. Bucket sort’s approach streamlines sorting ...

Recursion Tree Method

The Recursion Tree Method resolves recurrence relations by converting them into recursive trees, where each node signifies the cost at different recursion levels. This visual representation simplifies understanding. Recursion, vital in computer science and mathematics, enables functions to self-reference. Recursion trees visually depict the iterative execution of recursive functions, aiding comprehension in problem-solving. Types of ...

Greedy Algorithm in Data Structure

The Greedy algorithm solves optimization problems by making locally optimal choices, potentially leading to a globally optimal solution. This article covers the approach, related terms, and discusses its applications, including finding optimal solutions and approximating solutions for NP-Hard problems like the Traveling Salesman Problem. Takeaways Applications of Greedy Algorithm What is Greedy Algorithm? To maximize ...

Depth First Search (DFS) Algorithm

Depth First Search (DFS) is an algorithm that is mainly used to traverse the graph data structure. The algorithm starts from an arbitrary node (root node in case of trees) and explore as far as possible in the graph before backtracking. After backtracking it repeats the same process for all the remaining vertices which have ...