# Data Structure in Python (Updating)

## Preface

### Linear Data Structure

1. Array: fix number, same type
4. Stack: last-in, first-out
5. Queue: first-in, first-out
6. Deque: double end queue, combination of stack and queue
7. Matrix: using Numpy module

1. Binary Tree
2. Heap
3. Hash table
4. Graph

### Python Spec.

1. List: most versatile, basic ops:

• length
• concatenation
• repetition
• membership
• iteration
2. Tuple: immutable, include a single comma if one element

3. Dict:

• no dup-key
• key must be hashable
4. Sets

• No index
• No duplicates
• immutable
• operations: union |, intersect &, difference -, subset <=, superset >=
5. ChainMap

• collection of dicts
• order matters as a stack

Current section is a note of tutorials point

A linked list is a node-within-node hierarchical structure, and it is not a built-in data structure in python.

### Node

Node is a unit within a linked list, and it consists of two parts - value, and the next node, as shown below.

### Methods

Typically, there are three methods in a linked list.

#### Traverse

We can traverse all nodes in a linked list:

Adding a node to the head a special case, it’s pointing new_node.next to the object self.head represents, then let self.head represent the new_node object.

Besides, we can insert a node in a position denoted by index, traversal to the position by get “.next” method iteratively.

Mind that the head node is a special case, and position_node is more like a pointer, that’s why modifying position_node will change self.head.

We can also insert a node by key, and mind the pointer problem again!

And if we want to append a node without knowing either keys or indices, just exhaust all nodes.

#### Delete

Another useful method is deletion. In this case, we do it key-wise, and delete ALL node that have the given key value.

#### Disqus评论

⚠️ 无法加载评论系统，请确保您的网络能够正常访问 Disqus