Skip to main content

What is a stack; linear or non-linear

Short answer

A stack is a linear LIFO data structure with insertion/deletion only at top. It is linear because elements form a sequence with at most one predecessor and successor.

What is a stack data structure? Is stack a linear or non linear data structure?

A stack is a linear data structure in which insertion (push) and deletion (pop) take place only at one end, called the top. The last element inserted is the first one removed, so it follows LIFO (Last In First Out).

Linear or non-linear?

A stack is a linear data structure. In a linear structure the elements form a sequence in which every element (except the first and last) has exactly one predecessor and one successor, and elements are accessed one after another in order. In a stack the items are arranged one above another in a line; the only difference from an array or list is that insertion and deletion are restricted to one end (the top).

   push ->  | 30 | <- top   -> pop
            | 20 |
            | 10 | <- bottom

Non-linear structures such as trees and graphs allow an element to be linked to more than one next element, which is not the case here.

LinearNon-linear
One-to-one sequence between elementsOne-to-many or many-to-many relation
Single level, traversed in one runMultiple levels, branching
Stack, queue, array, linked listTree, graph

A stack can be implemented using an array or a linked list, both of which are linear.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Structure and Algorithm chapter 2 questions →