diff --git a/d2/de6/maximum__circular__subarray_8cpp__incl.map b/d2/de6/maximum__circular__subarray_8cpp__incl.map new file mode 100644 index 000000000..65cec5a3a --- /dev/null +++ b/d2/de6/maximum__circular__subarray_8cpp__incl.map @@ -0,0 +1,6 @@ + + + + + + diff --git a/d2/de6/maximum__circular__subarray_8cpp__incl.md5 b/d2/de6/maximum__circular__subarray_8cpp__incl.md5 new file mode 100644 index 000000000..51acae7b2 --- /dev/null +++ b/d2/de6/maximum__circular__subarray_8cpp__incl.md5 @@ -0,0 +1 @@ +f0f9267453022819cf85e054483aa620 \ No newline at end of file diff --git a/d2/de6/maximum__circular__subarray_8cpp__incl.svg b/d2/de6/maximum__circular__subarray_8cpp__incl.svg new file mode 100644 index 000000000..b732df4f6 --- /dev/null +++ b/d2/de6/maximum__circular__subarray_8cpp__incl.svg @@ -0,0 +1,67 @@ + + + + + + +dynamic_programming/maximum_circular_subarray.cpp + + +Node1 + + +dynamic_programming +/maximum_circular_subarray.cpp + + + + + +Node2 + + +cassert + + + + + +Node1->Node2 + + + + + +Node3 + + +iostream + + + + + +Node1->Node3 + + + + + +Node4 + + +vector + + + + + +Node1->Node4 + + + + + diff --git a/d5/d88/md__d_i_r_e_c_t_o_r_y.html b/d5/d88/md__d_i_r_e_c_t_o_r_y.html index 36c372448..cc022972a 100644 --- a/d5/d88/md__d_i_r_e_c_t_o_r_y.html +++ b/d5/d88/md__d_i_r_e_c_t_o_r_y.html @@ -223,6 +223,7 @@ Dynamic Programming
  • Longest Increasing Subsequence (Nlogn)
  • Longest Palindromic Subsequence
  • Matrix Chain Multiplication
  • +
  • Maximum Circular Subarray
  • Minimum Edit Distance
  • Palindrome Partitioning
  • Partition Problem
  • diff --git a/db/dfb/maximum__circular__subarray_8cpp.html b/db/dfb/maximum__circular__subarray_8cpp.html new file mode 100644 index 000000000..09ab08212 --- /dev/null +++ b/db/dfb/maximum__circular__subarray_8cpp.html @@ -0,0 +1,252 @@ + + + + + + + +Algorithms_in_C++: dynamic_programming/maximum_circular_subarray.cpp File Reference + + + + + + + + + + + + + + + +
    +
    + + + + + + +
    +
    Algorithms_in_C++ 1.0.0 +
    +
    Set of algorithms implemented in C++.
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    Loading...
    +
    Searching...
    +
    No Matches
    +
    +
    +
    +
    + +
    + +
    maximum_circular_subarray.cpp File Reference
    +
    +
    + +

    C++ program for maximum contiguous circular sum problem using Kadane's Algorithm +More...

    +
    #include <cassert>
    +#include <iostream>
    +#include <vector>
    +
    +Include dependency graph for maximum_circular_subarray.cpp:
    +
    +
    +
    +
    +
    + + + + +

    +Namespaces

    namespace  dynamic_programming
     Dynamic Programming algorithms.
     
    + + + + + + + + + + +

    +Functions

    int dynamic_programming::maxCircularSum (std::vector< int > &arr)
     returns the maximum contiguous circular sum of an array
     
    static void test ()
     Self-test implementation.
     
    int main (int argc, char *argv[])
     Main function.
     
    +

    Detailed Description

    +

    C++ program for maximum contiguous circular sum problem using Kadane's Algorithm

    +

    The idea is to modify Kadane’s algorithm to find a minimum contiguous subarray sum and the maximum contiguous subarray sum, then check for the maximum value between the max_value and the value left after subtracting min_value from the total sum. For more information, check Geeks For Geeks explanation page.

    +

    Function Documentation

    + +

    ◆ main()

    + +
    +
    + + + + + + + + + + + + + + + + + + +
    int main (int argc,
    char * argv[] 
    )
    +
    + +

    Main function.

    +
    Parameters
    + + + +
    argccommandline argument count (ignored)
    argvcommandline array of arguments (ignored)
    +
    +
    +
    Returns
    0 on exit
    +
    87 {
    +
    88 test(); // run self-test implementations
    +
    89 return 0;
    +
    90}
    +
    static void test()
    Self-test implementation.
    Definition: maximum_circular_subarray.cpp:64
    +
    +Here is the call graph for this function:
    +
    +
    +
    +
    + +
    +
    + +

    ◆ test()

    + +
    +
    + + + + + +
    + + + + + + + +
    static void test ()
    +
    +static
    +
    + +

    Self-test implementation.

    +
    Returns
    void
    +
    64 {
    +
    65 // Description of the test
    +
    66 // Input: arr[] = {8, -8, 9, -9, 10, -11, 12}
    +
    67 // Output: 22
    +
    68 // Explanation: Subarray 12, 8, -8, 9, -9, 10 gives the maximum sum, that is 22.
    +
    69
    +
    70 int n = 7; // size of the array
    +
    71 std::vector<int> arr = {8, -8, 9, -9, 10, -11, 12};
    +
    72 assert(dynamic_programming::maxCircularSum(arr) == 22); // this ensures that the algorithm works as expected
    +
    73
    +
    74 arr = {8, -8, 10, -9, 10, -11, 12};
    +
    75 assert(dynamic_programming::maxCircularSum(arr) == 23);
    +
    76
    +
    77 std::cout << "All tests have successfully passed!\n";
    +
    78}
    + +
    int maxCircularSum(std::vector< int > &arr)
    returns the maximum contiguous circular sum of an array
    Definition: maximum_circular_subarray.cpp:26
    + +
    +Here is the call graph for this function:
    +
    +
    +
    +
    + +
    +
    +
    +
    + + + + diff --git a/db/dfb/maximum__circular__subarray_8cpp.js b/db/dfb/maximum__circular__subarray_8cpp.js new file mode 100644 index 000000000..d414e4819 --- /dev/null +++ b/db/dfb/maximum__circular__subarray_8cpp.js @@ -0,0 +1,6 @@ +var maximum__circular__subarray_8cpp = +[ + [ "main", "db/dfb/maximum__circular__subarray_8cpp.html#a0ddf1224851353fc92bfbff6f499fa97", null ], + [ "maxCircularSum", "db/dfb/maximum__circular__subarray_8cpp.html#a5239174fa0d987f2c67edc1f2af82beb", null ], + [ "test", "db/dfb/maximum__circular__subarray_8cpp.html#aa8dca7b867074164d5f45b0f3851269d", null ] +]; \ No newline at end of file diff --git a/db/dfb/maximum__circular__subarray_8cpp_a0ddf1224851353fc92bfbff6f499fa97_cgraph.map b/db/dfb/maximum__circular__subarray_8cpp_a0ddf1224851353fc92bfbff6f499fa97_cgraph.map new file mode 100644 index 000000000..d2bab2969 --- /dev/null +++ b/db/dfb/maximum__circular__subarray_8cpp_a0ddf1224851353fc92bfbff6f499fa97_cgraph.map @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/db/dfb/maximum__circular__subarray_8cpp_a0ddf1224851353fc92bfbff6f499fa97_cgraph.md5 b/db/dfb/maximum__circular__subarray_8cpp_a0ddf1224851353fc92bfbff6f499fa97_cgraph.md5 new file mode 100644 index 000000000..2b45a49e5 --- /dev/null +++ b/db/dfb/maximum__circular__subarray_8cpp_a0ddf1224851353fc92bfbff6f499fa97_cgraph.md5 @@ -0,0 +1 @@ +5a1c3f652767703f55593fc0a2bfc8b1 \ No newline at end of file diff --git a/db/dfb/maximum__circular__subarray_8cpp_a0ddf1224851353fc92bfbff6f499fa97_cgraph.svg b/db/dfb/maximum__circular__subarray_8cpp_a0ddf1224851353fc92bfbff6f499fa97_cgraph.svg new file mode 100644 index 000000000..20b7ab1e9 --- /dev/null +++ b/db/dfb/maximum__circular__subarray_8cpp_a0ddf1224851353fc92bfbff6f499fa97_cgraph.svg @@ -0,0 +1,97 @@ + + + + + + +main + + +Node1 + + +main + + + + + +Node2 + + +test + + + + + +Node1->Node2 + + + + + +Node3 + + +dynamic_programming +::maxCircularSum + + + + + +Node2->Node3 + + + + + +Node4 + + +std::max + + + + + +Node3->Node4 + + + + + +Node5 + + +std::min + + + + + +Node3->Node5 + + + + + +Node6 + + +std::vector::size + + + + + +Node3->Node6 + + + + + diff --git a/db/dfb/maximum__circular__subarray_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map b/db/dfb/maximum__circular__subarray_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map new file mode 100644 index 000000000..45822ac86 --- /dev/null +++ b/db/dfb/maximum__circular__subarray_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map @@ -0,0 +1,7 @@ + + + + + + + diff --git a/db/dfb/maximum__circular__subarray_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 b/db/dfb/maximum__circular__subarray_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 new file mode 100644 index 000000000..e2ca908ae --- /dev/null +++ b/db/dfb/maximum__circular__subarray_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 @@ -0,0 +1 @@ +4056e69d4c435b34f1f9f925293a7af6 \ No newline at end of file diff --git a/db/dfb/maximum__circular__subarray_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg b/db/dfb/maximum__circular__subarray_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg new file mode 100644 index 000000000..ed43fb919 --- /dev/null +++ b/db/dfb/maximum__circular__subarray_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg @@ -0,0 +1,82 @@ + + + + + + +test + + +Node1 + + +test + + + + + +Node2 + + +dynamic_programming +::maxCircularSum + + + + + +Node1->Node2 + + + + + +Node3 + + +std::max + + + + + +Node2->Node3 + + + + + +Node4 + + +std::min + + + + + +Node2->Node4 + + + + + +Node5 + + +std::vector::size + + + + + +Node2->Node5 + + + + + diff --git a/dd/d24/namespacedynamic__programming.html b/dd/d24/namespacedynamic__programming.html index a1b8e0d06..81caf3459 100644 --- a/dd/d24/namespacedynamic__programming.html +++ b/dd/d24/namespacedynamic__programming.html @@ -111,6 +111,9 @@ Functions uint64_t LIS (const std::vector< uint64_t > &a, const uint32_t &n)  Calculate the longest increasing subsequence for the specified numbers.
      +int maxCircularSum (std::vector< int > &arr) + returns the maximum contiguous circular sum of an array

    Detailed Description

    Dynamic Programming algorithms.

    @@ -190,6 +193,72 @@ Here is the call graph for this function:
    + + + +

    ◆ maxCircularSum()

    + +
    +
    + + + + + + + + +
    int dynamic_programming::maxCircularSum (std::vector< int > & arr)
    +
    + +

    returns the maximum contiguous circular sum of an array

    +
    Parameters
    + + +
    arris the array/vector
    +
    +
    +
    Returns
    int which is the maximum sum
    +
    27{
    +
    28 // Edge Case
    +
    29 if (arr.size() == 1)
    +
    30 return arr[0];
    +
    31
    +
    32 // Sum variable which stores total sum of the array.
    +
    33 int sum = 0;
    +
    34 for (int i = 0; i < arr.size(); i++) {
    +
    35 sum += arr[i];
    +
    36 }
    +
    37
    +
    38 // Every variable stores first value of the array.
    +
    39 int current_max = arr[0], max_so_far = arr[0], current_min = arr[0], min_so_far = arr[0];
    +
    40
    +
    41 // Concept of Kadane's Algorithm
    +
    42 for (int i = 1; i < arr.size(); i++) {
    +
    43 // Kadane's Algorithm to find Maximum subarray sum.
    +
    44 current_max = std::max(current_max + arr[i], arr[i]);
    +
    45 max_so_far = std::max(max_so_far, current_max);
    +
    46
    +
    47 // Kadane's Algorithm to find Minimum subarray sum.
    +
    48 current_min = std::min(current_min + arr[i], arr[i]);
    +
    49 min_so_far = std::min(min_so_far, current_min);
    +
    50 }
    +
    51
    +
    52 if (min_so_far == sum)
    +
    53 return max_so_far;
    +
    54
    +
    55 // Return the maximum value
    +
    56 return std::max(max_so_far, sum - min_so_far);
    +
    57}
    +
    T min(T... args)
    +
    T size(T... args)
    +
    +Here is the call graph for this function:
    +
    +
    +
    +
    +
    diff --git a/dd/d24/namespacedynamic__programming_a5239174fa0d987f2c67edc1f2af82beb_cgraph.map b/dd/d24/namespacedynamic__programming_a5239174fa0d987f2c67edc1f2af82beb_cgraph.map new file mode 100644 index 000000000..4355d6184 --- /dev/null +++ b/dd/d24/namespacedynamic__programming_a5239174fa0d987f2c67edc1f2af82beb_cgraph.map @@ -0,0 +1,6 @@ + + + + + + diff --git a/dd/d24/namespacedynamic__programming_a5239174fa0d987f2c67edc1f2af82beb_cgraph.md5 b/dd/d24/namespacedynamic__programming_a5239174fa0d987f2c67edc1f2af82beb_cgraph.md5 new file mode 100644 index 000000000..1f25062ca --- /dev/null +++ b/dd/d24/namespacedynamic__programming_a5239174fa0d987f2c67edc1f2af82beb_cgraph.md5 @@ -0,0 +1 @@ +a4b53ef7a5f58d91d834f25179f45812 \ No newline at end of file diff --git a/dd/d24/namespacedynamic__programming_a5239174fa0d987f2c67edc1f2af82beb_cgraph.svg b/dd/d24/namespacedynamic__programming_a5239174fa0d987f2c67edc1f2af82beb_cgraph.svg new file mode 100644 index 000000000..74e4ed8a4 --- /dev/null +++ b/dd/d24/namespacedynamic__programming_a5239174fa0d987f2c67edc1f2af82beb_cgraph.svg @@ -0,0 +1,67 @@ + + + + + + +dynamic_programming::maxCircularSum + + +Node1 + + +dynamic_programming +::maxCircularSum + + + + + +Node2 + + +std::max + + + + + +Node1->Node2 + + + + + +Node3 + + +std::min + + + + + +Node1->Node3 + + + + + +Node4 + + +std::vector::size + + + + + +Node1->Node4 + + + + + diff --git a/dir_8a20dd5bfd5341a725342bf72b6b686f.html b/dir_8a20dd5bfd5341a725342bf72b6b686f.html index a1cf1aad8..3d50e33ef 100644 --- a/dir_8a20dd5bfd5341a725342bf72b6b686f.html +++ b/dir_8a20dd5bfd5341a725342bf72b6b686f.html @@ -127,6 +127,9 @@ Files file  longest_palindromic_subsequence.cpp  Program to find the Longest Palindormic Subsequence of a string.
      +file  maximum_circular_subarray.cpp + C++ program for maximum contiguous circular sum problem using Kadane's Algorithm
    +  file  minimum_edit_distance.cpp  Implementation of Minimum Edit Distance using Dynamic Programing.
      diff --git a/dir_8a20dd5bfd5341a725342bf72b6b686f.js b/dir_8a20dd5bfd5341a725342bf72b6b686f.js index f89660c9c..7c4e95f81 100644 --- a/dir_8a20dd5bfd5341a725342bf72b6b686f.js +++ b/dir_8a20dd5bfd5341a725342bf72b6b686f.js @@ -8,6 +8,7 @@ var dir_8a20dd5bfd5341a725342bf72b6b686f = [ "kadane2.cpp", "db/dca/kadane2_8cpp.html", "db/dca/kadane2_8cpp" ], [ "longest_increasing_subsequence.cpp", "d7/d57/longest__increasing__subsequence_8cpp.html", "d7/d57/longest__increasing__subsequence_8cpp" ], [ "longest_palindromic_subsequence.cpp", "d0/d77/longest__palindromic__subsequence_8cpp.html", "d0/d77/longest__palindromic__subsequence_8cpp" ], + [ "maximum_circular_subarray.cpp", "db/dfb/maximum__circular__subarray_8cpp.html", "db/dfb/maximum__circular__subarray_8cpp" ], [ "minimum_edit_distance.cpp", "da/d52/minimum__edit__distance_8cpp.html", "da/d52/minimum__edit__distance_8cpp" ], [ "palindrome_partitioning.cpp", "d5/d90/palindrome__partitioning_8cpp.html", "d5/d90/palindrome__partitioning_8cpp" ], [ "shortest_common_supersequence.cpp", "d7/d65/shortest__common__supersequence_8cpp.html", "d7/d65/shortest__common__supersequence_8cpp" ], diff --git a/files.html b/files.html index a9180a666..3e1b29f24 100644 --- a/files.html +++ b/files.html @@ -174,11 +174,12 @@ solve-a-rat-in-a-maze-c-java-pytho/" target="_blank">Rat in a Maze algorithm  kadane2.cppImplementation of Kadane Algorithm  longest_increasing_subsequence.cppCalculate the length of the longest increasing subsequence in an array  longest_palindromic_subsequence.cppProgram to find the Longest Palindormic Subsequence of a string - minimum_edit_distance.cppImplementation of Minimum Edit Distance using Dynamic Programing - palindrome_partitioning.cppImplements Palindrome Partitioning algorithm, giving you the minimum number of partitions you need to make - shortest_common_supersequence.cppSCS is a string Z which is the shortest supersequence of strings X and Y (may not be continuous in Z, but order is maintained) - subset_sum.cppImplements [Sub-set sum problem] (https://en.wikipedia.org/wiki/Subset_sum_problem) algorithm, which tells whether a subset with target sum exists or not - word_break.cppWord Break Problem + maximum_circular_subarray.cppC++ program for maximum contiguous circular sum problem using Kadane's Algorithm + minimum_edit_distance.cppImplementation of Minimum Edit Distance using Dynamic Programing + palindrome_partitioning.cppImplements Palindrome Partitioning algorithm, giving you the minimum number of partitions you need to make + shortest_common_supersequence.cppSCS is a string Z which is the shortest supersequence of strings X and Y (may not be continuous in Z, but order is maintained) + subset_sum.cppImplements [Sub-set sum problem] (https://en.wikipedia.org/wiki/Subset_sum_problem) algorithm, which tells whether a subset with target sum exists or not + word_break.cppWord Break Problem   geometry  graham_scan_functions.hpp  jarvis_algorithm.cppImplementation of Jarvis’s algorithm diff --git a/globals_func_i.html b/globals_func_i.html index d8a85457a..1517fd721 100644 --- a/globals_func_i.html +++ b/globals_func_i.html @@ -111,8 +111,8 @@ $(document).ready(function(){initNavTree('globals_func_i.html',''); initResizabl
  • is_happy() : happy_number.cpp
  • is_prime() : check_prime.cpp
  • is_square() : ordinary_least_squares_regressor.cpp
  • -
  • isPrime() : modular_inverse_fermat_little_theorem.cpp
  • IsPrime() : primality_test.cpp
  • +
  • isPrime() : modular_inverse_fermat_little_theorem.cpp
  • it_ternary_search() : ternary_search.cpp
  • diff --git a/globals_func_m.html b/globals_func_m.html index 0cdbce4c6..875d5b196 100644 --- a/globals_func_m.html +++ b/globals_func_m.html @@ -100,7 +100,7 @@ $(document).ready(function(){initNavTree('globals_func_m.html',''); initResizabl  

    - m -