# Mandatory Algorithms for Coding Interview

Basic algorithms that you must know if you want to crack your coding interview. In case you are starting to prepare for coding practice then make sure you learn all of these important algorightms. Get the source code for basic algorithms in JavaScript here

## Binary Search in Sorted Array

**O(log(n) time O(1) space**

## Reverse Linked List

**O(n) time O(1) space**

## Merge sort

In Merge sort since I need 2 Aux arrays. And it requires more space to solve merge sorting problem. Therefore, I will prefer Linked List datastructure. Because, in linkedlist to store values, I do not need contigous memory slots. Hence optimizing memory usage.

**O(n log (n)) time O(1) space**

## Quick Sort

**O(n log (n)) time O( log (n) ) and wrost case O(n) space**

Quicksort is best fit for sorting Arrays since it is completely in-place sorting. No auxilary arrays are requried. So no need to store contigous memory slots on computer.

## Partition Logic

• All the element lesser than pivot are pushed to the left of the partition index (use swap)

## Tree Traversal

Whenever tree is Sparse use BFT

**O(n) time O(n) space**

## Depth-First Traversal (DFT)

**O(n) time O(n) space**

## Insert in Binary Search Tree (BST)

**O(Log(n)) time Space O(1)**

For 1 insert operation, avg case is O(lgn) and worst case is O(n) For n insert operations, avg case is O(nlgn) and worst case is O(n²)

## Remove Node from BST

**O(log n) time space O(1)**

## Search in BST

O(log(n)) time | O(1)

## Heap implementation

In the interview no one will ask you to implement heap. This excercise is for your coding skills imporvement. In the interview, you can use array instead of heap and explain the concept.

## Insert node in the Heap

**O(log(n) time O(1) space**

## Revove root node from the Heap

**O(log(n) time O(1) space**

## Reference

Thanks for reading my article till end. I hope you learned something special today. If you enjoyed this article then please share to your friends and if you have suggestions or thoughts to share with me then please write in the comment box.

💖 Say 👋 to me!
Rupesh Tiwari
Founder of Fullstack Master
Email: rupesh.tiwari.info@gmail.com
Website: RupeshTiwari.com

--

--

## More from Rupesh Tiwari Blogs

I am a Senior Software Architect, mentor & successful PluralSight Author, professionally I am an expert at Angular, Express, Node.JS, Object Oriented Design but with a particular focus on Service Oriented Architecture, DDD, MEAN stack and Asp.Net.

## Rupesh Kumar Tiwari

Pluralsight Author, Developer and Trainer. I help students and professionals to become Full Stack Software Developer in less than a Year.