Articles for category: Data Structures and Algorithms

How to Move All Zeroes to End of Array?

Given an array of random numbers and zeros, arrange the array such that all the numbers restoring their order are moved in front and move all zeros to end of array. There are so many ways to solve this problem. We can make use of additional arrays, pointers, partitions, etc. Example to Understand Let us ...

Graph Algorithms

Graph algorithms are vital for analyzing interconnected data structures, enabling tasks like pathfinding and connectivity analysis in social networks and GPS systems. From route optimization to recommendation engines, they drive insights and optimizations across various domains. Their applications extend to fields like bioinformatics and logistics, showcasing their broad relevance in modern computing and problem-solving. What ...

Difference Between BFS and DFS

The Difference Between BFS and DFS lies in their traversal methods. BFS explores nodes level by level, making it ideal for finding the shortest path. In contrast, DFS explores, as far as possible, each branch suited for topological sorting and detecting cycles. What is BFS? Breadth-First Search (BFS) is a vertex-based algorithm used to find the ...

Dictionary in Data Structure

A dictionary in data structure is used to store the data in the form of key-value pair. The dictionary in data structure has an attribute called the key. The key is the attribute that helps us locate the data or value in the memory. A dictionary in data structure supports a wide variety of operations using a wide ...

Difference Between Algorithm and Flowchart

The difference between algorithm and flowchart is simply that algorithm is the collection of rules that should be followed while solving any particular problem. flowchart is diagrammatic representation of the algorithm. What is Algorithm? Let’s understand what an algorithm is to clarify the difference between algorithm and flowchart. An algorithm is a method for solving a problem step by step. An algorithm is a set ...

Detect Cycle in Directed Graph

Problem Statement Given a Directed graph $G=(V, E)$ with $V$ vertices numbered from $0$ to $V-1$ and $E$ edges. The task is to detect cycle in the directed graph $i.e.$ to check if there exists a cycle in the given graph. Examples Example 1 Input: Output:NO Explanation: No cycle exists in the above give Directed ...