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
5 answers

What is the difference between linkedlist and queue?

I'm new to data structures and it seems like both data structures have more similarities. In this answer it says that there is a difference in interface. Please explain it.
dilusha_dasanayaka
  • 1,401
  • 2
  • 17
  • 30
10
votes
2 answers

What makes Everything's file search and index so efficient?

Everything is a file searching program. As its author hasn't released the source code, I am wondering how it works. How could it index files so efficiently? What data structures does it use for file searching? How can its file searching be so…
Sraw
  • 18,892
  • 11
  • 54
  • 87
10
votes
0 answers

What is the R*-Tree algorithm?

Where can I find enough documentation to implement an R*-Tree? Specifically, I need to be able to: Insert nodes Remove nodes Search for K nearest neighbours Find all nearest neighbours within distance x. Is there a single place where this…
fmark
  • 57,259
  • 27
  • 100
  • 107
10
votes
1 answer

how to make sortable datatype in Python?

I have a class representing something with a few fields. When a list of instances of this class is sorted, I want them to be sorted in a particular order (get a particular key from each one). I can just do list.sort(key=Classname.sortKey) and define…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
10
votes
3 answers

What's the equivalent to a .NET SortedDictionary, in Java?

If .NET has a SortedDictionary object ... what is this in Java, please? I also need to be able to retrieve an Enumeration (of elements), in the Java code .. so I can just iterate over all the keys. I'm thinking it's a TreeMap ? But I don't think…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
10
votes
2 answers

Does julia have hashmaps like structures?

I am new to julia!I have just switched from java to julia, Can somebody tell me does julia have hashmap like structures? if No, then how do I map one type to another type in julia?
black sheep 369
  • 564
  • 8
  • 19
10
votes
11 answers

Are there O(1) random access data structures that don't rely on contiguous storage?

The classic O(1) random access data structure is the array. But an array relies on the programming language being used supporting guaranteed continuous memory allocation (since the array relies on being able to take a simple offset of the base to…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
10
votes
3 answers

Does R have a Set data structure?

I have a large vector variable holding exactly 5000 elements, and would like to know what these are, knowing that there are several repetitions. An introduction to R doesn't seem to say anything besides basic data structures, and I don't know if R…
Acsor
  • 1,011
  • 2
  • 13
  • 26
10
votes
3 answers

Finding mean and median in constant time

This is a common interview question. You have a stream of numbers coming in (let's say more than a million). The numbers are between [0-999]). Implement a class which supports three methods in O(1) * insert(int i); * getMean(); * getMedian();…
Melissa Stewart
  • 3,483
  • 11
  • 49
  • 88
10
votes
3 answers

Python OO program structure planning

I'm a beginner in OOP and I want to create a program with three classes, A, B, and C. Each instance of the class is defined by a set of characteristics, Achar1, Achar2 etc. The program is supposed to create uses comprising of element of A, element…
098799
  • 462
  • 1
  • 4
  • 17
10
votes
3 answers

Why does sapply return a matrix that I need to transpose, and then the transposed matrix will not attach to a dataframe?

I would appreciate insight into why this happens and how I might do this more eloquently. When I use sapply, I would like it to return a 3x2 matrix, but it returns a 2x3 matrix. Why is this? And why is it difficult to attach this to another data…
David LeBauer
  • 31,011
  • 31
  • 115
  • 189
10
votes
1 answer

A*, what's the best data structure for the open list?

Disclaimer: I really believe that this is not a duplicate of similar questions. I've read those, and they (mostly) recommend using a heap or a priority queue. My question is more of the "I don't understand how those would work in this case" kind. In…
Shivan Dragon
  • 15,004
  • 9
  • 62
  • 103
10
votes
6 answers

Interview Question: Data structure for a large social network

Another interesting interview question that I stumbled upon - Design the data structures for a very large social network (Facebook, LinkedIn, etc)? Also, design an algorithm to show the connection, or path, between two people (e.g.…
user450090
  • 181
  • 1
  • 2
  • 7
10
votes
3 answers

Aggregation of array data over a given dimension

Forgive the n00b-ish question but I am new to data structures. I had been recently asked to aggregate a given array over another array and produce a tree based result. Can someone give me some pointers on how to attain this output? INPUT var T =…
noob_here
  • 103
  • 5
10
votes
4 answers

HashMap Java get value if it exists

I wish to get a value from a HasMap but some time the value doesn't exist so I have done this: int var = 0; if (hashMapHouse.containsKey("home1") { var = hashMapHouse.get("houme1"); } if(var==0) //do something else //do something else My…
snorlax
  • 157
  • 2
  • 3
  • 10