The primitive operations of a data structure are the basic actions every structure must support: creating it, inserting an element, deleting an element, traversing its elements, searching for a value, and updating an existing value. Each structure implements them differently, and that difference decides the time cost of your program.
The phrase is also used in algorithm analysis, where a "primitive operation" means one basic step such as an assignment, a comparison or an arithmetic operation. This article covers the data structure meaning and shows the examples in modern JavaScript.
Almost every textbook lists the same core operations. Some structures restrict them (a stack only inserts and deletes at one end), but the vocabulary stays the same.
| Operation | What it does | Typical JavaScript form |
|---|---|---|
| Creation | Allocates an empty or pre-filled structure | [], new Map(), new Set() |
| Insertion | Adds an element | push, splice, map.set |
| Deletion | Removes an element | pop, splice, map.delete |
| Traversal | Visits every element once | for...of, forEach |
| Search | Finds an element or its position | includes, indexOf, map.get |
| Update | Replaces the value of an existing element | arr[i] = x, map.set |
Many books add sorting, merging and copying as derived operations. They are built from the six above, which is why the six are called primitive.
Creation allocates the structure. In JavaScript you rarely manage memory yourself, so creation is a literal or a constructor call.
Where you insert matters. Appending to the end of an array is amortised constant time. Inserting at the start or in the middle forces the engine to shift the elements after it, which is linear time. A linked list inserts in constant time when you already hold a reference to the node, but finding that node costs a traversal.
Deletion removes an element and, for arrays, closes the gap.
Avoid the delete operator on array elements. It leaves a hole (a sparse array) instead of shifting the elements, and the length does not change. Use splice, filter or toSpliced (ES2023, returns a new array) instead.
Traversal visits each element exactly once, so it is always linear in the number of elements.
Use for...of for arrays, sets and maps. Avoid for...in on arrays because it iterates property names (as strings) and can include inherited properties.
Search finds an element. The cost depends on the structure: an unsorted array needs a linear scan, a sorted array supports binary search in logarithmic time, and a hash-based structure (Map, Set) finds a key in average constant time.
Update replaces the value of an element that already exists. For an array with a known index it is constant time, because the position is computed directly.
The same operation costs different amounts in different structures. This table uses typical worst-case or average costs, where n is the number of elements.
| Structure | Insert | Delete | Search | Update |
|---|---|---|---|---|
| Array (by index) | O(n) middle, O(1) end | O(n) middle, O(1) end | O(n) | O(1) |
| Singly linked list | O(1) at head | O(1) at head, O(n) by value | O(n) | O(n) |
| Hash map or set | O(1) average | O(1) average | O(1) average | O(1) average |
| Balanced search tree | O(log n) | O(log n) | O(log n) | O(log n) |
Choosing a data structure is mostly choosing which of these operations must be cheap for your workload.
Primitive data types (number, string, boolean and so on) are the basic kinds of values. Primitive operations are the basic actions you perform on a data structure. They are unrelated concepts that happen to share a word.
Yes, in most textbooks. Printing, summing and copying are all traversals, and search is a traversal that can stop early.
It depends on the structure. In an array, inserting or deleting near the front is the costly one because every later element shifts. In a linked list it is search.
It is one basic step, such as a comparison or an assignment, that is assumed to take constant time. Counting these steps gives the running time of an algorithm.
The primitive operations of a data structure are creation, insertion, deletion, traversal, search and update. Every other behaviour is built from them. Their cost depends on how the structure stores its data, so learn the complexity of each operation for arrays, linked lists, hash maps and trees, and pick the structure that makes your most frequent operations cheap.