Questions tagged [data-structures]

A data structure is a way of organizing data in a fashion that allows particular properties of that data to be queried and/or updated efficiently.

Data structures are ubiquitous in software. Hash tables, balanced trees, and dynamic arrays are essential building blocks for large, complicated systems and almost all programmers have encountered them at some point. More complicated structures like binary heaps can speed up complicated systems, while simpler concepts like stacks and queues make it possible to more elegantly and concisely encode algorithms.

Of course, this is just the tip of the iceberg when it comes to data structures. Theoreticians have been developing progressively better and better data structures over the past years, many of which are used extensively in modern software, and many are only useful from a theoretical perspective.

Data structures are closely related to algorithms. Often, a good choice of data structure can lead to a marked improvement in an algorithm's runtime. For example, Dijkstra's algorithm with a naive implementation of a priority queue runs in quadratic time, but with a fast Fibonacci heap can be shown to run in O(m + n lg n).

Below is a (not at all comprehensive) list of some of the more popular data structures and their variants:

  • Dynamic arrays
    • Dynamic table
    • Tiered vector
    • Hashed array tree
    • Extendible array
  • Linked lists
    • Singly-linked lists
    • Doubly-linked lists
    • XOR-linked lists
    • Skip lists
  • Hash tables
    • Chained hash tables
    • Linear probing hash tables
    • Quadratic probing hash tables
    • Double hash tables
    • Cuckoo hash tables
    • Perfect hash tables
    • Dynamic perfect hash tables
  • Binary trees
    • Red/black trees
    • Interval trees
    • Binary search trees
    • Segment trees
    • AVL trees
    • AA trees
    • Splay trees
    • Scapegoat trees
    • Treap
  • Priority queues
    • Binary heap
    • Binomial heap
    • Fibonacci heap
    • van Emde Boas tree
    • Skew binomial heap
    • Brodal queue
  • Radix trees
    • Trie
    • Patricia tree
    • Ternary search tree
  • Multiway trees
    • B tree
    • B+ tree
    • B* tree
  • Geometric trees
    • Quadtree
    • Octree
    • kd-Tree
    • BSP-tree
    • R-tree
  • Geometric structures
    • Winged-edge
    • Quadedge
  • Network connectivity structures
    • Disjoint-set forest
    • Link/cut tree
    • Top tree
  • Graphs
    • DAG
    • Directed graph
    • Undirected graph
    • Hypergraph

Links:

33477 questions
10
votes
3 answers

Haskell data structure that is efficient for swapping elements?

I am looking for a Haskell data structure that stores an ordered list of elements and that is time-efficient at swapping pairs of elements at arbitrary locations within the list. It's not [a], obviously. It's not Vector because swapping creates new…
user1002430
10
votes
5 answers

Best data structure for nearest neighbour in 1 dimension

I have a list of values (1-dimensional) and I would like to know the best data structure / algorithm for finding the nearest to a query value I have. Most of the solutions (all?) I found for questions here are for 2 or more dimensions. Can anybody…
Muhammad Alkarouri
  • 23,884
  • 19
  • 66
  • 101
10
votes
2 answers

Print Specific nodes at a every level calculated by a given function

In an interview, i was given a function: f(n)= square(f(n-1)) - square(f(n-2)); for n>2 f(1) = 1; f(2) = 2; Here n is the level of an n-array tree. f(n)=1,2,3,5,16... For every level n of a given N-Array I have to print the f(n) node at every…
poorvank
  • 7,524
  • 19
  • 60
  • 102
10
votes
1 answer

Why is there no peek! function for clojure transient vectors?

Clojure has transient analogs for some of its persistent data structures, vectors, maps and sets. For vectors, there are pop! and conj! functions, analogous to pop and conj for persistent vectors, but no peek!. Is there a technical reason that…
Rob Lachlan
  • 14,289
  • 5
  • 49
  • 99
10
votes
0 answers

More cache friendly linked list or alternative with optimal append, delete, and ordered traversal for limit order book?

I am trying to implement a stock matching engine/order book in C++, and am searching for a more cache friendly architecture. Currently, my data structures are as follows: An intrusive rb-tree for the limit prices. An intrusive doubly linked list…
Ronny Rildil
  • 101
  • 6
10
votes
4 answers

a collection data structure to keep items sorted

I got a program which is using an ArrayList and that type T also implements Comparable. I need to keep that list sorted. For now, when I insert a new item, I add it to the ArrayList and then invoke Collections.sort(myArrayList). Is sorting…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
10
votes
3 answers

Map of Maps data structure

The MultiValueMap class (Apache commons collections) makes it easy to work with a Map whose values are Collections. I'm looking for a a class that makes it easy to work with a Map whose keys are objects and values are Maps. I'm using Java 1.4, so…
Dónal
  • 185,044
  • 174
  • 569
  • 824
10
votes
3 answers

Optimal algorithm to return largest k elements from an array of infinite number of elements in running stream

I have a running stream of integers, how can I take largest k elements from this stream at any point of time.
Ajay Gaur
  • 5,140
  • 6
  • 38
  • 60
10
votes
8 answers

java: sparse bit vector

Are there any well-known libraries in Java for sparse bit vectors? (And are there guidelines for how sparse is useful to use them vs. java.util.BitSet?)
Jason S
  • 184,598
  • 164
  • 608
  • 970
10
votes
2 answers

How to fit a custom graph to the boost graph library template?

I'm rusty on C++ templates and I'm using the boost graph library (a fatal combination). I've searched the web and can't find any direct instructions on how to take a custom graph structure and fit enough of it to BGL (boost graph library) that I can…
Michael
  • 313
  • 2
  • 8
10
votes
4 answers

Deep changing values in a JavaScript object

I have an object which contains an unknown number of other objects. Each (sub-)object may contain boolean values as strings and I want to change them to real boolean values. Here's an example object: var myObj = { my1stLevelKey1: "true", …
10
votes
4 answers

Data structure for pixel based pattern recognition

I have an application that constructs random images based on constraints. Different colored pixels are randomly selected and placed in a grid that satisfy all constraints. For example (simplifying), there might be a constraint that says if a blue or…
jasonm76
  • 500
  • 2
  • 13
10
votes
5 answers

parsing of mathematical expressions

(in c90) (linux) input: sqrt(2 - sin(3*A/B)^2.5) + 0.5*(C*~(D) + 3.11 +B) a b /*there are values for a,b,c,d */ c d input: cos(2 - asin(3*A/B)^2.5) +cos(0.5*(C*~(D)) + 3.11 +B) a b /*there are values for a,b,c,d */ c d input: sqrt(2 -…
user319824
10
votes
6 answers

Given n tuples representing pairs, return a list with connected tuples

Given n tuples, write a function that will return a list with connected values. Example: pairs = [(1,62), (1,192), (1,168), (64,449), (263,449), (192,289), (128,263), (128,345), (3,10), (10,11) …
Arian Pasquali
  • 432
  • 2
  • 6
  • 17
10
votes
1 answer

Rope data structure explanation?

I was reading about the rope data structure on wikipedia and I was a little confused about the description. Wiki link: http://en.wikipedia.org/wiki/Rope_(data_structure) Description A rope is a binary tree having leaf nodes that contain a short…
Kevvvvyp
  • 1,704
  • 2
  • 18
  • 38
1 2 3
99
100