Class Note 2: Data Structures and Algorithms
Class Note 2: Data Structures and Algorithms
Page 1
Arrays
Linked Lists
Page 2
Sorting Algorithms
Bubble Sort:
Definition: A simple sorting algorithm that repeatedly steps through the
list, compares adjacent elements, and swaps them if they are in the wrong order.
Time Complexity: O(n^2)
Space Complexity: O(1)
Selection Sort:
Definition: A sorting algorithm that selects the smallest element from the
unsorted portion of the list and swaps it with the first unsorted element.
Time Complexity: O(n^2)
Space Complexity: O(1)
Insertion Sort:
Definition: A sorting algorithm that builds the final sorted list one item
at a time, inserting each item into its proper position.
Time Complexity: O(n^2)
Space Complexity: O(1)
Merge Sort:
Definition: A divide-and-conquer algorithm that splits the list into
smaller sublists, sorts each sublist, and then merges the sorted sublists.
Time Complexity: O(n log n)
Space Complexity: O(n)
Quick Sort:
Definition: A divide-and-conquer algorithm that selects a pivot element,
partitions the list around the pivot, and recursively sorts the sublists.
Time Complexity: O(n log n) on average, O(n^2) in the worst case
Space Complexity: O(log n) on average, O(n) in the worst case
Stacks: A last-in, first-out (LIFO) data structure that allows for efficient
insertion and deletion of elements.
Queues: A first-in, first-out (FIFO) data structure that allows for efficient
insertion and deletion of elements.
Trees: A hierarchical data structure that consists of nodes, each with a value
and zero or more child nodes.
Graphs: A non-linear data structure that consists of nodes and edges, which
connect pairs of nodes.