Arrays and Linked Lists

Arrays store elements contiguously for O(1) indexed access but need shifting to insert, while linked lists store nodes with pointers for O(1) insertion at a known position but require O(n) traversal to locate an element.

Key formulas & points

Skim these first — then read the full notes below.

  • Arrays give O(1) random access but a fixed contiguous layout
  • Linked lists give O(1) head insertion but no random access
  • Circular lists simplify queue and round-robin implementations

Topic details

Introduction

This topic contrasts the two fundamental linear structures. You compute array element addresses, analyse the cost of insertion, deletion and access for each structure, and choose between contiguous storage (arrays) and pointer-linked storage (lists) based on the operation mix.

Key relations & formulas

Formulas (Indian textbook notation)

  • arrayelementaddress=base+index×elementsizearray element address = base + index \times element_{size}

Formulas (Indian textbook notation)

  • singlylinkedlist:O(1)insertathead,O(n)searchsingly linked list: O(1) insert at head, O(n) search

Formulas (Indian textbook notation)

  • doublylinkedlist:O(1)deletegivenanodepointerdoubly linked list: O(1) delete given a node pointer

Notation and sign conventions

Relation 1 —
arrayelementaddress=base+index×elementsizearray element address = base + index \times element_{size}

Formulas (Indian textbook notation)

  • arrayelementaddress=base+index×elementsizearray element address = base + index \times element_{size}
Write this relation with symbols exactly as in Schaum Ds — Standard reference before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 2 —
singlylinkedlist:Osingly linked list: O

Formulas (Indian textbook notation)

  • singlylinkedlist:O(1)insertathead,O(n)searchsingly linked list: O(1) insert at head, O(n) search
Write this relation with symbols exactly as in Schaum Ds — Standard reference before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 3 —
doublylinkedlist:Odoubly linked list: O

Formulas (Indian textbook notation)

  • doublylinkedlist:O(1)deletegivenanodepointerdoubly linked list: O(1) delete given a node pointer
Write this relation with symbols exactly as in Schaum Ds — Standard reference before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.

Concept in depth

The array-versus-list choice is a classic time/space trade-off. An array’s contiguous layout gives constant-time indexing by address arithmetic and excellent cache locality, but inserting in the middle means shifting elements and its size is fixed at allocation (dynamic arrays amortise resizing). A linked list scatters nodes across memory joined by pointers, so it grows freely and inserts or deletes in constant time once you hold the relevant node — but reaching that node costs a linear scan, and each node carries pointer overhead with poor cache behaviour. Doubly linked lists add a back-pointer for O(1) deletion and bidirectional traversal at extra memory cost.

Assumptions and validity limits

State assumptions explicitly before using any relation for arrays and linked lists — steady state, uniform properties, linear elastic material, ideal gas, incompressible flow, etc., as applicable.
Wrong assumptions invalidate the entire solution even when the formula is correct. In Data Structures viva and GATE descriptive questions, listing valid assumptions often earns separate marks.

Step-by-step problem approach

1. Read the question and list given data with SI units (common in Data Structures papers).
2. Draw a neat labelled diagram where applicable — examiners in Indian universities award diagram marks even when arithmetic slips.
3. Identify which relation from this topic applies to arrays and linked lists.
4. Use equation 1:
arrayelementaddress=base+index×elementsizearray element address = base + index \times element_{size}
.
5. Use equation 2:
singlylinkedlist:Osingly linked list: O
.
6. Substitute values, compute, and verify units and sign (direction).
7. State conclusion in one line — e.g. safe/unsafe, stable/unstable, feasible/infeasible.

Applications & exam relevance

Arrays and Linked Lists appears in interviews and systems programming. In Indian it software curricula this topic is tested because it connects theory to organising data for efficient algorithms.
GATE and semester exams often combine arrays and linked lists with earlier units — revise prerequisites before attempting mixed problems.
Industry interview panels sometimes ask: "Where did you use arrays and linked lists?" — answer with a lab, mini-project, or plant visit example if possible.

Common mistakes in exams

Students claim linked lists allow random access (they do not) and forget that array insertion in the middle is O(n) due to shifting. Off-by-one errors in address computation and losing the list when reassigning the head pointer are also common.

Quick revision checklist

Before attempting arrays and linked lists problems, confirm you can:
1. Arrays give O(1) random access but a fixed contiguous layout
2. Linked lists give O(1) head insertion but no random access
3. Circular lists simplify queue and round-robin implementations
Revise the solved examples in Schaum Ds — Standard reference and one previous-year GATE or university paper for this unit.

Worked examples

Try the problem first — open the solution when you are ready to check.

Array address computation

Problem

An int array (4 bytes/element) starts at address 2000. Find the address of A[18].

Solution

Address = base + i × size = 2000 + 18×4 = 2072. Always confirm the index origin (0-based) before substituting.

Conceptual check — Arrays and Linked Lists

Problem

In a Data Structures semester or GATE paper you are asked: "State the main assumption, the governing relation, and one practical consequence of arrays and linked lists." What should a complete answer include?

📖 Standard books (India)

  • Schaum DsStandard reference

    Read: Syllabus unit

    Referenced in Indian B.Tech syllabus