background preloader

Data structures

Facebook Twitter

Help Center – Algorithm Tutorials. Fibonacci heap. Find-minimum is O(1) amortized time.[1] Operations insert, decrease key, and merge (union) work in constant amortized time.[2] Operations delete and delete minimum work in O(log n) amortized time.[2] This means that starting from an empty data structure, any sequence of a operations from the first group and b operations from the second group would take O(a + b log n) time.

Fibonacci heap

In a binomial heap such a sequence of operations would take O((a + b) log (n)) time. A Fibonacci heap is thus better than a binomial heap when b is asymptotically smaller than a. Using Fibonacci heaps for priority queues improves the asymptotic running time of important algorithms, such as Dijkstra's algorithm for computing the shortest path between two nodes in a graph.

Graph theory

Set 1 (Introduction) Splay tree. A splay tree is a self-adjusting binary search tree with the additional property that recently accessed elements are quick to access again.

Splay tree

It performs basic operations such as insertion, look-up and removal in O(log n) amortized time. For many sequences of non-random operations, splay trees perform better than other search trees, even when the specific pattern of the sequence is unknown. The splay tree was invented by Daniel Dominic Sleator and Robert Endre Tarjan in 1985.[1] All normal operations on a binary search tree are combined with one basic operation, called splaying.

Rope (data structure) A simple rope built on the string of "Hello_my_name_is_Simon".

Rope (data structure)

A rope is a binary tree having leaf nodes that contain a short string. Each node has a "weight" equal to the length of its string plus the sum of all the weights in its left subtree. Thus a node with two children divides the whole string into two parts: the left subtree stores the first part of the string. The right subtree stores the second part and its weight is the sum of the left child's weight and the length of its contained string. The binary tree can be seen as several levels of nodes. In the following definitions, N is the length of the rope. Figure 2.1: Example of index lookup on a rope. Definition: Index(i): return the character at position i Time complexity: O(log N) To retrieve the i-th character, we begin a recursive search from the root node: Figure 2.2: Concatenating two child ropes into a single rope. Definition: Concat(S1, S2): concatenate two ropes, S1 and S2, into a single rope.

Trie. A trie for keys "A","to", "tea", "ted", "ten", "i", "in", and "inn".

Trie

Note that this example does not have all the children alphabetically sorted from left to right as it should be (the root and node 't'). In the example shown, keys are listed in the nodes and values below them. Each complete English word has an arbitrary integer value associated with it. A trie can be seen as a tree-shaped deterministic finite automaton. Each finite language is generated by a trie automaton, and each trie can be compressed into a deterministic acyclic finite state automaton. Though tries are usually keyed by character strings,[not verified in body] they need not be. History and etymology[edit] Applications[edit] As a replacement for other data structures[edit] As discussed below, a trie has a number of advantages over binary search trees.[6] A trie can also be used to replace a hash table, over which it has the following advantages: Tries do have some drawbacks as well: Dictionary representation[edit]

SPQR tree. A graph and its SPQR tree.

SPQR tree

The dashed black lines connect pairs of virtual edges, shown as black; the remaining edges are colored according to the triconnected component they belong to. In graph theory, a branch of mathematics, the triconnected components of a biconnected graph are a system of smaller graphs that describe all of the 2-vertex cuts in the graph. An SPQR tree is a tree data structure used in computer science, and more specifically graph algorithms, to represent the triconnected components of a graph. The SPQR tree of a graph may be constructed in linear time[1] and has several applications in dynamic graph algorithms and graph drawing.

Structure[edit] In an S node, the associated graph is a cycle graph with three or more vertices and edges. Each edge xy between two nodes of the SPQR tree is associated with two directed virtual edges, one of which is an edge in Gx and the other of which is an edge in Gy. Suffix tree. Suffix tree for the text BANANA.

Suffix tree

Each substring is terminated with special character $. The six paths from the root to a leaf (shown as boxes) correspond to the six suffixes A$, NA$, ANA$, NANA$, ANANA$ and BANANA$. The numbers in the leaves give the start position of the corresponding suffix. Suffix links, drawn dashed, are used during construction.