logo
Data Structures

01. Linear List

A1A2A3A4A5
顺序表:元素地址连续,支持随机访问

The linear list is one of the most fundamental and commonly used structures in data structures. Understanding it will help you learn stacks, queues, strings, and more.

1. Basic Concepts

  • Linear List: A finite sequence of n data elements of the same data type
  • Features: Has a unique first and last element; except for the first and last, each element has exactly one predecessor and one successor

2. Storage Structure Comparison

Storage TypeContiguous AddressSupports Random AccessInsert/Delete EfficiencySpace Utilization
Array ListYesYesLowLow
Linked ListNoNoHighHigh
  • Array List: Uses a group of contiguous memory units to store linear list elements in order
  • Linked List: Each node contains a data field and a pointer field, connected by pointers

3. Animation Demo

A1A2A3A4A5
顺序表:元素地址连续,支持随机访问

4. Common Pitfalls

When inserting/deleting in an array list, you need to move all subsequent elements; in a linked list, you only need to modify pointers. Don’t get confused!

5. Typical Applications of Linear Lists

  • As the basis for stacks, queues, strings, and other data structures
  • Task queues, browsing history, shopping carts, undo/redo in text editors, etc.
Application ScenarioRecommended Structure
Frequent random accessArray List
Frequent insertions/deletionsLinked List

Exercises

  1. Briefly describe the definition and main features of a linear list.
  2. What are the advantages and disadvantages of array lists and linked lists?
  3. What is the basic idea of insertion and deletion operations in a singly linked list?
  4. How to traverse a linear list?
  5. What are some typical applications of linear lists?
Reference Answers

1. Definition & Features

A linear list is an ordered sequence of n data elements, with a unique first and last element, and one-to-one relationships between elements.


2. Pros & Cons of Array List and Linked List

Array List: Fast search, slow insert/delete, low space utilization;
Linked List: Fast insert/delete, slow search, high space utilization


3. Singly Linked List Insert/Delete

Insert: The new node points to the successor, the predecessor points to the new node;
Delete: The predecessor points to the successor of the deleted node


4. Traversal Implementation

Array List: Loop by index;
Linked List: Visit each node via pointer


5. Typical Applications

Stacks, queues, strings, search, sort, merge, etc.