Thanks to visit codestin.com
Credit goes to github.com

Skip to content

wwken/TrianglePuzzle

Repository files navigation

To view the problem, please open the triangle_puzzle.pdf file included in this directory
------------------------------------------------------------------------------------------------------------------------------


I implemented this as the O(N) time complexity by using the hashMap to store the previous computed node's sum in order to avoid traversing its child again.
I also avoid creating any extra spaces for storing extra data structure.  Hopefully, this is the fastest and the most efficient algorithm for this problem.
------------------------------------------------------------------------------------------------------------------------------


TO INSTALL and build and run:

First, extract the zip file to the folder C:\workplace\my-liquidNetApp.  Then open the command and prompt console window under window 7 and go to the folder C:\workplace\my-liquidNetApp, assuming all tools have been installed already, such as mvn, Java, java_home..etc

Step 1: Run the following command to compile the source code and build the jar file

mvn package


Step 2: Run the following command to run the TrianglePuzzleTrianglePuzzle program

java -cp target/my-liquidNetApp-1.0-SNAPSHOT.jar com.liquidNet.app.TrianglePuzzle


Step 3: You will be prompted the location of the input file.  In the default distrubution, enter either triangle_test_4rows.txt or triangle_test_100rows.txt for testing.


If you enter triangle_test_4rows.txt, the program will calculate and print 

The maximum sum from top to bottom is : 27
This is found by following the path : 5 + 9 + 6 + 7 = 27

If you enter triangle_test_100rows.txt, the program will calculate and print 

The maximum sum from top to bottom is : 732506
This is found by following the path : 9235 + 9096 + 3269 + 3350 + 8032 + 9642 +
1921 + 3674 + 6345 + 3058 + 7324 + 3248 + 9558 + 4473 + 8497 + 8487 + 8099 + 653
4 + 9326 + 6145 + 7750 + 6287 + 8414 + 8230 + 3774 + 7628 + 9434 + 1897 + 9306 +
 9161 + 9644 + 9081 + 8047 + 9729 + 5151 + 7337 + 5596 + 5963 + 7901 + 4237 + 79
44 + 9646 + 8844 + 9357 + 8136 + 6544 + 7359 + 5969 + 8177 + 8548 + 9262 + 8539
+ 8028 + 9766 + 9833 + 7641 + 7792 + 9397 + 7542 + 8108 + 3216 + 7644 + 9461 + 5
124 + 6477 + 7119 + 9022 + 8466 + 9721 + 8208 + 6996 + 9763 + 7650 + 9048 + 9385
 + 1335 + 6481 + 3307 + 1459 + 9075 + 9094 + 7098 + 7030 + 9313 + 9605 + 8451 +
6150 + 3036 + 8207 + 6683 + 4102 + 6118 + 4982 + 9172 + 9760 + 9730 + 9983 + 667
9 + 9720 + 8324 = 732506



About

Finding the heaviest sum weight path on the acyclic diagrph

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages