Memory Representation
Memory representation and basic operations for some common data structures are as follows:
1. Arrays:
- Memory Representation: Contiguous block of memory where elements are stored sequentially.
- Basic Operations:
- Accessing elements by index:
array[index] - Insertion at the end:
array.append(value) - Deletion by index:
del array[index] - Finding length:
len(array)
- Accessing elements by index:
2. Linked Lists:
- Memory Representation: Nodes containing data and a pointer/reference to the next node.
- Basic Operations:
- Insertion at the beginning:
new_node = Node(value) new_node.next = head head = new_node - Deletion at the beginning:
temp = head head = head.next temp.next = None - Traversal:
current = head while current is not None: print(current.data) current = current.next
- Insertion at the beginning:
3. Stacks:
- Memory Representation: Can be implemented using arrays or linked lists.
- Basic Operations:
- Push (Insertion):
stack.push(value) - Pop (Deletion):
stack.pop() - Peek (Access top element):
stack.peek() - Checking if empty:
stack.is_empty()
- Push (Insertion):
4. Queues:
- Memory Representation: Can be implemented using arrays or linked lists.
- Basic Operations:
- Enqueue (Insertion):
queue.enqueue(value) - Dequeue (Deletion):
queue.dequeue() - Peek (Access front element):
queue.peek() - Checking if empty:
queue.is_empty()
- Enqueue (Insertion):
5. Trees:
- Memory Representation: Nodes containing data and references/pointers to child nodes.
- Basic Operations:
- Insertion:
- Binary Search Tree: Recursively traverse and insert based on comparison with node values.
- Deletion:
- Binary Search Tree: Replace with successor or predecessor node.
- Traversal:
- In-order, Pre-order, Post-order traversal algorithms.
- Insertion:
6. Graphs:
- Memory Representation: Adjacency list or adjacency matrix.
- Basic Operations:
- Insertion of vertices and edges.
- Deletion of vertices and edges.
- Traversal: Depth-first search (DFS), Breadth-first search (BFS).
These are basic representations and operations for each data structure. The actual implementation details may vary based on language and specific requirements.
Table of Contents