Algorithms TIME & SPACE are key factors any actions
Top 10 Algorithms src - Youtube (opens new window)
Depth first search Breadth first search Match Brackets/Parentheses Hashtables Variables/pointers manipulations
Ex - find longest palindrome substring in a string Quicksort & Mergesort are faster than Bubblesort Reverse Linked list Sorting algorithms Recursion (Rarely used in production because its a stack which has limits of iterations. Not sure.) Custom Datastructures (Classes, OOPs) Binary Search BUBBLE SORT Sorts elements list like an array . Compares 2 adjacent elements Advantages Disadvantage Simple Not optimal due to multiple iterations No additional space required worst-case for n number of elements requires swappings (n-1) + (n-2) + (n-3) + .... + 3 + 2 + 1 = n(n-1)/2
SELECTION SORT Finds smallest element and place it at start. Repeat for rest of elements. Advantages Disadvantage Very good for smaller list Bad for big lists No additional space required -
INSERTION SORT Similar to sorting playing cards Advantages Disadvantage Good for small lists Bad for large lists No extra space -
MERGE SORT Divide and conquer Divide array into half until each item is single element Advantages Disadvantage Good for sorting Linked lists with no extra space Array needs temporary extra space
QUICK SORT Select any element as pivot element Sort rest of elements as [] <= (pivot) >= []
Repeat for remaining arrays. Advantages Disadvantage Faster Slow if bad pivot is choosen No extra space
3-way Quicksort is another way in which 3 arrays are created (lesser, equal, greater) instead of 2 arrays TOWER OF HANOI LINEAR SEARCH Every item is searched and the index is returned if matched. -1
is returned if not matched Starts from left of the list
Disadvantages Rarely used. Binary search(see below) is better BINARY SEARCH Sorted list is required Divide and conquer. Into 2 parts. Matches elements with middle element of list Index is returned if matched If middle item is greater than search item then use left side array else use right side array. Repeat on each sub-arrays till sub-array size is 0. Last Updated: 4/7/2021, 10:29:29 AM