Types of Data Structures Explained, With Measured Costs and Examples

Linear, non-linear and hashed data structures classified, with the cost of each operation from the Python and Java docs, timings measured at up to a million elements, tree-height and hash-table worked examples, the GATE 2027 scope and India pay data.

Types of Data Structures Explained, With Measured Costs and Examples

Data structures come in three families. Linear structures keep one sequence: arrays, linked lists, stacks and queues. Non-linear structures keep a hierarchy or a network: trees, heaps, tries and graphs. Hashed structures compute where a key lives: hash tables and hash sets. Each type exists because it makes one operation cheap at the cost of another, and the right choice is decided by which operation your program repeats most.

This guide classifies every common data structure, states the cost of its defining operations from the Python 3.15 and Java SE 25 documentation, and backs the theory with measurements: a Skill-Lync script timed the same membership and insertion operations on lists, sets and deques from 1,000 to 1,000,000 elements on 29 November 2026. It also shows how a search tree can be 19 levels deep or a million, lists exactly which structures GATE 2027 examines, and ends with what the roles that test this knowledge pay in India.

Key takeaways

  • Three families: linear (array, linked list, stack, queue), non-linear (tree, heap, trie, graph) and hashed (hash table, hash set). Primitive types (int, float, char, bool) are the building blocks, not structures in their own right.
  • The cost that defines each: an array indexes in O(1) but inserts in the middle in O(n); a linked list is the reverse; a hash table finds a key in O(1) on average; a balanced tree does everything in O(log n) and keeps order (Python docs 3.15.2; Java SE 25 docs).
  • Measured, not assumed: at one million elements, membership in a Python list took 7.4 ms against 0.57 µs in a set, a 13,000× gap; inserting at the front of a list took 2.4 ms against 1.4 µs for a deque (CPython 3.14.5, 29 Nov 2026).
  • Trees depend on balance: 100,000 random keys built a binary search tree 39 levels deep; the same keys inserted in sorted order give a 100,000-level chain. Balanced trees guarantee 19 levels for a million keys.
  • Exam scope: GATE 2027 CS (IIT Madras) lists "Arrays, stacks, queues, linked lists, trees, binary search trees, binary heaps, graphs" under Programming and Data Structures, and "Searching, sorting, hashing" under Algorithms.

What is a data structure?

A data structure is a way of arranging data in memory so that a chosen set of operations (insert, delete, search, index, find the minimum) runs fast. The arrangement and the operations go together: an array stores items side by side so that the th item's address is one multiplication away, and that same layout is why inserting in the middle means shifting everything after it. Choosing a data structure is choosing which operations you want cheap.

The cost of an operation is written in big-O notation, which counts how the work grows with the number of items . O(1) means constant, O(log n) means it grows by one step each time doubles, O(n) means it grows in proportion to . Those three classes separate the structures below more sharply than any language or library does, as the measurements in this article show.

Classification tree: data structures split into primitive (int, float, char, bool) and non-primitive; non-primitive splits into linear (array, linked list, stack, queue), non-linear (binary search tree, heap, trie, graph) and hashed (hash table, hash set), each box giving its defining operation cost
How data structures are classified, with the defining cost of each. Drawn by Skill-Lync; costs from the Python and Java documentation cited at the end.

What are the types of data structures?

Textbooks first split data into primitive types and non-primitive structures, then split the structures by how their elements connect.

FamilyMembersDefining propertyWhat is cheapWhat is expensive
Primitiveint, float, char, boolFixed size, stored directlyEverything is O(1)Cannot grow or hold a collection
LinearArray, dynamic array, linked list, stack, queue, dequeOne sequence with one next elementIndex (array), insert at a known node (list), ends (stack, queue)Search by value: O(n) for all of them
Non-linearBinary search tree, balanced trees, heap, trie, graphHierarchy or network of linksOrdered search O(log n) (balanced tree), min/max O(1) (heap), prefix lookup (trie)Keeping balance; graphs need O(V + E) traversals
HashedHash table (map, dict), hash setPosition computed from the keyLookup, insert, delete: O(1) averageNo ordering; O(n) worst case when hashes collide

What are linear data structures?

Array and dynamic array

An array stores elements of one type in consecutive memory, so element sits at . For 8-byte items at base address 0x1000, item 1,250 is at 0x1000 + 1,250 × 8 = 0x3710, found with one multiply and one add however large the array is. A dynamic array (Python's list, Java's ArrayList, C++'s vector) grows by reallocating a larger block when full. The Python documentation lists append as O(1) amortized ("an individual operation may occasionally be O(n) when the underlying storage is resized, but this cost is spread over many operations"), get and set item as O(1), and insert, delete and pop at position as O(n − k). Java's ArrayList documentation says the same: "The size, isEmpty, get, set ... operations run in constant time. The add ... operations runs in amortized constant time."

Linked list

A linked list stores each element in its own node with a pointer to the next (and, in a doubly linked list, the previous) node. Inserting or deleting at a node you already hold is O(1), because only two pointers change; reaching the th node is O(k) because there is no address arithmetic. Python's collections.deque is the standard-library structure with this property at both ends: the docs state it supports "appends and pops from either side of the deque with approximately the same O(1) performance in either direction", whereas lists "incur O(n) memory movement costs for pop(0) and insert(0, v)". The measurements below make that sentence concrete.

Stack

A stack allows insertion and removal only at one end: last in, first out. Push and pop are O(1). The call stack of every running program is one; so is the undo history of an editor and the bracket checker in a compiler. A seven-line checker that pushes opening brackets and pops on closing ones returns true for {[()]} and false for ([)], which is the classic interview warm-up.

Queue and deque

A queue inserts at the back and removes from the front: first in, first out, both O(1) when built on a linked list or a circular array. Schedulers, print spoolers and message brokers are queues. Breadth-first search on a graph is a queue in action: starting from A in a six-node graph, it visits nodes in increasing distance and reports that F is three edges away. A deque (double-ended queue) allows both operations at both ends and covers stacks and queues alike.

Worked example: the same operation on four structures, measured

The table below is what the big-O rows mean in practice. A Skill-Lync script timed, on CPython 3.14.5 on an Apple-silicon laptop on 29 November 2026, a worst-case membership test (the target is the last element), insertion at the front, and binary search on a sorted list, at four sizes. Absolute times depend on the machine; the trend down each column does not.

nx in list (O(n))list.insert(0, x) (O(n))bisect on sorted list (O(log n))x in set (O(1))deque.appendleft (O(1))
1,0007.5 µs0.33 µs0.10 µs0.034 µs0.047 µs
10,00075 µs3.4 µs0.19 µs0.050 µs0.057 µs
100,000767 µs45 µs0.23 µs0.10 µs0.17 µs
1,000,0007,421 µs2,424 µs1.5 µs0.57 µs1.4 µs

Each tenfold increase in multiplies the two O(n) columns by about ten, while the other three barely move until cache effects appear at a million elements. At one million, a list membership test is about 13,000 times slower than a set lookup, and binary search is about 5,000 times faster than the linear scan. Insert at the front of a list is slower than appending at the end by a factor of about 200 at 100,000 elements. None of this is a Python quirk; the same shape appears in Java, C++ or Go because it comes from the memory layout.

Log-log chart of time per operation against n from 1,000 to 1,000,000: list membership and insert at index 0 rise tenfold per decade to 7.4 ms and 2.4 ms, while bisect, set membership and deque appendleft stay between 0.03 and 1.5 microseconds
Measured time per operation, CPython 3.14.5, 29 Nov 2026. The O(n) lines climb; the O(log n) and O(1) lines stay flat. Script in the run folder.

What are non-linear data structures?

Binary search tree and balanced trees

A binary search tree (BST) keeps every key larger than its left subtree and smaller than its right, so a search walks one path from the root and each step halves what is left, if the tree is balanced. The cost of every search, insert and delete equals the tree's height. A balanced tree with a million keys is only levels deep. A plain BST has no guarantee: the Skill-Lync script inserted 100,000 random keys and measured a height of 39, then inserted 5,000 sorted keys and measured a height of 5,000, one node per level, which is a linked list wearing a tree's name. Self-balancing trees (AVL, red-black, B-trees) rebalance on every insert to keep the logarithmic height; Java's TreeMap is "a Red-Black tree based NavigableMap implementation" that "provides guaranteed log(n) time cost for the containsKey, get, put and remove operations". Database indexes are B-trees for the same reason.

Log-log chart of binary search tree height against number of keys: sorted-insert BST height equals n minus 1, reaching a million; random insertion measured 39 at 100,000 keys; balanced trees reach 19 levels at one million keys
The height of a binary search tree decides its cost. Measured points from the run folder script; the balanced line is the guaranteed bound.

Heap

A heap is a complete binary tree stored in an array in which every parent is smaller (min-heap) or larger (max-heap) than its children. The minimum is always at index 0, so reading it is O(1); inserting or removing it is O(log n) because the element sifts up or down one level at a time. Python's heapq module describes itself as "an implementation of the heap queue algorithm, also known as the priority queue algorithm". Taking the top 10 of a million random numbers with heapq.nlargest took 11 ms in the Skill-Lync measurement against 164 ms for a full sort, because the heap never orders the other 999,990 values.

Trie

A trie (prefix tree) stores strings one character per level, so all words sharing a prefix share a path. Lookup costs O(length of the key) regardless of how many keys are stored, which is why autocomplete, spell-checkers and IP routing tables use it.

Graph

A graph is a set of vertices connected by edges, directed or undirected, weighted or not, stored as an adjacency list (one list of neighbours per vertex) or an adjacency matrix. Road networks, social networks, dependency graphs and circuit netlists are graphs. Breadth-first and depth-first traversals cost O(V + E); shortest paths and minimum spanning trees are the standard algorithms built on them. Our post on graph data structures and algorithms in Python implements each one.

What are hashed data structures?

A hash table stores key-value pairs in an array whose index is computed from the key by a hash function. Lookup, insertion and deletion are O(1) on average. The Python docs are precise about the condition: the times "are average-case times, as they assume the hash function for the objects is sufficiently robust to make collisions uncommon", and "in the worst case, when every key hashes to the same value, each of the O(1) operations below instead takes O(n) time". Java's HashMap "provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets", starts with 16 buckets and resizes when the load factor (entries per bucket) passes 0.75, so the 13th entry triggers the first doubling to 32 buckets.

The load factor sets the expected work. With separate chaining and uniform hashing, an unsuccessful search examines about entries and a successful one about : at , 1.75 and 1.38 comparisons. That flat line is the whole reason a dictionary of a million items answers in half a microsecond while a list scans 7 ms. The price is order: a hash table cannot tell you the smallest key or the keys between two values. For that you go back to a balanced tree.

Log-log chart of worst-case comparisons to find one key from 10 to one billion elements: linear search rises to a billion, binary search reaches 10, 20 and 30 at a thousand, a million and a billion, hash lookup stays flat near 1.75
Comparisons to find one key. Sorting or hashing the data changes the cost from a billion to 30 or about two.

Which data structure should you use?

You need to…UseWhy
Access items by position, iterate in orderArray / dynamic arrayO(1) index, cache-friendly layout
Add and remove at both ends constantlyDeque (or a linked list)O(1) at both ends; list.insert(0) is O(n)
Undo, backtrack, match brackets, evaluate expressionsStackLast in, first out is the natural order
Process tasks in arrival order, breadth-first searchQueueFirst in, first out
Test membership or look up by key, no ordering neededHash set / hash tableO(1) average, measured 0.57 µs at one million items
Keep keys sorted, range queries, predecessor and successorBalanced tree (TreeMap, B-tree)O(log n) with guaranteed height
Repeatedly take the smallest or largest, top-k of a streamHeapO(1) peek, O(log n) push and pop
Autocomplete, prefix matchingTrieCost depends on key length, not count
Model connections: routes, networks, dependenciesGraphThe only structure that represents arbitrary links

Which data structures does GATE test?

The GATE 2027 Computer Science and Information Technology syllabus, issued by IIT Madras as organising institute, puts data structures in Section 4, Programming and Data Structures: "Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary search trees, binary heaps, graphs." Section 5, Algorithms, adds "Searching, sorting, hashing. Asymptotic worst case time and space complexity. Algorithm design techniques: greedy, dynamic programming and divide-and-conquer. Graph traversals, minimum spanning trees, shortest paths." Every structure in this article except the trie is named, and the measured-cost table above is exactly the "asymptotic worst case" reasoning the questions test. For interview preparation, our data structure interview questions post works through the questions companies actually ask.

Where do the limits of this classification lie?

Big-O hides constants, and constants decide real programs. A dynamic array beats a linked list for almost every sequential workload because its elements sit next to each other in cache, which is why Java's documentation notes that ArrayList's "constant factor is low compared to that for the LinkedList implementation". The measurements above show the other side: at one million elements the O(1) set lookup rose from 0.03 µs to 0.57 µs, a cache effect that big-O does not model. Hash tables are O(1) only with a good hash function and a sane load factor; adversarial keys turn them into O(n). Trees are O(log n) only if balanced. The classification tells you which structure can be fast; measuring tells you whether it is.

What do jobs that test data structures pay in India?

Data structures are the core of software hiring tests, and the roles span a wide pay range. AmbitionBox lists a typical software developer salary of ₹9.5 to 10.5 lakh a year for 1 to 5 years' experience (4.2 lakh salaries, updated 27 Nov 2026), with ₹7 to 7.8 lakh at 1 to 3 years, and a typical software development engineer salary of ₹13.5 to 15 lakh for 0 to 6 years (31.2k salaries, updated 28 Nov 2026), with ₹11.6 to 12.9 lakh at 1 to 3 years. Those are self-reported by people in the roles.

Starting offers for learners entering from a non-CS background sit lower. Based on 3,711 Skill-Lync placement records up to 7 Nov 2026 (data snapshot of 15 Nov 2026), learners placed in the software domain (n = 54) had a median starting package of ₹3.8 lakh, a middle half of ₹3.3 to 4.53 lakh and a top-10% line of ₹7.0 lakh, with TCS (5 placements), Ashok Leyland and Infosys (3 each) the most frequent hirers. The group is small and most records are 2021-23 offers from a self-selected learner sample, so treat it as a floor. This is a starting point; we will update it as new placements come in.

How should you learn data structures?

Implement each structure once by hand in one language, then measure it the way this article did: time the operation you expect to be cheap and the one you expect to be expensive, and check that the slope matches the big-O. Skill-Lync's Data Structures and Algorithms using Python (12 weeks) and Data Structures and Algorithms using Java (12 weeks) follow that implement-then-apply pattern, with Core and Advanced Python Programming as the entry point for engineers from other branches. If you want help choosing a language or a path, talk to a Skill-Lync counsellor.

Frequently asked questions

What are the 4 main types of data structures?

Most syllabuses name four: linear structures (arrays, linked lists, stacks, queues), non-linear structures (trees and graphs), hashed structures (hash tables and sets), and the primitive types they are built from (int, float, char, bool). Heaps and tries are special trees; a deque is a generalised queue.

What is the difference between linear and non-linear data structures?

In a linear structure every element has at most one next element, so the data forms a single sequence: arrays, linked lists, stacks, queues. In a non-linear structure an element can connect to several others, forming a hierarchy (trees, heaps, tries) or a network (graphs). Linear structures are traversed in one pass; non-linear ones need a traversal order such as BFS or DFS.

Which data structure is fastest for searching?

A hash table, when you search by exact key and do not need order: O(1) on average, measured at 0.57 µs for a million-item Python set. A balanced binary search tree or sorted array with binary search is next at O(log n), 20 comparisons for a million items, and it also supports range queries. An unsorted array or linked list is slowest at O(n).

Is a hash table always O(1)?

No. The Python documentation states that dictionary times are average-case and that "in the worst case, when every key hashes to the same value, each of the O(1) operations below instead takes O(n) time". Keeping the load factor low (Java's default limit is 0.75) and using a good hash function keeps the average near 1.75 comparisons per unsuccessful search.

Which data structures are in the GATE CSE syllabus?

GATE 2027 CS (IIT Madras) lists arrays, stacks, queues, linked lists, trees, binary search trees, binary heaps and graphs under Programming and Data Structures, plus searching, sorting, hashing, asymptotic complexity, graph traversals, minimum spanning trees and shortest paths under Algorithms. Tries are not named.

Should I learn data structures in Python or Java?

Either; the costs come from memory layout, not the language. Python is faster to write and its list, dict, set, deque and heapq cover every structure here. Java forces you to see types and interfaces (ArrayList, LinkedList, HashMap, TreeMap, PriorityQueue) and is what many Indian service companies test in. Skill-Lync teaches both; pick the one your target employers use.

Sources and further reading

Want this on your résumé?

Talk to a counsellor.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.