Algorithms Class Notes
1. Arrays and Strings
Arrays are fixed-size collections of elements of the same type.
Advantages:
- Fast access (O(1))
- Efficient memory usage
Disadvantages:
- Fixed size
- Costly insertions/deletions
Strings are arrays of characters, often with special handling in many languages.
2. Linked Lists
Linked List is a linear data structure where each element points to the next.
Types:
- Singly Linked List
- Doubly Linked List
- Circular Linked List
Advantages:
- Dynamic size
- Easy insertion/deletion
Disadvantages:
- Sequential access
- Extra memory for pointers
Algorithms Class Notes
3. Stacks and Queues
Stacks: LIFO (Last-In-First-Out)
- Operations: push, pop, peek
- Applications: recursion, undo functionality
Queues: FIFO (First-In-First-Out)
- Operations: enqueue, dequeue
- Types: Circular Queue, Priority Queue
- Applications: scheduling, buffering
4. Trees
Trees are hierarchical data structures with nodes.
Types:
- Binary Tree
- Binary Search Tree (BST)
- AVL Tree (self-balancing)
- Heap (Max/Min)
Operations: insertion, deletion, traversal (inorder, preorder, postorder)
5. Hash Tables
Hash Tables store key-value pairs using a hash function.
Advantages:
- Fast lookups (average O(1))
Algorithms Class Notes
Challenges:
- Collisions (handled by chaining or open addressing)
Applications: dictionaries, caching, databases
6. Graphs
Graphs consist of vertices (nodes) and edges.
Can be directed/undirected, weighted/unweighted.
Representations:
- Adjacency Matrix
- Adjacency List
Applications: social networks, web page linking, navigation