2.
6 Data Structures and
Algorithms
Understanding the Foundations of
Efficient Programming
What are Data Structures?
• Data structures are ways to organize and store
data efficiently.
• - Help in managing and manipulating data.
• - Improve performance in searching, sorting,
and processing.
• - Examples: Arrays, Linked Lists, Stacks,
Queues, Trees, Graphs.
Common Data Structures
• - Arrays: Fixed-size, indexed collection.
• - Linked Lists: Dynamic nodes linked together.
• - Stacks: Last-In-First-Out (LIFO) structure.
• - Queues: First-In-First-Out (FIFO) structure.
• - Trees: Hierarchical structure (e.g., Binary
Tree).
• - Graphs: Nodes connected by edges, used in
networks.
What are Algorithms?
• An algorithm is a step-by-step procedure for
solving a problem.
• - Optimizes efficiency in computation.
• - Examples: Sorting, searching, and graph
traversal algorithms.
Sorting Algorithms
• - Bubble Sort: Repeatedly swaps adjacent
elements.
• - Selection Sort: Finds the smallest element
and places it first.
• - Merge Sort: Recursively splits and merges
sorted halves.
• - Quick Sort: Uses pivot element for
partitioning.
Searching Algorithms
• - Linear Search: Checks each element
sequentially.
• - Binary Search: Efficient for sorted arrays
(O(log n)).
• - Hashing: Uses a key-value pair mapping for
quick access.
Algorithm Complexity (Big O Notation)
• Big O Notation describes algorithm efficiency:
• - O(1): Constant time.
• - O(log n): Logarithmic time.
• - O(n): Linear time.
• - O(n log n): Efficient sorting.
• - O(n²): Nested loops, inefficient for large
inputs.
Applications of Data Structures &
Algorithms
• - Databases use indexing for fast searches.
• - Operating systems manage memory using
queues.
• - AI and ML optimize data processing.
• - Networking uses graph algorithms for
routing.
Conclusion
• Data structures and algorithms improve
efficiency in problem-solving.
• - Choosing the right structure affects speed
and memory usage.
• - Understanding algorithms helps optimize
performance.