Data Structures & Algorithms · Interview question

How do you use linked lists on a system with no heap?

A strong answer

Pre-allocate a fixed array of nodes at compile time and manage them with a free list, itself a linked list threading the unused nodes. At init you link every node from the static pool into the free list; "allocating" a node pops the head of the free list (O(1)), and "freeing" pushes it back (O(1)). This gives constant-time alloc/free with zero fragmentation and a hard, known memory bound (exactly POOL_SIZE nodes, exhaustion returns NULL, which you handle), replacing malloc/free with something deterministic and bounded, which is what real-time and safety-critical code needs. The common refinement is an intrusive list: rather than a node owning the data, embed the next pointer inside the data object itself (a Task or Timer carries its own link), so there's no separate node allocation at all, the object is the node. That's the pattern Linux and most RTOSes use.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Linked Lists

Nodes chained by pointers: O(1) splice anywhere, O(n) search and no random access, and how embedded does them without a heap via static node pools and intrusive lists.

More Linked Lists questions

Browse all 472 interview questions
How do you use linked lists on a system with no heap? | EmbeddedPrep.io