Comprehensive notes, MCQs, and Short Questions for Chapter 4 Computational Structures. Covers Lists, Stacks, Queues, Trees, and Graphs in Python.
Definition: A list is a data structure that stores multiple items in a specific sequence. Created using square brackets [].
Properties:
- Dynamic Size: Can grow or shrink.
- Indexed Access: Elements accessed by index (starting at 0).
- Maintains Order: Preserves insertion order.
- Heterogeneous: Can store different data types.
- Mutable: Can be changed after creation.
- Allows Duplicates: Same value can appear multiple times.
Insertion:
- append(item): Adds item at the end.
- insert(index, item): Adds item at a specific position.
Deletion:
- remove(item): Removes by value.
- pop(index): Removes by index.
Searching: Use in keyword to check if item exists.
Definition: A data structure where the last item added is the first one removed (Last-In, First-Out).
Real-life Example: A pile of plates.
Operations:
- Push: Add item to the top (append()).
- Pop: Remove item from the top (pop()).
Definition: A data structure where the first item added is the first one removed (First-In, First-Out).
Real-life Example: A line at a ticket counter.
Operations:
- Enqueue: Add item to the end (put()).
- Dequeue: Remove item from the front (get()).
Definition: A hierarchical structure with nodes connected by edges. Has one root node and can have many levels.
Key Terms:
- Root: Topmost node.
- Node: Individual element.
- Edge: Connection between nodes.
- Leaf: Node with no children.
- Height: Number of edges from root to deepest node.
Applications: File systems, decision trees, family trees, organization charts.
Definition: A structure showing connections between objects, made of vertices (nodes) and edges (links).
Types:
- Directed Graph: One-way connections.
- Undirected Graph: Two-way connections.
- Weighted Graph: Edges have values (e.g., distance).
Applications: Social networks, city maps, transport systems.