### Coding Interview - Useful Terms Cheatsheet

Big-O notation In simpler terms, its kind of a unit to measure how efficient an…

May 16, 2019

This is kind of preliminary technique of sorting. And, this is the first algorithm that a beginner learns.

In this algorithm, we iterate over the array, and compare two consecutive numbers. And, if first is larger, then swap it.
And, we keep on doing this till end.
So, the **Bubble** here is the biggest element which we keep on swapping.

- We start with two loops. Outer loop just goes from 0 to last-1 index.
- Inner loop always starts frmo 0-index, and goes till n-1 each time.
- On first iteration, we got the biggest element at the end of the array.
- Next iteration goes till n-1 elements. Since, we already sorted the largest element at the end.
- We keep on pushing the largets element from remaining n-1 array.

See the code here:

```
public void sort(int[] arr) {
int l = arr.length;
for (int i=0; i<l-1; i++) {
for (int j=0; j<(l-i-1); j++) {
if (arr[j] > arr[j+1]) {
//swap
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
}
}
}
```

- Its an in-place sorting algorithm
- Performance is usually worse than Insertion sort
- Applicable for small set of input only
- Its very simple algorithm

The algorithm runs on O(n^2) in worst/average case.

Big-O notation In simpler terms, its kind of a unit to measure how efficient an…

Introduction I will list some of the interesting usage of bitwise operators…

Problem Statement Determine whether an integer is a palindrome. An integer is a…

Counting sort runs on relatively smaller set of input. Counting sort calculates…

Problem Statement Given a string s, find the longest palindromic substring in s…

Problem Statement Determine if a 9x9 Sudoku board is valid. Only the filled…

Problem Statement You are given a string text of words that are placed among…

Problem Statement You are given a rows x cols matrix grid. Initially, you are…

Problem Statement Given a string s, return the maximum number of unique…

Problem The Leetcode file system keeps a log each time some user performs a…

Problem Statement Replace all spaces in a string with ‘%20’ (three characters…

Problem Implement an algorithm to determine if a string has all the characters…