5

Problem Link - http://opc.iarcs.org.in/index.php/problems/NUMTRIPLE

In my opinion, the problem can be solved by a data structure, that shows how each number is connected to another, and via recursion find the smallest possible value. But my question is, what data structure (most efficient) can hold/represent such data? Also, is there a better (faster) way of solving this problem.

Thanks

asked Oct 4, 2012 at 20:36
3
  • 1
    Thank you for your first post to Stack Exchange Programmers. Please consider revising your question title to help people know what it is about without drilling down into the comments and the problem link. Given this question seems to be part of a competition, is it ethical to ask for help on this site? Additional guidelines for questions can be found in the FAQ at programmers.stackexchange.com/faq Commented Oct 5, 2012 at 0:36
  • The question is pretty specific to the given problem, so it seems like a conundrum to find a better title. It is just a preparation Q and is not part of a competition. Appreciate the concern... Commented Oct 5, 2012 at 10:10
  • 2
    Please strive for a better title. "Efficient Data Structure for this particular problem" doesn't tell me anything about what the problem is when reading through question listings or rss feeds. Commented Nov 6, 2012 at 21:19

2 Answers 2

2

The problem is equivalent to the shortest-path problem in a graph, where the vertices are given by the first and third number of each of your triples, an edge is given by a triple "connecting" two vertices, and the weight of the edge is given by the second number of each triple. It can be efficiently solved, for example, by Dijkstra's algorithm. The Wikipedia article lists some different heap data structures for graphs which may be appropriate for this algorithm as long as the graph is "sparse".

answered Oct 4, 2012 at 20:50
0
0

multidimetional array, we can also call it matrix.

create nxn dimentional array (lets say A) - where n is number of node in graph. when node i and j is connected set A[i][j] to 1 else set to 0.

answered Apr 23, 2013 at 18:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.