Asymptotic Notations

Asymptotic Notations

We have discussed Asymptotic Analysis, and Worst, Average and Best Cases of Algorithms. The main idea of asymptotic analysis is to have a measure of efficiency of algorithms that doesn’t depend on machine specific constants, and doesn’t require algorithms to be implemented and time taken by programs to be compared. Asymptotic notations are mathematical tools to represent time complexity of algorithms for asymptotic analysis. The following 3 asymptotic notations are mostly used to represent time complexity of algorithms.

thetanotation1) Θ Notation: The theta notation bounds a functions from above and below, so it defines exact asymptotic behavior.
A simple way to get Theta notation of an expression is to drop low order terms and ignore leading constants. For example, consider the following expression.
3n3 + 6n2 + 6000 = Θ(n3)
Dropping lower order terms is always fine because there will always be a n0 after which Θ(n3) has higher values than Θn2) irrespective of the constants involved.
For a given function g(n), we denote Θ(g(n)) is following set of functions.

Θ(g(n)) = {f(n): there exist positive constants c1, c2 and n0 such 
                 that 0 <= c1*g(n) <= f(n) <= c2*g(n) for all n >= n0}

The above definition means, if f(n) is theta of g(n), then the value f(n) is always between c1*g(n) and c2*g(n) for large values of n (n >= n0). The definition of theta also requires that f(n) must be non-negative for values of n greater than n0.

BigO2) Big O Notation: The Big O notation defines an upper bound of an algorithm, it bounds a function only from above. For example, consider the case of Insertion Sort. It takes linear time in best case and quadratic time in worst case. We can safely say that the time complexity of Insertion sort is O(n^2). Note that O(n^2) also covers linear time.
If we use Θ notation to represent time complexity of Insertion sort, we have to use two statements for best and worst cases:
1. The worst case time complexity of Insertion Sort is Θ(n^2).
2. The best case time complexity of Insertion Sort is Θ(n).

The Big O notation is useful when we only have upper bound on time complexity of an algorithm. Many times we easily find an upper bound by simply looking at the algorithm.

 

O(g(n)) = { f(n): there exist positive constants c and 
                  n0 such that 0 <= f(n) <= cg(n) for 
                  all n >= n0}

BigOmega3) Ω Notation: Just as Big O notation provides an asymptotic upper bound on a function, Ω notation provides an asymptotic lower bound.

Ω Notation< can be useful when we have lower bound on time complexity of an algorithm. As discussed in the previous post, the best case performance of an algorithm is generally not useful, the Omega notation is the least used notation among all three.

For a given function g(n), we denote by Ω(g(n)) the set of functions.

Ω (g(n)) = {f(n): there exist positive constants c and
                  n0 such that 0 <= cg(n) <= f(n) for
                  all n >= n0}.

Let us consider the same Insertion sort example here. The time complexity of Insertion Sort can be written as Ω(n), but it is not a very useful information about insertion sort, as we are generally interested in worst case and sometimes in average case.

Exercise:
Which of the following statements is/are valid?
1. Time Complexity of QuickSort is Θ(n^2)
2. Time Complexity of QuickSort is O(n^2)
3. For any two functions f(n) and g(n), we have f(n) = Θ(g(n)) if and only if f(n) = O(g(n)) and f(n) = Ω(g(n)).
4. Time complexity of all computer algorithms can be written as Ω(1)

Important Links :

Worst, Average and Best Cases

 

Worst, Average and Best Cases

we discussed how Asymptotic analysis overcomes the problems of naive way of analyzing algorithms. In this post, we will take an example of Linear Search and analyze it using Asymptotic analysis.

We can have three cases to analyze an algorithm:
1) Worst Case
2) Average Case
3) Best Case

Let us consider the following implementation of Linear Search.

 

#include <stdio.h>

// Linearly search x in arr[].  If x is present then return the index,
// otherwise return -1
int search(int arr[], int n, int x)
{
    int i;
    for (i=0; i<n; i++)
    {
       if (arr[i] == x)
         return i;
    }
    return -1;
}

/* Driver program to test above functions*/
int main()
{
    int arr[] = {1, 10, 30, 15};
    int x = 30;
    int n = sizeof(arr)/sizeof(arr[0]);
    printf("%d is present at index %d", x, search(arr, n, x));

    getchar();
    return 0;
}

Worst Case Analysis (Usually Done)
In the worst case analysis, we calculate upper bound on the running time of an algorithm. We must know the case that causes the maximum number of operations to be executed. For Linear Search, the worst case happens when the element to be searched (x in the above code) is not present in the array. When x is not present, the search() functions compares it with all the elements of arr[] one by one. Therefore, the worst case time complexity of linear search would be Θ(n).

Average Case Analysis (Sometimes done) 
In average case analysis, we take all possible inputs and calculate computing time for all of the inputs. Sum all the calculated values and divide the sum by a total number of inputs. We must know (or predict) distribution of cases. For the linear search problem, let us assume that all cases are uniformly distributed (including the case of x not being present in array). So we sum all the cases and divide the sum by (n+1). Following is the value of average case time complexity.

Average Case Time = analysis1

                  = analysis2 

                  = Θ(n) 

Best Case Analysis (Bogus) 
In the best case analysis, we calculate lower bound on the running time of an algorithm. We must know the case that causes minimum number of operations to be executed. In the linear search problem, the best case occurs when x is present at the first location. The number of operations in the best case is constant (not dependent on n). So time complexity in the best case would be Θ(1)
Most of the times, we do worst-case analysis to analyze algorithms. In the worst analysis, we guarantee an upper bound on the running time of an algorithm which is good information.
The average case analysis is not easy to do in most of the practical cases and it is rarely done. In the average case analysis, we must know (or predict) the mathematical distribution of all possible inputs.
The Best Case analysis is bogus. Guaranteeing a lower bound on an algorithm doesn’t provide any information as in the worst case, an algorithm may take years to run.

For some algorithms, all the cases are asymptotically same, i.e., there are no worst and best cases. For example,Merge Sort. Merge Sort does Θ(nLogn) operations in all cases. Most of the other sorting algorithms have worst and best cases. For example, in the typical implementation of Quick Sort (where pivot is chosen as a corner element), the worst occurs when the input array is already sorted and the best occurs when the pivot elements always divide array in two halves. For insertion sort, the worst case occurs when the array is reverse sorted and the best case occurs when the array is sorted in the same order as output.

Analysis of Algorithms

(Asymptotic Analysis)

Why performance analysis?
There are many important things that should be taken care of, like user-friendliness, modularity, security, maintainability, etc. Why worry about performance? 
The answer to this is simple, we can have all the above things only if we have performance. So performance is like currency through which we can buy all the above things. Another reason for studying performance is – speed is fun!


Given two algorithms for a task, how do we find out which one is better?

One naive way of doing this is – implement both the algorithms and run the two programs on your computer for different inputs and see which one takes less time. There are many problems with this approach for the analysis of algorithms.
1) It might be possible that for some inputs, the first algorithm performs better than the second. And for some inputs second performs better.
2) It might also be possible that for some inputs, the first algorithm performs better on one machine and the second works better on other machines for some other inputs.

Asymptotic Analysis is the big idea that handles above issues in analyzing algorithms. In Asymptotic Analysis, we evaluate the performance of an algorithm in terms of input size (we don’t measure the actual running time). We calculate, how does the time (or space) taken by an algorithm increases with the input size.
For example, let us consider the search problem (searching for a given item) in a sorted array. One way to search is Linear Search (order of growth is linear) and another way is Binary Search (order of growth is logarithmic). To understand how Asymptotic Analysis solves the above-mentioned problems in analyzing algorithms, let us say we run the Linear Search on a fast computer and Binary Search on a slow computer. For small values of input array size n, the fast computer may take less time. But, after a certain value of input array size, the Binary Search will definitely start taking less time compared to the Linear Search even though the Binary Search is being run on a slow machine. The reason is the order of growth of Binary Search with respect to input size logarithmic while the order of growth of Linear Search is linear. So the machine dependent constants can always be ignored after certain values of input size.

Does Asymptotic Analysis always work?
Asymptotic Analysis is not perfect, but that’s the best way available for analyzing algorithms. For example, say there are two sorting algorithms that take 1000nLogn and 2nLogn time respectively on a machine. Both of these algorithms are asymptotically same (order of growth is nLogn). So, With Asymptotic Analysis, we can’t judge which one is better as we ignore constants in Asymptotic Analysis.
Also, in the Asymptotic analysis, we always talk about input sizes larger than a constant value. It might be possible that those large inputs are never given to your software and an algorithm which is asymptotically slower, always performs better for your particular situation. So, you may end up choosing an algorithm that is Asymptotically slower but faster for your software.

Algorithms

Algorithms

 

Topics :

 

Analysis of Algorithms:

  1. Asymptotic Analysis
  2. Worst, Average and Best Cases
  3. Asymptotic Notations
  4. Little o and little omega notations
  5. Analysis of Loops
  6. Solving Recurrences
  7. Amortized Analysis
  8. What does ‘Space Complexity’ mean?
  9. Pseudo-polynomial Algorithms
  10. NP-Completeness Introduction
  11. Polynomial Time Approximation Scheme
  12. A Time Complexity Question
  13. Time Complexity of building a heap
  14. Time Complexity where loop variable is incremented by 1, 2, 3, 4 ..
  15. Time Complexity of Loop with Powers
  16. Performance of loops (A caching question)

Recent Articles on Analysis of Algorithms
Quiz on Analysis of Algorithms
Quiz on Recurrences

 

Searching and Sorting:

  1. Linear Search, Binary Search, Jump Search, Interpolation Search, Exponential Search, Ternary Search
  2. Selection Sort, Bubble Sort, Insertion Sort, Merge Sort, Heap Sort, QuickSort, Radix Sort, Counting Sort, Bucket Sort, ShellSort, Comb Sort, Pigeonhole Sort, Cycle Sort
  3. Interpolation search vs Binary search
  4. Stability in sorting algorithms
  5. When does the worst case of Quicksort occur?
  6. Lower bound for comparison based sorting algorithms
  7. Which sorting algorithm makes minimum number of memory writes?
  8. Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
  9. Merge Sort for Linked Lists
  10. Sort a nearly sorted (or K sorted) array
  11. Iterative Quick Sort
  12. QuickSort on Singly Linked List
  13. QuickSort on Doubly Linked List
  14. Find k closest elements to a given value
  15. Sort n numbers in range from 0 to n^2 – 1 in linear time
  16. A Problem in Many Binary Search Implementations
  17. Search in an almost sorted array
  18. Sort an array in wave form
  19. Why is Binary Search preferred over Ternary Search?
  20. K’th Smallest/Largest Element in Unsorted Array
  21. K’th Smallest/Largest Element in Unsorted Array in Expected Linear Time
  22. K’th Smallest/Largest Element in Unsorted Array in Worst Case Linear Time
  23. Find the closest pair from two sorted arrays
  24. Find common elements in three sorted arrays
  25. Given a sorted array and a number x, find the pair in array whose sum is closest to x
  26. Count 1’s in a sorted binary array
  27. Binary Insertion Sort
  28. Insertion Sort for Singly Linked List
  29. Why Quick Sort preferred for Arrays and Merge Sort for Linked Lists?
  30. Merge Sort for Doubly Linked List
  31. Minimum adjacent swaps to move maximum and minimum to corners

Recent Articles on Searching
Recent Articles on Sorting
Quiz on Searching
Quiz on Sorting
Coding Practice on Searching
Coding Practice on Sorting

 

Greedy Algorithms:

  1. Activity Selection Problem
  2. Kruskal’s Minimum Spanning Tree Algorithm
  3. Huffman Coding
  4. Efficient Huffman Coding for Sorted Input
  5. Prim’s Minimum Spanning Tree Algorithm
  6. Prim’s MST for Adjacency List Representation
  7. Dijkstra’s Shortest Path Algorithm
  8. Dijkstra’s Algorithm for Adjacency List Representation
  9. Job Sequencing Problem
  10. Quiz on Greedy Algorithms
  11. Greedy Algorithm to find Minimum number of Coins
  12. K Centers Problem
  13. Minimum Number of Platforms Required for a Railway/Bus Station

Recent Articles on Greedy Algorithms
Quiz on Greedy Algorithms
Coding Practice on Greedy Algorithms

 

Dynamic Programming:

  1. Overlapping Subproblems Property
  2. Optimal Substructure Property
  3. Longest Increasing Subsequence
  4. Longest Common Subsequence
  5. Edit Distance
  6. Min Cost Path
  7. Coin Change
  8. Matrix Chain Multiplication
  9. Binomial Coefficient
  10. 0-1 Knapsack Problem
  11. Egg Dropping Puzzle
  12. Longest Palindromic Subsequence
  13. Cutting a Rod
  14. Maximum Sum Increasing Subsequence
  15. Longest Bitonic Subsequence
  16. Floyd Warshall Algorithm
  17. Palindrome Partitioning
  18. Partition problem
  19. Word Wrap Problem
  20. Maximum Length Chain of Pairs
  21. Variations of LIS
  22. Box Stacking Problem
  23. Program for Fibonacci numbers
  24. Minimum number of jumps to reach end
  25. Maximum size square sub-matrix with all 1s
  26. Ugly Numbers
  27. Largest Sum Contiguous Subarray
  28. Longest Palindromic Substring
  29. Bellman–Ford Algorithm for Shortest Paths
  30. Optimal Binary Search Tree
  31. Largest Independent Set Problem
  32. Subset Sum Problem
  33. Maximum sum rectangle in a 2D matrix
  34. Count number of binary strings without consecutive 1?s
  35. Boolean Parenthesization Problem
  36. Count ways to reach the n’th stair
  37. Minimum Cost Polygon Triangulation
  38. Mobile Numeric Keypad Problem
  39. Count of n digit numbers whose sum of digits equals to given sum
  40. Minimum Initial Points to Reach Destination
  41. Total number of non-decreasing numbers with n digits
  42. Find length of the longest consecutive path from a given starting character
  43. Tiling Problem
  44. Minimum number of squares whose sum equals to given number n
  45. Find minimum number of coins that make a given value
  46. Collect maximum points in a grid using two traversals
  47. Shortest Common Supersequence
  48. Compute sum of digits in all numbers from 1 to n
  49. Count possible ways to construct buildings
  50. Maximum profit by buying and selling a share at most twice
  51. How to print maximum number of A’s using given four keys
  52. Find the minimum cost to reach destination using a train
  53. Vertex Cover Problem | Set 2 (Dynamic Programming Solution for Tree)
  54. Count number of ways to reach a given score in a game
  55. Weighted Job Scheduling
  56. Longest Even Length Substring such that Sum of First and Second Half is same

Recent Articles on Dynamic Programming
Quiz on Dynamic Programming
Coding Practice on Dynamic Programing

 

Pattern Searching:

  1. Naive Pattern Searching
  2. KMP Algorithm
  3. Rabin-Karp Algorithm
  4. A Naive Pattern Searching Question
  5. Finite Automata
  6. Efficient Construction of Finite Automata
  7. Boyer Moore Algorithm – Bad Character Heuristic
  8. Suffix Array
  9. Anagram Substring Search (Or Search for all permutations)
  10. Pattern Searching using a Trie of all Suffixes
  11. Aho-Corasick Algorithm for Pattern Searching
  12. kasai’s Algorithm for Construction of LCP array from Suffix Array
  13. Z algorithm (Linear time pattern searching Algorithm)
  14. Program to wish Women’s Day

Recent Articles on Pattern Searching

 

Other String Algorithms:

  1. Manacher’s Algorithm – Linear Time Longest Palindromic Substring – Part 1, Part 2, Part 3, Part 4
  2. Longest Even Length Substring such that Sum of First and Second Half is same
  3. Print all possible strings that can be made by placing spaces

Recent Articles on Strings
Coding practice on Strings

 

Backtracking:

  1. Print all permutations of a given string
  2. The Knight’s tour problem
  3. Rat in a Maze
  4. N Queen Problem
  5. Subset Sum
  6. m Coloring Problem
  7. Hamiltonian Cycle
  8. Sudoku
  9. Tug of War
  10. Solving Cryptarithmetic Puzzles

Recent Articles on Backtracking
Coding Practice on Backtracking

 

Divide and Conquer:

  1. Introduction
  2. Write your own pow(x, n) to calculate x*n
  3. Median of two sorted arrays
  4. Count Inversions
  5. Closest Pair of Points
  6. Strassen’s Matrix Multiplication

Recent Articles on Divide and Conquer
Quiz on Divide and Conquer
Coding practice on Divide and Conquer

 

Geometric Algorithms:

  1. Closest Pair of Points | O(nlogn) Implementation
  2. How to check if two given line segments intersect?
  3. How to check if a given point lies inside or outside a polygon?
  4. Convex Hull | Set 1 (Jarvis’s Algorithm or Wrapping)
  5. Convex Hull | Set 2 (Graham Scan)
  6. Given n line segments, find if any two segments intersect
  7. Check whether a given point lies inside a triangle or not
  8. How to check if given four points form a square

Recent Articles on Geometric Algorithms
Coding Practice on Geometric Algorithms

 

Mathematical Algorithms:

  1. Write an Efficient Method to Check if a Number is Multiple of 3
  2. Efficient way to multiply with 7
  3. Write a C program to print all permutations of a given string
  4. Lucky Numbers
  5. Write a program to add two numbers in base 14
  6. Babylonian method for square root
  7. Multiply two integers without using multiplication, division and bitwise operators, and no loops
  8. Print all combinations of points that can compose a given number
  9. Write you own Power without using multiplication(*) and division(/) operators
  10. Program for Fibonacci numbers
  11. Average of a stream of numbers
  12. Count numbers that don’t contain 3
  13. MagicSquare
  14. Sieve of Eratosthenes
  15. Number which has the maximum number of distinct prime factors in the range M to N
  16. Find day of the week for a given date
  17. DFA based division
  18. Generate integer from 1 to 7 with equal probability
  19. Given a number, find the next smallest palindrome
  20. Make a fair coin from a biased coin
  21. Check divisibility by 7
  22. Find the largest multiple of 3
  23. Lexicographic rank of a string
  24. Print all permutations in sorted (lexicographic) order
  25. Shuffle a given array
  26. Space and time efficient Binomial Coefficient
  27. Reservoir Sampling
  28. Pascal’s Triangle
  29. Select a random number from stream, with O(1) space
  30. Find the largest multiple of 2, 3 and 5
  31. Efficient program to calculate e^x
  32. Measure one litre using two vessels and infinite water supply
  33. Efficient program to print all prime factors of a given number
  34. Print all possible combinations of r elements in a given array of size n
  35. Random number generator in arbitrary probability distribution fashion
  36. How to check if a given number is Fibonacci number?
  37. Russian Peasant Multiplication
  38. Count all possible groups of size 2 or 3 that have sum as multiple of 3
  39. Tower of Hanoi
  40. Horner’s Method for Polynomial Evaluation
  41. Count trailing zeroes in factorial of a number
  42. Program for nth Catalan Number
  43. Generate one of 3 numbers according to given probabilities
  44. Find Excel column name from a given column number
  45. Find next greater number with same set of digits
  46. Count Possible Decodings of a given Digit Sequence
  47. Calculate the angle between hour hand and minute hand
  48. Count number of binary strings without consecutive 1?s
  49. Find the smallest number whose digits multiply to a given number n
  50. Draw a circle without floating point arithmetic
  51. How to check if an instance of 8 puzzle is solvable?
  52. Birthday Paradox
  53. Multiply two polynomials
  54. Count Distinct Non-Negative Integer Pairs (x, y) that Satisfy the Inequality x*x + y*y < n
  55. Count ways to reach the n’th stair
  56. Replace all ‘0’ with ‘5’ in an input Integer
  57. Program to add two polynomials
  58. Print first k digits of 1/n where n is a positive integer
  59. Given a number as a string, find the number of contiguous subsequences which recursively add up to 9
  60. Program for Bisection Method
  61. Program for Method Of False Position
  62. Program for Newton Raphson Method

Recent Articles on Mathematical Algorithms
Coding Practice on Mathematical Algorithms

 

Bit Algorithms:

  1. Find the element that appears once
  2. Detect opposite signs
  3. Set bits in all numbers from 1 to n
  4. Swap bits
  5. Add two numbers
  6. Smallest of three
  7. A Boolean Array Puzzle
  8. Set bits in an (big) array
  9. Next higher number with same number of set bits
  10. Optimization Technique (Modulus)
  11. Add 1 to a number
  12. Multiply with 3.5
  13. Turn off the rightmost set bit
  14. Check for Power of 4
  15. Absolute value (abs) without branching
  16. Modulus division by a power-of-2-number
  17. Minimum or Maximum of two integers
  18. Rotate bits
  19. Find the two non-repeating elements in an array
  20. Number Occurring Odd Number of Times
  21. Check for Integer Overflow
  22. Little and Big Endian
  23. Reverse Bits of a Number
  24. Count set bits in an integer
  25. Number of bits to be flipped to convert A to B
  26. Next Power of 2
  27. Check if a Number is Multiple of 3
  28. Find parity
  29. Multiply with 7
  30. Find whether a no is power of two
  31. Position of rightmost set bit
  32. Binary representation of a given number
  33. Swap all odd and even bits
  34. Find position of the only set bit
  35. Karatsuba algorithm for fast multiplication
  36. How to swap two numbers without using a temporary variable?
  37. Check if a number is multiple of 9 using bitwise operators
  38. Swap two nibbles in a byte
  39. How to turn off a particular bit in a number?
  40. Check if binary representation of a number is palindrome

Recent Articles on Bit Algorithms
Quiz on Bit Algorithms
Coding Practice on Bit Algorithms

 

Graph Algorithms:

Introduction, DFS and BFS:

  1. Graph and its representations
  2. Breadth First Traversal for a Graph
  3. Depth First Traversal for a Graph
  4. Applications of Depth First Search
  5. Detect Cycle in a Directed Graph
  6. Detect Cycle in a an Undirected Graph
  7. Detect cycle in an undirected graph
  8. Longest Path in a Directed Acyclic Graph
  9. Topological Sorting
  10. Check whether a given graph is Bipartite or not
  11. Snake and Ladder Problem
  12. Biconnected Components
  13. Check if a given graph is tree or not

Minimum Spanning Tree:

  1. Prim’s Minimum Spanning Tree (MST))
  2. Applications of Minimum Spanning Tree Problem
  3. Prim’s MST for Adjacency List Representation
  4. Kruskal’s Minimum Spanning Tree Algorithm
  5. Boruvka’s algorithm for Minimum Spanning Tree

Shortest Paths:

  1. Dijkstra’s shortest path algorithm
  2. Dijkstra’s Algorithm for Adjacency List Representation
  3. Bellman–Ford Algorithm
  4. Floyd Warshall Algorithm
  5. Johnson’s algorithm for All-pairs shortest paths
  6. Shortest Path in Directed Acyclic Graph
  7. Some interesting shortest path questions
  8. Shortest path with exactly k edges in a directed and weighted graph

Connectivity:

  1. Find if there is a path between two vertices in a directed graph
  2. Connectivity in a directed graph
  3. Articulation Points (or Cut Vertices) in a Graph
  4. Biconnected graph
  5. Bridges in a graph
  6. Eulerian path and circuit
  7. Fleury’s Algorithm for printing Eulerian Path or Circuit
  8. Strongly Connected Components
  9. Transitive closure of a graph
  10. Find the number of islands
  11. Count all possible walks from a source to a destination with exactly k edges
  12. Euler Circuit in a Directed Graph
  13. Biconnected Components
  14. Tarjan’s Algorithm to find Strongly Connected Components

Hard Problems:

  1. Graph Coloring (Introduction and Applications)
  2. Greedy Algorithm for Graph Coloring
  3. Travelling Salesman Problem (Naive and Dynamic Programming)
  4. Travelling Salesman Problem (Approximate using MST)
  5. Hamiltonian Cycle
  6. Vertex Cover Problem (Introduction and Approximate Algorithm)
  7. K Centers Problem (Greedy Approximate Algorithm)

Maximum Flow:

  1. Ford-Fulkerson Algorithm for Maximum Flow Problem
  2. Find maximum number of edge disjoint paths between two vertices
  3. Find minimum s-t cut in a flow network
  4. Maximum Bipartite Matching
  5. Channel Assignment Problem

Misc:

  1. Find if the strings can be chained to form a circle
  2. Given a sorted dictionary of an alien language, find order of characters
  3. Karger’s algorithm for Minimum Cut
  4. Karger’s algorithm for Minimum Cut | Set 2 (Analysis and Applications)
  5. Hopcroft–Karp Algorithm for Maximum Matching | Set 1 (Introduction)
  6. Hopcroft–Karp Algorithm for Maximum Matching | Set 2 (Implementation)
  7. Length of shortest chain to reach a target word
  8. Find same contacts in a list of contacts

All Algorithms on Graph
Quiz on Graph
Quiz on Graph Traversals
Quiz on Graph Shortest Paths
Quiz on Graph Minimum Spanning Tree
Coding Practice on Graph

 

Randomized Algorithms:

  1. Linearity of Expectation
  2. Expected Number of Trials until Success
  3. Randomized Algorithms | Set 0 (Mathematical Background)
  4. Randomized Algorithms | Set 1 (Introduction and Analysis)
  5. Randomized Algorithms | Set 2 (Classification and Applications)
  6. Randomized Algorithms | Set 3 (1/2 Approximate Median)
  7. Karger’s algorithm for Minimum Cut
  8. K’th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time)
  9. Reservoir Sampling
  10. Shuffle a given array
  11. Select a Random Node from a Singly Linked List

Recent Articles on Randomized Algorithms

 

Branch and Bound:

  1. Branch and Bound | Set 1 (Introduction with 0/1 Knapsack)
  2. Branch and Bound | Set 2 (Implementation of 0/1 Knapsack)
  3. Branch and Bound | Set 3 (8 puzzle Problem)
  4. Branch And Bound | Set 4 (Job Assignment Problem)
  5. Branch and Bound | Set 5 (N Queen Problem)
  6. Branch And Bound | Set 6 (Traveling Salesman Problem)

 

 

Recent Articles on Branch and Bound

 

Quizzes on Algorithms:

  1. Analysis of Algorithms
  2. Sorting
  3. Divide and Conquer
  4. Greedy Algorithms
  5. Dynamic Programming
  6. Backtracking
  7. Misc
  8. NP Complete
  9. Searching
  10. Analysis of Algorithms (Recurrences)
  11. Recursion
  12. Bit Algorithms
  13. Graph Traversals
  14. Graph Shortest Paths
  15. Graph Minimum Spanning Tree

 

Misc:

  1. Commonly Asked Algorithm Interview Questions | Set 1
  2. Given a matrix of ‘O’ and ‘X’, find the largest subsquare surrounded by ‘X’
  3. Nuts & Bolts Problem (Lock & Key problem)
  4. Flood fill Algorithm – how to implement fill() in paint?
  5. Given n appointments, find all conflicting appointments
  6. Check a given sentence for a given set of simple grammer rules
  7. Find Index of 0 to be replaced with 1 to get longest continuous sequence of 1s in a binary array
  8. How to check if two given sets are disjoint?
  9. Minimum Number of Platforms Required for a Railway/Bus Station
  10. Length of the largest subarray with contiguous elements | Set 1
  11. Length of the largest subarray with contiguous elements | Set 2
  12. Print all increasing sequences of length k from first n natural numbers
  13. Given two strings, find if first string is a subsequence of second
  14. Snake and Ladder Problem
  15. Write a function that returns 2 for input 1 and returns 1 for 2
  16. Connect n ropes with minimum cost
  17. Find the number of valid parentheses expressions of given length
  18. Longest Monotonically Increasing Subsequence Size (N log N): Simple implementation
  19. Generate all binary permutations such that there are more 1’s than 0’s at every point in all permutations
  20. Lexicographically minimum string rotation
  21. Construct an array from its pair-sum array
  22. Program to evaluate simple expressions
  23. Check if characters of a given string can be rearranged to form a palindrome
  24. Print all pairs of anagrams in a given array of strings

Please see Data Structures and Advanced Data Structures for Graph, Binary Tree, BST and Linked List based algorithms.

We will be adding more categories and posts to this page soon.

You can create a new Algorithm topic and discuss it with other geeks using our portal PRACTICE. See recently added problems on Algorithms on PRACTICE.