Python Matplotlib比较贪心算法和动态规划算法的执行时间
import numpy as np
import matplotlib.pyplot as plt
# 生成模拟数据
n_values = np.array([10, 20, 30, 40, 50])
greedy_times = np.array([0.1, 0.5, 1.2, 2.3, 4.0])
dp_times = np.array([0.2, 0.8, 1.5, 3.0, 5.5])
# 绘制曲线图
plt.plot(n_values, greedy_times, label='Greedy')
plt.plot(n_values, dp_times, label='Dynamic Programming')
# 添加标题和标签
plt.xlabel('Number of activities')
plt.ylabel('Execution time')
plt.legend()
# 显示图形
plt.show()
原文地址: https://www.cveoy.top/t/topic/fwDK 著作权归作者所有。请勿转载和采集!