Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions doc/sketch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
This documents intends to give an overview of the time complexity of the different graph transformations implemented by the various data types existent in Alga.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"time" -> "time and memory"


When specifying the time and memory complexity of graph algorithms, _n_ will denote the number of vertices in the graph, _m_ will denote the number of edges in the graph, and _s_ will denote the _size_ of the corresponding `Graph` expression.

**`removeVertex`**: Removes a vertex from a given graph. In `NonEmpty` graphs, returns `Nothing` if the resulting graph is empty.

| removeVertex | Time | Memory |
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first header here should probably be Data type instead of removeVertex (same for other tables).

|--------------------|---------------|--------|
| AdjacencyMap | `O(n * log(n))` | ` ` |
| Fold | `O(s)` | `O(s)` |
| HigherKinded.Class | `O(s)` | `O(s)` |
| IntAdjacencyMap | `O(log(n))` | `O(s)` |
| NonEmpty | `O(s)` | ` ` |
| Relation | `O(n+m)`| ` ` |
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't cover Graph in this table -- is this because the implementation simply reuses HigherKinded.Class.removeVertex?

I think it would be nice to have an entry for Graph as well, since at some point we might change the implementation and it will no longer rely on HigherKinded.Class.


**`removeEdge`**: Removes an edge from a given graph.

| removeEdge | Time | Memory |
|--------------------|-----------|--------|
| AdjacencyMap | `O(log(n))` | ` ` |
| Fold | `O(s)` | `O(s)` |
| IntAdjacencyMap | `O(log(n))` | ` ` |
| NonEmpty | `O(s)` | `O(s)` |
| Relation | `O(log(m))` | ` ` |

**`replaceVertex`**: Replaces a vertex `x` with a vertex `y` in a given `AdjacencyMap`. If `y` already exists, `x` and `y` will be merged.
Copy link
Copy Markdown
Owner

@snowleopard snowleopard May 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"AdjacencyMap" -> "graph".


| replaceVertex | Time | Memory |
|--------------------|-------------------|--------|
| AdjacencyMap | `O((n+m)*log(n))` | ` ` |
| Fold | `O(s)` | `O(s)` |
| HigherKinded.Class | `O(s)` | `O(s)` |
| IntAdjacencyMap | `O((n+m)*log(n))` | ` ` |
| NonEmpty | `O(s)` | `O(s)` |
| Relation | `O((n+m)*log(n))` | ` ` |

**`mergeVertices`**: Merge vertices sastisfying a given predicate into a given vertex.

| mergeVertices | Time | Memory |
|--------------------|-------------------|--------|
| AdjacencyMap | `O((n+m) * log(n))` assuming predicate computes in `O(1)` | ` ` |
| Fold | `O(s)` assuming predicate computes in `O(1)` | `O(s)` assuming predicate computes in `O(1)` |
| HigherKinded.Class | `O(s)` assuming predicate computes in `O(1)` | `O(s)` assuming predicate computes in `O(1)` |
| IntAdjacencyMap | `O((n+m)*log(n))` assuming predicate computes in `O(1)` | ` ` |
| NonEmpty | `O(s)` assuming predicate computes in `O(1)` | `O(s)` assuming predicate computes in `O(1)` |
| Relation | `O((n+m)*log(n))` assuming predicate computes in `O(1)` | ` ` |


**`transpose`**: Transpose a given graph.

| transpose | Time | Memory |
|--------------------|-------------------|--------|
| AdjacencyMap | `O(m*log(n))` | `O(n+m)` |
| Fold | `O(s)` | `O(s)` |
| IntAdjacencyMap | `O(m*log(n))` | `O(n+m)` |
| NonEmpty | `O(s)` | `O(s)` |
| Relation | `O(m*log(m))` | ` ` |

**`induce`**: Constructs the induced subgraph of a given graph by removing the vertices that do not satisfy a given predicate. For `NonEmpty` graphs, it returns `Nothing` if the resulting graph is empty.

| induce | Time | Memory |
|--------------------|-------------------|--------|
| AdjacencyMap | `O(m)` assuming predicate computes in `O(1)` | ` ` |
| Fold | `O(s)` assuming predicate computes in `O(1)` | `O(s)` assuming predicate computes in `O(1)` |
| HigherKinded.Class | `O(s)` assuming predicate computes in `O(1)` | `O(s)` assuming predicate computes in `O(1)` |
| IntAdjacencyMap | `O(m)` assuming predicate computes in `O(1)` | ` ` |
| NonEmpty | `O(s)` assuming predicate computes in `O(1)` | `O(s)` assuming predicate computes in `O(1)` |
| Relation | `O(m)` assuming predicate computes in `O(1)` | ` ` |

**`splitVertex`**: Split a vertex into a list of vertices with the same connectivity. For `NonEmpty` graphs, it returns `Nothing` if the resulting graph is empty.

| splitVertex | Time | Memory |
|--------------------|-------------------|--------|
| Fold | `O(s+k*L)` where `k` is the number of occurrences of the vertex in the expression and `L` the length of the given list | ` ` |
| HigherKinded.Class | `O(s+k*L)` where `k` is the number of occurrences of the vertex in the expression and `L` the length of the given list | ` ` |
| NonEmpty | `O(s+k*L)` where `k` is the number of occurrences of the vertex in the expression and `L` the length of the given list | ` ` |

**`simplify`**: Simplifies a graph expression in a reasonable time.

| simplify | Time | Memory |
|--------------------|-------------------|--------|
| Fold | `O(s)` | `O(s)` |
| NonEmpty | `O(s)` | `O(s)` |