MindMap Gallery Data Structure Chapter 2-Linear Table
Chapter 2 of "Data Structure" - sorting out the knowledge of linear tables, including its definition and basic operations, sequential representation, and chain representation.
Edited at 2022-11-23 16:06:11One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
Project management is the process of applying specialized knowledge, skills, tools, and methods to project activities so that the project can achieve or exceed the set needs and expectations within the constraints of limited resources. This diagram provides a comprehensive overview of the 8 components of the project management process and can be used as a generic template for direct application.
One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
Project management is the process of applying specialized knowledge, skills, tools, and methods to project activities so that the project can achieve or exceed the set needs and expectations within the constraints of limited resources. This diagram provides a comprehensive overview of the 8 components of the project management process and can be used as a generic template for direct application.
linear table
Definition and basic operations
definition
A linear table is a finite sequence of n data elements of the same data type
a1 is the header element
an is the table element
Every element except the first element has one and only one direct predecessor; every element except the last element has one and only one direct successor.
Features
The number of elements in the table is limited
The elements in the table have a logical sequence. The elements in the table have their order.
The elements in the table are all data elements, and each element is a single element
The data types of the elements in the table are all the same, which means that each element occupies the same size of storage space
The elements in the table are abstract, that is, only the logical relationship between the elements is discussed, without considering what the elements actually represent.
Basic operations of linear tables
InitList(&): Initialization list. Construct an empty linear table
Length(L): Find the length of the table. Returns the length of the linear table L, that is, the number of data elements in L
LocateElem(L,e): Find operation by value. Find elements in table L with given key value
GetElem(L,i): Bitwise search operation. Get the value of the element at position i in the table
ListInsert (&L,i,e): Insertion operation. Insert the specified element e at the i-th position in table L
ListDelete(&L,i,&e): Delete operation. Delete the element at the i-th position in the table and use e to return the value of the deleted element
PrintList(L): Output operation. Output all element values of the linear table in sequential order
Empty(L): Empty operation. If the job is an empty table, return true, otherwise return false
DestroyList(&L): Destroy operation. Destroy the linear table and release the memory space occupied by linear table L
sequential representation
definition
The sequential storage of a linear table uses a set of storage units with consecutive addresses to sequentially store the data elements in the linear table, so that two logically adjacent elements are also physically adjacent.
Features
random access
The specified element can be found in time O(1) through the first address and element number.
High storage density, each node only stores data elements
The logical order of elements in a table is the same as their physical order, so insertion and deletion operations require moving a large number of elements
Basic operations
(1) insert
Time complexity: O(n)
(2) delete
Time complexity: O(n)
(3) Find by value (sequential search)
Time complexity: O(n)
chain representation
Definition of singly linked list
Store data elements in a linear table through an arbitrary set of storage units
For each linked list node, in addition to storing the element's own information, it also needs to store a pointer to its successor.
Attach a node before the first node of the singly linked list, called the head node. Its data field does not contain any information, and the pointer points to the first element node of the linear list.
Basic operations of singly linked list
Create a singly linked list using head insertion method
The order of the nodes in the generated linked list is inconsistent with the order of the input data.
Time complexity: O(n)
Create a singly linked list using tail insertion method
Introduce the tail pointer r, which always points to the tail node of the current linked list
Time complexity: O(n)
Find node value by serial number
Time complexity: O(n)
Find table nodes by value
Time complexity: O(n)
Insert node operation
time complexity
Inserting after a given node: O(1)
Otherwise, O(n)
Forward insertion operation
Assume that the node to be inserted is s, and insert it in front of node p: s can be inserted after p first, and then p->data and s->data are exchanged. The time complexity is only O(1)
Delete node operation
Time complexity: O(1)
Extended approach: In order to delete node p, you can first assign the value of its successor node to itself, and then delete the successor node. The time complexity is only O(1)
Find table length operation
Time complexity: O(n)
Double linked list
The time complexity of accessing the predecessor node of a single linked list is O(n). For this reason, a double linked list is introduced. Each node has two pointers, prior and next, pointing to its predecessor and successor nodes respectively.
insert operation
Delete operation
circular linked list
Circular singly linked list
The pointer of the last node in the table is not NULL, but points to the head node.
The rest is the same as singly linked list
Circular doubly linked list
The prior pointer of the head node points to the end node of the list; when the linked list is an empty list, the prior field and next field of the head node are both equal to L
static linked list
Use arrays to describe the linked storage structure of linear lists
The pointer is the relative address of the node (array subscript), also known as the cursor
Use next==-1 as the end mark
Comparison of sequence list and linked list
Access (read and write) methods
Sequence table: can be accessed sequentially or randomly
Linked list: elements can only be accessed sequentially from the head of the list
Logical structure and physical structure
Find, insert and delete element operations
space allocation
Sequential storage is difficult to expand when static storage is allocated; dynamic storage allocation will reduce operating efficiency