From e272befbd7f2ea4a8d899e816f9cba0e2c92ef07 Mon Sep 17 00:00:00 2001 From: ABHISHEK-821005 <69668943+ABHISHEK-821005@users.noreply.github.com> Date: Mon, 26 Oct 2020 12:51:34 +0530 Subject: [PATCH] updated time complexity if all the prices are same case(o(n)). --- dynamic_programming/cut_rod.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/dynamic_programming/cut_rod.cpp b/dynamic_programming/cut_rod.cpp index e67c3eb4a..5aeb801f5 100644 --- a/dynamic_programming/cut_rod.cpp +++ b/dynamic_programming/cut_rod.cpp @@ -61,18 +61,11 @@ int maxProfitByCuttingRod(const std::array &price, const int n) { delete[] profit; return ans; // returning maximum profit } -} // namespace cut_rod -} // namespace dynamic_programming - -/** - * @brief Function to test above algorithm - * @returns void - */ template -bool WhatIfAllPricesAreSame(const std::array &price, const int n){ +bool WhatIfAllPricesAreSame(const std::array &price, const uint64_t &n){ /* @@ -108,7 +101,18 @@ CR(0) } return true; -} +}// checks whether all the prices are same or not + + +} // namespace cut_rod +} // namespace dynamic_programming + +/** + * @brief Function to test above algorithm + * @returns void + */ + + static void test() { @@ -119,7 +123,7 @@ static void test() { dynamic_programming::cut_rod::maxProfitByCuttingRod(price1, n1); const int expected_max_profit1 = 22; - if( WhatIfAllPricesAreSame(price1,n1)){ + if(dynamic_programming::cut_rod::WhatIfAllPricesAreSame(price1,n1)){ std::cout << "Maximum profit with " << n1 << " inch road is " <<(n1)*price1[0] << std::endl; }