Learn R Programming

MESS (version 0.5.12)

maximum_subarray: Fast computation of maximum sum subarray

Description

Fast computation of the maximum subarray sum of a vector using Kadane's algorithm. The implementation handles purely negative numbers.

Usage

maximum_subarray(x)

Value

A list with three elements: sum (the maximum subarray sum), start (the starting index of the subarray) and end (the ending index of the subarray)

Arguments

x

A vector

Author

Claus Ekstrom <claus@rprimer.dk>

Examples

Run this code

maximum_subarray(1:4)

maximum_subarray(c(-2, 1, -3, 4, -1, 2, 1, -5, 4))
 
maximum_subarray(rnorm(100000))

Run the code above in your browser using DataLab