Data structures are ways of organizing and storing data so that it can be accessed and modified efficiently. Here are some common data structures:
- Array: A collection of elements of the same type stored in contiguous memory locations. Example:
[1, 2, 3, 4]
. - Linked List: A sequence of elements where each element (node) contains a value and a reference to the next node.
- Stack: A data structure that follows the Last In, First Out (LIFO) principle. Example: managing function calls.
- Queue: A data structure that follows the First In, First Out (FIFO) principle. Example: processing tasks in order of arrival.
- Hash Table: A data structure that stores data in key-value pairs, allowing for fast data retrieval based on a key.
- Tree: A hierarchical data structure with a root node and child nodes. Examples include binary trees and binary search trees.
- Graph: A collection of nodes (vertices) and edges connecting pairs of nodes.
- Binary Search Trees
- Heaps
- Tries
- Union Find
Algorithms are step-by-step procedures or formulas for solving problems. Here are some common algorithms:
- Sorting Algorithms: Techniques for arranging data in a particular order. Examples include Quick Sort, Merge Sort, and Bubble Sort.
- Searching Algorithms: Techniques for finding specific data. Examples include Binary Search and Linear Search.
- Graph Algorithms: Techniques for working with graphs, such as Dijkstra's Algorithm for finding the shortest path.
- Bit Manipulation
- Tree Traversal (InOrder, PreOrder, PostOrder)
- Depth First Search
- Breadth First Search
- Topological Sort
- Minimum Spanning Tree
- Recursion
- Dynamic Programming
- Greedy Algorithms
- Backtracking
Complexity analysis helps evaluate the efficiency of an algorithm in terms of time and space.
Measures the amount of time an algorithm takes to complete, often expressed using Big O notation (O-notation). Common time complexities include:
- O(1): Constant time
- O(n): Linear time
- O(log n): Logarithmic time
- O(n^2): Quadratic time
Measures the amount of memory an algorithm requires. Also expressed using Big O notation.
-
Searching in an Array:
- Linear Search: O(n)
- Binary Search: O(log n)
-
Sorting an Array:
- Bubble Sort: O(n^2)
- Merge Sort: O(n log n)
- Two Pointers
- Sliding Window
- Prefix Sum
- Fast and Slow Pointers
- Divide and Conquer
- Greedy
- Recursion
- Backtracking
- Dynamic Programming
- Top 'K' Elements
- Big O Notation
- Time Complexity
- Space Complexity