Skip to content

Commit e1de83b

Browse files
Copilotgjbex
andcommitted
Add array-based intersection tree implementation with comprehensive testing and analysis
Co-authored-by: gjbex <4801336+gjbex@users.noreply.github.com>
1 parent da61da1 commit e1de83b

File tree

5 files changed

+1060
-1
lines changed

5 files changed

+1060
-1
lines changed

source_code/intersection_trees/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,27 @@ on intervals.
1313
uses sets and named tuples.
1414
1. `naive_intersectionic_queries.py`: brute force implementaion that
1515
uses lists and tuples.
16-
1. `interval_tree.py`: implementation of an interval tree.
16+
1. `intersection_tree.py`: implementation of an intersection tree using traditional node-based structure.
17+
1. `array_intersection_tree.py`: alternative array-based implementation of an intersection tree.
18+
1. `test_comparison.py`: comprehensive test suite comparing both implementations.
19+
1. `performance_analysis.py`: detailed performance analysis and benchmarking tools.
20+
21+
## Implementation Comparison
22+
23+
### Traditional Node-based Tree (`intersection_tree.py`)
24+
- Uses traditional tree nodes with object references
25+
- Each node is a separate object with `start`, `end`, `max_end`, `left`, `right` attributes
26+
- More intuitive object-oriented design
27+
- Faster execution time due to direct object access
28+
29+
### Array-based Tree (`array_intersection_tree.py`)
30+
- Uses arrays to store tree data: `start[]`, `end[]`, `max_end[]`, `left[]`, `right[]`
31+
- Nodes are represented as indices into these arrays
32+
- Better memory density (~70% memory savings)
33+
- Slightly slower execution (~20% overhead) due to array indexing
34+
35+
### Performance Characteristics
36+
- **Memory Usage**: Array-based implementation uses ~70% less memory
37+
- **Execution Speed**: Traditional implementation is ~20% faster
38+
- **Cache Locality**: Array-based shows potential for better cache performance with sequential access patterns
39+
- **Scalability**: Both implementations scale similarly with increasing dataset size

0 commit comments

Comments
 (0)