This assignment is a variation of a problem from Project Euler. You are required to find the greatest path sum starting at the top of the triangle and moving only to adjacent numbers on the row below.
3 7 4 2 4 6 8 5 9 3In the above triangle, the maximum path sum is 3 + 7 + 4 + 9 = 23.
You will read your input from the file triangle.in . The first line indicates n the number of rows in the triangle. This will be followed by n lines of data. Each line of data will have only positive integers greater than 0. The first line of data in the triangle will have one number, the second line in the triangle will have two numbers and so on. The nth line will have n integers.
You will apply four different approaches to problem solving to this single problem - exhaustive search (recursive), greedy, divide and conquer (recursive), and dynamic programming. The functions - brute_force(), greedy(), divide_conquer(), and dynamic_prog() are wrapper functions. You must use the grid returned from calling the read_file() function. You cannot change the header of any of the given functions but you can always add more helper functions.
Both the exhaustive search and the divide and conquer methods are recursive. Here is the difference. In the exhaustive search you will store all the path sums. You will then find the maximum from all the path sums. In the divide and conquer method you will only get back a single number that is the maximum path sum. The exhaustive search will give you a lot more information if you need it. For example, you can get the minimum, mean, median, standard deviation, and the frequency distribution of the path sums. The amount of time taken to do the exhaustive search and the divide and conquer should be about the same. The exhaustive search maybe a tad longer.
You will have these lines of output:
The greatest path sum through exhaustive search is 23 The time taken for exhaustive search in seconds is x The greatest path sum through greedy search is 23 The time taken for greedy approach in seconds is x The greatest path sum through recursive search is 23 The time taken for recursive search in seconds is x The greatest path sum through dynamic programming is 23 The time taken for dynamic programming in seconds is xMost likely the maximum path that you will get from exhaustive search, recursive search, and dynamic programming will be the same. Whereas the result from the greedy search will be less and so will be the execution time.
Here is the template of the file called Triangle.py that you will be turning in. We are looking for clean and structured design using the standard coding conventions in Python. You may not change the function signatures but you may add as many helper functions as needed. The file will have a header of the following form:
# File: Triangle.py # Description: # Student's Name: # Student's UT EID: # Partner's Name: # Partner's UT EID: # Course Name: CS 313E # Unique Number: # Date Created: # Date Last Modified:To run this code on the command line on the Mac you will do
python3 Triangle.py < triangle.inTo run the code on the command line on a Windows machine you will do
python Triangle.py < triangle.in
For this assignment you may work with a partner. Both of you must read the paper on Pair Programming and abide by the ground rules as stated in that paper. If you are working with a partner you will be submitting only one program but make sure that you have your partner's name and eid in your program. If you are working alone, then remove the two lines that has the partner's name and eid in the header.
Use the Canvas system to submit your Triangle.py file. We should receive your work by 11 PM on Friday, 04 Mar 2022. There will be substantial penalties if you do not adhere to the guidelines. Remember Python is case sensitive. The name of your file must match exactly what we have specified.