Found 1862 Articles for Data Structure

Encode Strings in form of “xAyB” where x and y and based on count of digits

Shubham Vora
Updated on 24-Aug-2023 17:17:50

40 Views

In this problem, we need to encode the string in xAyB format, where x is the count of digits present in both strings at the same index, and y is the count of digits in both strings at different indices. We can solve the problem by counting the same digits in both strings. Also, we can count the total number of the same digits present at same index in both strings to encode the string. Problem statement - We have given str1 and str2 strings of the same length containing only digits. We need to encode the given ... Read More

Encode given string by shifting each character forward with its alphabetical value

Shubham Vora
Updated on 24-Aug-2023 17:00:06

143 Views

In this problem, we need to calculate the distance between the character and 'a', and by adding it to the character, we need to shift the character. The solution approach is to find the difference between the ASCII values of both characters, and add it to the current character's ASCII value. Problem statement - We have given an alpha string of length N containing only alphabetical characters. We need to encode the string according to the below conditions. Take a distance between the current character and 'a'. ... Read More

Find Maximum Shortest Distance in Each Component of a Graph

Pranavnath
Updated on 25-Aug-2023 11:18:54

65 Views

Introduction In C language, finding the most extreme briefest separate in each component of a chart may be a vital assignment. The chart is spoken to utilizing a contiguousness list or lattice. By utilizing Breadth-First Search (BFS) or Depth-First Look (DFS), we will compute the most limited separations from each hub to all other hubs inside a component. To get the most extreme most brief separate in each component, we emphasize through the components and keep up a running most extreme. At last, we yield the comes about for each component. This productive calculation permits us to analyze complex systems, ... Read More

Count the number of nodes in a Graph whose sum of neighbours is at most K

Pranavnath
Updated on 25-Aug-2023 11:18:03

149 Views

Introduction Undirected graphs are an essential component of computer science and graph theory, representing a set of vertices connected by edges without any directionality. One common problem associated with undirected graphs is the counting the number of nodes in a graph whose sum of neighbours is at most K. In computer science, the graph theory field will deal with the connection between the elements in the given matrix. Usually the graphs consists of the elements namely the edges and the nodes. Count the number of nodes in a Graph The Graph that is exclusively used is the undirected graph in ... Read More

Difference between Minimum Spanning Tree and Shortest Path

Pranavnath
Updated on 25-Aug-2023 11:16:37

849 Views

Introduction The Minimum Spanning tree and the shortest tree plays a vital role in the field of graph theory to design the networks. While they share similarities as fundamental concepts, their purposes diverge significantly. In this article, we will dive into these two interesting elements within graphs and highlight their differences. MSTs aim at establishing minimal-cost connectivity among all vertices of a graph without loops, while shortest paths target identifying optimal routes between specific nodes in terms of distance or weight accumulation. Difference between Minimum Spanning Tree and shortest Path Graph theory offers various tools for analyzing connections and pathways ... Read More

Why does Dijkstra's Algorithm fail on negative weights?

Pranavnath
Updated on 25-Aug-2023 11:20:58

257 Views

Introduction Dijkstra's algorithm could be a broadly utilized graph traversal algorithm that finds the shortest way between two vertices in a graph. It is effective and ensures ideal comes about when connected to graphs with non-negative weights. In any case, when negative weights are presented, Dijkstra's algorithm comes up short to produce rectify comes about. In this article, we'll investigate the reasons behind this disappointment and discuss three distinctive approaches to handling negative weights in graphs using C language. We'll give a step-by-step clarification of each approach, in conjunction with the comparing code and outputs. Understanding Dijkstra's Algorithm Dijkstra's algorithm ... Read More

Graph Homomorphism

Pranavnath
Updated on 25-Aug-2023 11:15:22

121 Views

Introduction Graph homomorphism may be a crucial concept in chart hypothesis and computational science. Within the setting of C dialect, a chart homomorphism may be a mapping between two charts that jam the contiguousness connections between their vertices. It is frequently spoken to as a work that allocates vertices from one chart to vertices in another, whereas keeping up the edges between them. This concept empowers the consideration and examination of basic similitudes and associations between distinctive charts. By executing chart homomorphism in C, software engineers can investigate different applications, such as chart coordinating, chart coloring, and chart isomorphism testing, ... Read More

Check if a cycle between nodes S and T in an Undirected Graph with only S and T repeating

Pranavnath
Updated on 25-Aug-2023 11:13:07

64 Views

Introduction Graphs are powerful mathematical structures that allow us to model and visualize relationships between various entities. In computer science, graphs find application in a wide range of algorithms and data structures. One common problem with undirected graphs is determining whether a cycle exists between two given nodes. In this article, we embark upon the journey to unravel this mystery and present an elegant solution using C/C++. Determining cycles within an undirected graph is vital in various applications where connectivity matters. Undirected Graphs is determining whether a cycle exists between two given nodes Unweighted bidirectional (or undirected) graphs consist of ... Read More

Construct a Graph from size of components for each node

Pranavnath
Updated on 25-Aug-2023 11:11:35

128 Views

Introduction Graph theory is a fundamental field in computer science, allowing us to study and visualize relationships between objects or entities. One important aspect of analyzing graphs understands the sizes of components or connected subgraphs within the network. In this article, we will explore how to construct a graph from component size for each node using C++ code. In graph theory, a component refers to any connected subgraph where there exists some path between any two vertices within that subgraph. It helps depict clusters or groups of interconnected nodes within the entire graph structure. A Graph from size of components ... Read More

Traverse in lexicographical order using DFS

Pranavnath
Updated on 25-Aug-2023 11:10:35

281 Views

Introduction Graph traversal could be a principal operation in computer science that includes going by all nodes of a graph. In certain scenarios, it may be fundamental to navigate the graph in the lexicographical order of nodes, which suggests going by the nodes in climbing numerical order. In this article, we'll investigate two distinctive approaches to performing a lexicographical DFS traversal of a graph utilizing the C language. These approaches point to creating the same correct yield while giving elective executions and viewpoints. They offer an establishment for understanding a wide extent of graph-related issues, empowering productive investigation, and analysis ... Read More

Advertisements