https://github.com/gregorybchris/interval-tree
Swift implementation of AVL balanced interval trees
https://github.com/gregorybchris/interval-tree
Last synced: 3 months ago
JSON representation
Swift implementation of AVL balanced interval trees
- Host: GitHub
- URL: https://github.com/gregorybchris/interval-tree
- Owner: gregorybchris
- Created: 2015-12-25T02:34:16.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-03-10T05:22:09.000Z (almost 5 years ago)
- Last Synced: 2025-03-02T02:33:26.766Z (11 months ago)
- Language: Swift
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Interval Tree
## Problem
You own a small business that supplies gondola rides to tourists. Unfortunately, because of the reckless nature of tourists in your area, you find yourself constantly making repairs on your gondolas. Some days your fleet is drastically diminished and you worry about not having enough operational gondolas to accommodate your customers. However, you do know the start and end times for all trips on a given day. You figure there must be a way to determine the minimum number of boats you need to get through a day without delays.
## My Solution
1. Take as input a list of time intervals representing the start and end times for gondola trips on a given day.
2. Determine overlap between trips efficiently by inserting each interval into an interval tree (AVL tree).
3. Construct a graph where trips are represented by vertices and overlap between two trips is represented as an edge between two vertices.
4. Color the graph vertices such that no two adjacent vertices have the same color using as few colors as possible.
The total number of colors used is the number of operational gondolas needed and the vertex color can be used to select the boat for that trip.