Range minimum query

Finds the position of the minimum element between two given indices in an array in constant time.
다운로드 수: 123
업데이트 날짜: 2014/12/22

라이선스 보기

Given an array A[1...N], it finds the position of the element with the minimum value between two given indices.
It returns the answer in constant time. The RMQ problem can be used to recover the lca (lowest common ancestor) in a graph in constant time. See http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAncestor for more details.
Time complexity: O(N log(N))
Space complexity: O(N log(N))
Example
A = [-1 5 0 3 -6 4 2 1 0 -1];
N = length(A);
M = rmq(A);
% Find the position of the minimum element between indices i, j
i = 2;
j = 6;
k = floor(log2(j - i + 1));
if A(M(i,k+1)) <= A(M(j-2^k+1,k+1))
idx = M(i,k+1);
else
idx = M(j-2^k+1,k+1);
end

인용 양식

Georgios Papachristoudis (2026). Range minimum query (https://kr.mathworks.com/matlabcentral/fileexchange/48841-range-minimum-query), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2014b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Matrices and Arrays에 대해 자세히 알아보기
태그 태그 추가
rmq
버전 게시됨 릴리스 정보
1.1.0.0

I changed the title to a more descriptive one and added an image.

1.0.0.0