Found 1862 Articles for Data Structure

Check if a Character is Only Occurring as One Single Contiguous Substring or Not

Shubham Vora
Updated on 17-Jul-2023 12:02:34

120 Views

In this problem, we will check whether all characters are present continuously in the given string. We will use the map data structure to solve the problem. The map will keep track of the last index of the particular character, and based on the last index of the current character, we will decide whether the string contains contiguous characters. Problem statement – We have given a string alpha of length N containing the lowercase and uppercase alphabetical characters. We need to check whether the given string is contiguous. The string is contiguous only if it contains all characters as a ... Read More

Breadth First Search without using Queue

Ayush Singh
Updated on 17-Jul-2023 10:06:09

338 Views

Breadth To begin with, Look (BFS) may be a chart traversal calculation utilised to investigate hubs in a chart in a breadthward movement. The normal usage of BFS utilises a line information structure to keep track of hubs to come. In any case, it is conceivable to execute BFS without utilising an unequivocal line by utilising other information structures. One elective approach to actualizing BFS without a line is to utilise two clusters or records: one for the current level of hubs being investigated and another for the next level of hubs to be investigated. At first, the current level ... Read More

Shortest path in a graph from a source S to destination D with exactly K edges for multiple Queries

Ayush Singh
Updated on 17-Jul-2023 11:54:14

306 Views

Finding the shortest route between a source vertex and a target vertex in a graph with precisely K edges is one of the most typical graph traversal issues. The objective is to find the shortest path with minimum weight and exactly K edges. This issue can manifest in a number of practical contexts, including transportation networks, routing protocols, and resource allocation. Dynamic Programming (DP), and Dijkstra's Algorithm are just some of the strategies that may be used to attack this issue. The shortest path under the given constraints can be found using one of many methods. Dijkstra's Algorithm takes into ... Read More

Minimum Number of Colours Required to Colour a Graph

Ayush Singh
Updated on 17-Jul-2023 11:52:55

451 Views

The Minimum Number of Colours Required to Colour a Graph is a fundamental graph theory issue that includes colouring vertices so that no two neighbouring vertices have the same colour. Determine the least amount of colours needed for a valid colouring.Greedy Colouring is a simple and commonly used technique that colours vertices one by one based on their neighbours. Backtracking also carefully analyses all colour allocations. DSatur−based graph colouring prioritises vertices with the highest degree and saturation. Methods Used Greedy colouring Backtracking Graph colouring Greedy Colouring Method The Greedy Colouring technique makes graph colouring easy. It colours the ... Read More

Minimum Cost to Reverse Edges such that there is Path Between Every Pair of Nodes

Ayush Singh
Updated on 14-Jul-2023 10:51:33

196 Views

The minimum cost to invert edges in order to have a way between each match of hubs alludes to finding the slightest costly way to alter the course of edges in a chart. The objective is to guarantee that there's a way to interconnect any two hubs within the chart. This may involve changing the course of a few edges to set up the network. The least taken toll speaks to the smallest cumulative weight related to reversing the edges. By minimising the fetch, we are able to accomplish the specified result of having a way between all sets of ... Read More

Minimum Colors Required such that Edges Forming Cycle do Not have Same Color

Ayush Singh
Updated on 14-Jul-2023 10:48:59

50 Views

To reduce the number of colours needed and to avoid having the edges form a cycle with the same colour, you can use a chart colouring approach. The goal is to map colours to vertices such that no two adjacent vertices connected by an edge have the same colour. By recognising cycles within the chart, we are able to guarantee that the edges shaping the cycle are allotted diverse colours. This requires navigating the chart using strategies like Depth−First Look (DFS) or Breadth−First Look (BFS) and applying backtracking to backtrack and reassign colours when essential. The objective is to discover ... Read More

Maximum number of edges that N-vertex graph can have such that graph is Triangle free| Mantel’s Theorem

Ayush Singh
Updated on 14-Jul-2023 10:46:59

117 Views

The concept of a triangle−free graph, in which no collection of three vertices forms a triangle, is crucial to the study of graph theory. It's amazing to consider how many edges an N−vertex graph may have and yet be triangle−free. Mantel's theorem offers the elegant solution to this issue.The maximum number of edges in a graph may be determined via Mantel's theorem without generating any triangles. Methods Used Mantel’s algorithm Mantel’s Algorithm Mantel's theorem is a famous conclusion in graph theory that sheds light on how many edges a graph without triangles may have. According to this theory, ... Read More

Minimum Value of Distance of Farthest Node in a Graph

Ayush Singh
Updated on 14-Jul-2023 10:45:28

229 Views

The goal here is to determine the path with the fewest hops from a given starting point to the endpoint of the whole graph. This distance may be computed using a variety of methods, including those specifically designed for graph traversal (like Breadth−First Search) and shortest path discovery (like Dijkstra's algorithm). Methods Used Breadth first search Dijkstra's algorithm Breadth first search method All graph vertices are traversed using the breadth−first search algorithm. A source node's neighbours are all visited before moving on to the next stage. In an unweighted graph, BFS determines the shortest path. By applying BFS ... Read More

Minimum Spanning Tree using Priority Queue and Array List

Ayush Singh
Updated on 14-Jul-2023 10:44:04

381 Views

To discover the least crossing tree of a chart, be ready to utilise a combination of a need line and a cluster list. To begin with, we initialise the need line with the edges of the chart, sorted by their weights in climbing order. At that point, we make a cluster list to store the edges of the least traversing tree. We more than once extricate the edge with the least weight from the need line and check in the event that including it in the cluster list makes a cycle. In the event that not, we include the edge ... Read More

Minimum Number of Edges that Need to be Added to form a Triangle

Ayush Singh
Updated on 14-Jul-2023 10:41:16

49 Views

To determine the least number of edges required to make a triangle in a chart, we analyse the network between the hubs. In cases where three hubs are associated specifically or in a roundabout way through edges, a triangle can be shaped. The minimum number of edges required is equal to the number of lost edges within the existing connections between the three hubs. By looking at the graph and distinguishing the hubs that are not associated, we can count the number of extra edges required to make a triangle. This approach makes a difference because it requires the fewest ... Read More

Advertisements