Skip to content

A C++ example of a segment tree for Range Minimum Query (RMQ). Tutorial can be found (eventually) at www.srcmake.com/home/segment-tree

License

Notifications You must be signed in to change notification settings

srcmake/segment-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Segment Trees

Segment Trees are data structures that let you easily find the minimum, maximum, or sum over a given subrange of a larger range.

I've created a tutorial explaining how segment trees work and the process of building/updating/querying one here.

This repository contains a C++ class that implements a segment tree for a minimum (Range Minimum Query) example.

Please note that I've intentionally left the code unoptimized for the reader to make better, as this code is meant to be easily understandable to the viewer, not necessarily the most efficient implementation.

File Structure

The segment tree code exists as a class in segment-tree.hpp. The class is encapsulated within a namespace of srcmake to avoid any collisions with another library's segment tree.

(I've also bundled the header file with the cpp file because realistically when using a segment tree in an algorithm competition, we just want to be able to copy and paste the entire thing without worrying about eloquent file structures.)

main.cpp has a single main function that calls the segment-tree class with some example queries.

Deployment

The makefile will compile the project with C++14 (the version was chosen arbitrarily, we're not really using any special language features).

On Linux/Mac, as long as you have GCC, the following command will compile and run the project.

make

LICENSE

This code is licensed under the MIT License.

About

A C++ example of a segment tree for Range Minimum Query (RMQ). Tutorial can be found (eventually) at www.srcmake.com/home/segment-tree

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published