This simulator holds five fixed values in whichever structure you choose and performs one operation at a time, so the arrangement and the cost of each operation are visible. You change the structure and the search key, then step through the trace.
• A 3D scene with stored elements, the access relationships between them, an operation cursor and a result station. • A Structure selector (array, linked list, stack, queue, binary search tree) and a Search key / array index control from 0 to 9. • Readouts for elements currently stored, key comparisons, modeled operations, the read value or found index (−1 when absent), and visited search nodes. • Restart demonstration and Advance event buttons, and three experiments.
An array read by index is O(1). A linked-list search follows nodes one by one and is O(n); searching for an absent key visits all five nodes and returns −1. A stack pushes and pops at one end (LIFO) and a queue enqueues at one end and dequeues at the other (FIFO), each O(1) with a suitable representation — the experiment inserts 4, 7, 2, 9, 5 and shows a stack returning 5 while a queue returns 4. A binary search tree search is O(h), the height, and is not always O(log n): the fixed tree search for 5 visits 7, then 4, then 5 for three comparisons.
Five fixed values keep each operation inspectable. In array mode the control selects an index modulo 5; list and tree modes search by key; stack and queue modes insert and then remove one item. The tree is ordered but is not a balancing algorithm, and timing is event playback (0.8 animation seconds), not benchmark performance.
No. A skewed tree can have linear height, which is why search is O(h) rather than always O(log n).
A stack, which uses last-in first-out order. A queue removes the oldest item first.
The search must visit every node before it can conclude the key is missing. In the lab that means five visited nodes and a result of −1.
It wraps the control value onto the five array positions, so values 0 to 9 select indices 0 to 4 twice and every read is a direct O(1) access.