GithubHelp home page GithubHelp logo

srcmake / segment-tree Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 3.0 38 KB

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: MIT License

C++ 99.59% Makefile 0.41%

segment-tree's Introduction

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.

segment-tree's People

Contributors

srcmake avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.