Data Structure Articles

Page 159 of 164

Count ways to reach the n’th stair

Samual Sam
Samual Sam
Updated on 16-Jun-2020 527 Views

There are n stairs. One person will go to 1'st to the n'th stair. Maximum how many stairs he/she can cross in one step is also given. With this information, we have to find possible ways to go to the n'th stairs.Let us consider one can cross a maximum two stairs in each step. So we can find recursive relations to solve this problem. One can move to n'th stair, either from (n-1)'th stair or from (n-2)'th stair. So ways(n) = ways(n-1) + ways(n-2).Input and OutputInput: The number of stairs, say 10 the maximum number of stairs that can be ...

Read More

Egg Dropping Puzzle

karthikeya Boyini
karthikeya Boyini
Updated on 16-Jun-2020 739 Views

This is a famous puzzle problem. Suppose there is a building with n floors, if we have m eggs, then how can we find the minimum number of drops needed to find a floor from which it is safe to drop an egg without breaking it.There some important points to remember −When an egg does not break from a given floor, then it will not break for any lower floor also.If an egg breaks from a given floor, then it will break for all upper floors.When an egg breaks, it must be discarded, otherwise, we can use it again.Input and ...

Read More

Edit Distance\\n

Ankith Reddy
Ankith Reddy
Updated on 16-Jun-2020 3K+ Views

There are two strings given. The first string is the source string and the second string is the target string. In this program, we have to find how many possible edits are needed to convert first string to the second string. The edit of strings can be either Insert some elements, delete something from the first string or modify something to convert into the second string.Input and OutputInput: Two strings to compare. string 1: Programming string 2: Programs Output: Enter the initial string: Programming Enter the final string: Programs The number of changes required to convert Programming to Programs is 4AlgorithmeditCount(initStr, ...

Read More

Find the minimum cost to reach destination using a train

Arjun Thakur
Arjun Thakur
Updated on 16-Jun-2020 682 Views

For this problem, there are N stops on a journey. The vehicle starts the journey from stop 0 to N-1. In a table, ticket costs for all pair of stations are given. We have to find the minimum cost to reach the destination with those given costs.Input and OutputInput: The cost matrix of the journey. 0 15 80 90 ∞  0 40 50 ∞  ∞  0 70 ∞  ∞  ∞  0 Output: The minimum cost is 65. At first go to the destination 1 from 0. (cost 15), then 1 to 4 (cost 50). So total cost 65.AlgorithmfindMinCost(cost)Input − ...

Read More

Snake and Ladder Problem

George John
George John
Updated on 16-Jun-2020 2K+ Views

We know about the famous game Snake and Ladder. In this game, some rooms are present on the board, with the room number. Some rooms are connected with a ladder or with snakes. When we get a ladder, we can climb up to some rooms to reach near to the destination without moving sequentially. Similarly, when we get some snake, it sends us to a lower room to start the journey again from that room.In this problem, we have to find the minimum number of the dice throw is required to reach start to destination.Input and OutputInput: The starting and ...

Read More

Transitive closure of a Graph

George John
George John
Updated on 16-Jun-2020 21K+ Views

Transitive Closure it the reachability matrix to reach from vertex u to vertex v of a graph. One graph is given, we have to find a vertex v which is reachable from another vertex u, for all vertex pairs (u, v).The final matrix is the Boolean type. When there is a value 1 for vertex u to vertex v, it means that there is at least one path from u to v.Input and OutputInput: 1 1 0 1 0 1 1 0 0 0 1 1 0 0 0 1 Output: The matrix of transitive closure 1 1 1 ...

Read More

Check For Star Graph

karthikeya Boyini
karthikeya Boyini
Updated on 16-Jun-2020 718 Views

A graph is given; we have to check the given graph is a star graph or not.By traversing the graph, we have to find the number of vertices has degree one, and number of vertices, whose degree is n-1. (Here n is the number of vertices in the given graph). When the number of vertices with degree 1 is n-1 and a number of vertices with a degree (n-1) is one, then it is a star graph.Input and OutputInput: The adjacency matrix: 0 1 1 1 1 0 0 0 1 0 0 0 1 0 0 0 Output: ...

Read More

Box Stacking Problem

Samual Sam
Samual Sam
Updated on 16-Jun-2020 1K+ Views

In this problem a set of different boxes are given, the length, breadth, and width may differ for different boxes. Our task is to find a stack of these boxes, whose height is as much as possible. We can rotate any box as we wish. But there is a rule to maintain.One can place a box on another box if the area of the top surface for the bottom box is larger than the lower area of the top box.Input and OutputInput: A list of boxes is given. Each box is denoted by (length, bredth, height). { (4, 6, 7), ...

Read More

Fleury’s Algorithm

Chandu yadav
Chandu yadav
Updated on 16-Jun-2020 7K+ Views

Fleury’s Algorithm is used to display the Euler path or Euler circuit from a given graph. In this algorithm, starting from one edge, it tries to move other adjacent vertices by removing the previous vertices. Using this trick, the graph becomes simpler in each step to find the Euler path or circuit.We have to check some rules to get the path or circuit −The graph must be a Euler Graph.When there are two edges, one is bridge, another one is non-bridge, we have to choose non-bridge at first.Choosing of starting vertex is also tricky, we cannot use any vertex as ...

Read More

Longest Path in a Directed Acyclic Graph

Samual Sam
Samual Sam
Updated on 16-Jun-2020 2K+ Views

One weighted directed acyclic graph is given. Another source vertex is also provided. Now we have to find the longest distance from the starting node to all other vertices, in the graph.We need to sort the nodes in topological sorting technique, and the result after the topological sort is stored into a stack. After that repeatedly popped from the stack and try to find the longest distance for each vertex.Input and OutputInput: The cost matrix of the graph. 0  5   3 -∞ -∞ -∞ -∞ 0   2  6 -∞ -∞ -∞ -∞  0  7  4  2 -∞ -∞ ...

Read More
Showing 1581–1590 of 1,635 articles
« Prev 1 157 158 159 160 161 164 Next »
Advertisements