Question: Do the following tasks: i . Design and implement an efficient algorithm that computes the OSR metric for the MCM Problem's DP solution and generates

Do the following tasks:
i. Design and implement an efficient algorithm that computes the OSR metric for the MCM Problem's DP solution and generates the OSR metric table up to an entered table size (See the sample output below)(80 pts )
ii. Analyze your algorithm's time complexity by making comments about it. There is no need for line by line analysis. (20 pts)
SAMPLE OUTPUT:
Enter table size: 10
Reference:
[1] Cormen, T., Leiserson, C., Rivest, R. and Stein, C., Introduction to Algorithms (Third Edition), The MIT Press, 2009, ISBN: 978-0-262-03384-8
PS:
1. You are required to work either alone or in at most three-person groups.
2. If you wish to work as a group, all the group members should send an e-mail (furkan.bakal@atilim.edu.tr) indicating the name of his/her agreed group member until 08.12.2024(Sunday) Hr:23:59. Otherwise, it is assumed that you will work alone (by default).
3. Note that besides submitting the homework, you are also required to attend code review \& demonstration of your code.
4. Percentages of written part submission and demo parts are \(\%70\) and \(\%30\) of your overall Homework \#2 grade, respectively. Submissions without code review \& demonstrations gets \(\mathbf{0}\)(zero) grade from both parts, directly.
5. Time table for the code review \& demos to be announced later via course Moodle site.
6. For Part 1, you can prefer any one of the programming languages \(\mathbf{C},\mathbf{C}_{++}\)or Python as your implementation language. Do NOT submit a screen shot of your source code but submit it as a text file!!!
7. Your answer for Part \(\mathbf{2}\) should be submitted as a handwritten separate file.
I made this code def compute_osr_metric(n):
"""
Function to compute overlapping recursive calls, total recursive calls,
and the OSR metric based on matrix chain multiplication.
"""
if n ==1:
overlapping_calls =0
total_calls =1
elif n ==2:
overlapping_calls =0
total_calls =3
else:
total_calls =3**(n -1)# Total recursive calls
overlapping_calls = total_calls -(n *(n -1))# Overlapping calls using the provided formula
# OSR metric result: overlapping_calls / total_calls
osr_metric = overlapping_calls / total_calls if total_calls !=0 else 0
return overlapping_calls, total_calls, osr_metric
def generate_table(size):
print(f"
{'Matrix Chain Size':20}{'Total Recursive Calls':30}"
f"{'Overlapping Recursive Calls':30}{'OSR (Overlapping Subproblem Ratio)':20}")
print("-"*100)
for n in range(1, size +1):
overlapping_calls, total_calls, osr_metric = compute_osr_metric(n)
print(f"{n:20}{total_calls:30}{overlapping_calls:30}{osr_metric:20.4f}")
def main():
print("OSR Metric Table Generator")
try:
table_size = int(input("Enter the number of matrices (size n): "))
if table_size =0:
print("Please enter a positive integer for the table size.")
return
generate_table(table_size)
except ValueError:
print("Invalid input. Please enter an integer for the table size.")
if __name__=="__main__":
main()
but this code is not calculate overlapping recursivce calls truely I need help for calculate them correct. I guess correct ones something like
Do the following tasks: i . Design and implement

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!