https://github.com/biserkov/twotree-longest-path
The code from my master thesis. 100.0% Clojure.
https://github.com/biserkov/twotree-longest-path
2-tree algorithm clojure complexity graph iterative linear longest-path memoization property-based-testing recursive transients
Last synced: about 1 month ago
JSON representation
The code from my master thesis. 100.0% Clojure.
- Host: GitHub
- URL: https://github.com/biserkov/twotree-longest-path
- Owner: Biserkov
- Created: 2016-12-04T12:29:18.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-19T13:46:14.000Z (about 7 years ago)
- Last Synced: 2025-10-22T00:06:41.503Z (about 1 month ago)
- Topics: 2-tree, algorithm, clojure, complexity, graph, iterative, linear, longest-path, memoization, property-based-testing, recursive, transients
- Language: Clojure
- Homepage:
- Size: 71.3 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# O(n) algorithm for computing longest paths in 2-trees
[](https://clojars.org/twotree.longest-path)
[](https://cljdoc.xyz/d/twotree.longest-path/twotree.longest-path/CURRENT)
## Overview
In 2013 Markov, Vassilev and Manev published a novel linear time [algorithm](https://sites.google.com/site/minkommarkov/longest-2-tree--draft.pdf?attredirects=0&d=1) for computing longest paths in 2-trees.
This repository contains 3 implementations of said algorithm in Clojure:
The [first](https://github.com/Biserkov/twotree-longest-path/blob/master/test/longest_path/direct.clj) one is a direct implementation of the mathematical operations described in the paper. Due to the need to construct subgraphs to implement splitting, the time complexity is ```O(n√n)```.
The [second](https://github.com/Biserkov/twotree-longest-path/blob/master/test/longest_path/preprocessed.clj) one was suggested by Minko Markov and preprocesses the 2-tree, thus avoiding the need to construct subgraphs. The time complexity is ```O(n)```. Due to its recursive nature, this implementation will fail with a Stack Overflow Error if used on deep 2-trees with millions of vertices.
The [third](https://github.com/Biserkov/twotree-longest-path/blob/master/src/longest_path/iterative.clj) implementation is an iterative one. It uses the EdgeLabels map as a sort of explicit call stack. The time complexity is ```O(n)```.
Only the third one should be used for any practical purposes.
## Data representation
The vertices of the graph are represented as positive integers.
On an abstract lever, the graph is represented as an adjacency list.
On a concrete level, it's a int-map in which a vertex acts as key and the corresponding values is an int-set of the its neighbours.