Introduction to Data Structures and ADTs
1. Introduction to Data Structures
Data structures are ways to store and organize data efficiently so operations can be performed effectively.
Common examples include arrays, linked lists, stacks, and queues.
2. Abstract Data Types (ADTs)
ADTs are theoretical concepts that define data and the operations that can be performed on them, without
specifying implementation. Examples: List, Stack, Queue, Tree.
3. List ADT
List ADT defines a linear collection of elements where order matters. Basic operations: insert, delete,
traverse, and search.
4. Array-based Implementation of List
An array is used to store elements in contiguous memory.
Algorithm (Insert at index i):
1. Shift elements from i to end by one position right.
2. Place new element at index i.
3. Increase size.
Time complexity: O(n) for insert/delete.
5. Linked List Implementation
Linked list uses nodes with data and a pointer to the next node.
Advantages:
- Dynamic size
- Easy insertion/deletion
Introduction to Data Structures and ADTs
Types:
1. Singly Linked List
2. Doubly Linked List
3. Circularly Linked List
6. Singly Linked List
Each node contains data and a pointer to the next node.
Algorithm (Insert at beginning):
1. Create new node
2. Set new_node.next = head
3. head = new_node
Time complexity: O(1) for insertion at beginning.
7. Doubly Linked List
Each node has three parts: prev, data, next.
Algorithm (Insert after a node):
1. Create new node
2. Set new_node.prev = current
3. Set new_node.next = current.next
4. Update pointers accordingly
More efficient backward traversal.
8. Circularly Linked List
Last node points back to the head. Can be singly or doubly circular.
Introduction to Data Structures and ADTs
Used in round-robin scheduling, buffering.
9. Applications - Polynomial Manipulation
Polynomials can be represented using linked lists where each node contains coefficient and exponent.
Example: 5x^3 + 4x^2 + 2 -> Node1(5,3)->Node2(4,2)->Node3(2,0)
Addition Algorithm:
1. Traverse both polynomials
2. Compare exponents
3. Add like terms and store in result list