Contiguous blocks of memory. Master traversal, insertion, deletion, sub-arrays, rotation, and two-pointer techniques.
P1. Two Sum: Given an array of integers, find two numbers such that they add up to a specific target.
Approach: Use a Hash Map to store elements and their indices. For each element x, check if target - x exists in the map. Time complexity is O(N).
Sequences of characters. Learn reverse algorithms, anagram verification, palindrome checks, substring counts, and pattern matching.
P1. Valid Anagram: Determine if string S and T are anagrams of each other.
Approach: Use a character frequency counter array of size 26. Increment counts for string S and decrement counts for string T. Check if all values are zero. O(N) time and O(1) auxiliary space.
Linear collections of nodes containing pointers. Study singly, doubly, and circular linked lists, loops detection, and node reversals.
P1. Detect Loop in Linked List: Check if a linked list contains a cycle.
Approach: Use two pointers: slow moving 1 step and fast moving 2 steps. If they meet at any node, a cycle exists. If fast reaches NULL, no cycle exists.
LIFO (Last In First Out) structures. Learn array/list implementations, parenthesis matching, expression evaluations, and monotonic stack concepts.
P1. Balanced Parentheses: Check if brackets (), {}, and [] in string S are balanced.
Approach: Push opening brackets onto a stack. When a closing bracket arrives, verify it matches the top of the stack and pop. If mismatched or stack ends empty/non-empty incorrectly, return false.
FIFO (First In First Out) structures. Practice circular queues, double-ended queues (Deques), sliding window maximums, and buffer queues.
P1. Implement Stack using Queues: Construct stack LIFO behavior using queue FIFO methods.
Approach: Use two queues. On pushing an element, enqueue to Queue2, then enqueue all elements from Queue1 to Queue2. Swap the names of Queue1 and Queue2. Push becomes O(N), Pop is O(1).
Non-linear hierarchical nodes. Master Binary Trees, Binary Search Trees (BST), traversals (Pre, In, Post, Level order), heights, and balancing.
P1. Find Height of Binary Tree: Find the length of the longest path from root to leaf node.
Approach: Use a post-order traversal recursively. Height of tree = 1 + max(Height(left_subtree), Height(right_subtree)). Base case returns 0 for NULL.
Nodes (vertices) and edges. Understand Adjacency lists, DFS, BFS, cycle checks, Dijkstra's algorithm, and topological sorting.
P1. Detect Cycle in Undirected Graph: Check if a path can cycle back to an already visited vertex.
Approach: During DFS, pass the 'parent' node. If a neighbor is already visited and is not the parent of the current node, a cycle exists.
Functions calling themselves. Study call stack mechanisms, base cases, fibonacci series, Tower of Hanoi, and backtracking principles.
P1. Fibonacci Sequence: Compute the N-th Fibonacci number.
Approach: Base case: if N <= 1, return N. Otherwise, return fib(N-1) + fib(N-2). Optimize to O(N) using dynamic programming / memoization.
Arranging elements in order. Analyze Bubble, Selection, Insertion, Merge, Quick, Heap, and Radix sort complexities.
P1. Merge Sort Implementation: Sort an array recursively using merge partitions.
Approach: Divide the array into two halves, recursively sort both halves, and then merge the sorted halves back together in O(N log N) time and O(N) auxiliary space.
Finding target elements. Compare Linear Search and Binary Search on sorted spaces, and search space reduction.
P1. Binary Search: Find index of target K in a sorted array.
Approach: Initialize low = 0, high = N-1. While low <= high, calculate mid = low + (high - low)/2. If array[mid] == target, return mid. Adjust boundaries accordingly.