DSA Simple Algorithm
DSA Simple Algorithm is not an official technical term, but in many beginner-friendly tutorials, YouTube channels, and Indian college coaching content, when people say
“simple algorithms in DSA” “start with simple algorithms” “DSA simple algorithm list”
they usually mean:
The easiest, most fundamental, most frequently asked algorithms that almost every beginner should learn first — before moving to medium/hard topics like DP, Graphs, Heaps, etc.
These are the algorithms that:
- Use basic concepts
- Appear in almost every company’s easy/medium questions
- Help you build intuition for coding patterns
- Are short to implement (10–25 lines usually)
Let me explain it like your friend who’s one year ahead in college and is teaching you honestly.
What are “Simple Algorithms” in DSA? (Most common meaning)
These are the algorithms that usually come in the first 1–3 months of serious DSA learning:
- Linear Search
- Binary Search
- Bubble Sort
- Selection Sort
- Insertion Sort
- Find minimum / maximum in array
- Reverse an array / string
- Find duplicates in array (simple methods)
- Count frequency of elements
- Check if array is sorted
- Find second largest / second smallest
- Move all zeros to end
- Rotate array by k positions
- Kadane’s Algorithm (maximum subarray sum) — considered simple-medium
- Prefix Sum array (very useful pattern)
These are sometimes called “Level 1 Algorithms” or “Basic Algorithms” in many roadmaps.
Let’s go through the most important ones with clear explanations + examples
1. Linear Search
What it does: Checks every element one by one until it finds the target or reaches the end.
When to use: Small list, or list is not sorted
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
def linear_search(arr, target): for i in range(len(arr)): if arr[i] == target: return i # return index where found return -1 # not found # Example numbers = [64, 34, 25, 12, 22, 11, 90] print(linear_search(numbers, 22)) # Output: 4 print(linear_search(numbers, 100)) # Output: -1 |
Time Complexity: O(n) — worst case check all elements
2. Binary Search
What it does: Repeatedly divides the search interval in half (but array must be sorted)
Super important — asked in almost every company
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
def binary_search(arr, target): left = 0 right = len(arr) - 1 while left <= right: mid = (left + right) // 2 if arr[mid] == target: return mid elif arr[mid] < target: left = mid + 1 else: right = mid - 1 return -1 # Example sorted_numbers = [2, 5, 8, 12, 16, 23, 38, 56, 72, 91] print(binary_search(sorted_numbers, 23)) # Output: 5 |
Time Complexity: O(log n) — very fast even for 1 million elements
3. Bubble Sort
What it does: Repeatedly steps through the list, compares adjacent elements and swaps them if they are in wrong order
Very easy to understand, very slow in practice
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
def bubble_sort(arr): n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: # swap arr[j], arr[j+1] = arr[j+1], arr[j] return arr # Example arr = [64, 34, 25, 12, 22, 11, 90] print(bubble_sort(arr)) # Output: [11, 12, 22, 25, 34, 64, 90] |
Time Complexity: O(n²) — very slow for large arrays
4. Selection Sort
What it does: Repeatedly finds the minimum element from unsorted part and puts it at the beginning
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
def selection_sort(arr): n = len(arr) for i in range(n): min_idx = i for j in range(i+1, n): if arr[j] < arr[min_idx]: min_idx = j # swap arr[i], arr[min_idx] = arr[min_idx], arr[i] return arr # Example same as above |
Time Complexity: O(n²)
5. Insertion Sort
What it does: Builds the final sorted array one item at a time (like sorting cards in your hand)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def insertion_sort(arr): for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key return arr |
Best case (already sorted): O(n) — very fast Worst case: O(n²)
6. Find Maximum and Minimum in one pass
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
def find_min_max(arr): if not arr: return None, None min_val = max_val = arr[0] for num in arr[1:]: if num < min_val: min_val = num if num > max_val: max_val = num return min_val, max_val # Example print(find_min_max([3, 7, 1, 9, 4, 2])) # (1, 9) |
7. Reverse an array (two pointer method – most efficient)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def reverse_array(arr): left = 0 right = len(arr) - 1 while left < right: arr[left], arr[right] = arr[right], arr[left] left += 1 right -= 1 return arr |
8. Move all zeros to end (very common question)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
def move_zeros(arr): non_zero = 0 # Move all non-zero elements to front for i in range(len(arr)): if arr[i] != 0: arr[non_zero] = arr[i] non_zero += 1 # Fill rest with zeros while non_zero < len(arr): arr[non_zero] = 0 non_zero += 1 return arr # Example print(move_zeros([0, 1, 0, 3, 12])) # [1, 3, 12, 0, 0] |
Quick Summary Table – Simple Algorithms
| Algorithm | Difficulty | Time Complexity | Very Important? | Appears in |
|---|---|---|---|---|
| Linear Search | ★☆☆ | O(n) | Yes | Easy questions |
| Binary Search | ★★☆ | O(log n) | ★★★★★ | Almost every company |
| Bubble Sort | ★☆☆ | O(n²) | Learning only | Interviews rarely |
| Selection Sort | ★☆☆ | O(n²) | Learning only | Rarely |
| Insertion Sort | ★★☆ | O(n²) best O(n) | Learning + useful | Sometimes |
| Reverse Array | ★☆☆ | O(n) | Yes | Very common |
| Move Zeroes | ★★☆ | O(n) | Yes | Very common |
| Find Min/Max | ★☆☆ | O(n) | Yes | Basic |
| Kadane’s (max subarray) | ★★☆ | O(n) | Yes | Very common |
Suggested Order (realistic for beginners)
- Linear Search + Find min/max
- Binary Search (practice a lot!)
- Reverse array, move zeroes
- Understand Bubble / Selection / Insertion (don’t memorize code, understand logic)
- Kadane’s Algorithm (very important pattern)
- Prefix Sum questions
These 6–8 simple algorithms + patterns will help you solve ~40–60% of easy questions on LeetCode.
Would you like me to explain any one of these in even more detail? Examples:
- Binary Search all variations
- Kadane’s algorithm with many examples
- Two-pointer technique for simple problems
- How to spot when to use which simple algorithm
Just tell me which one you want next! 😄
