coding-interview|May 16, 2019|2 min read

Coding Interview - Useful Terms Cheatsheet

TL;DR

Big-O measures worst-case growth rate. O(1) < O(log n) < O(n) < O(n log n) < O(n^2). Always clarify time vs space, and know the difference between stable and unstable sort.

Coding Interview - Useful Terms Cheatsheet

Big-O notation

In simpler terms, its kind of a unit to measure how efficient an algorithm is, with respect to the size of input, often refered to as ‘n’. There are two kind of units in algorithms:

  1. Time Complexity It defines how much time an algorithm is taking w.r.t. ‘n’
  2. Space Complexity It defines much space an algorithm is taking w.r.t. ‘n’

In interviews, mostly people are interested in Time complexities, but you should be familiar with space complexitity as well.

For example, Bubble Sort’s time complexity is O(n^2) What it means, if the number of input is: 10. This algorithm requires an average of 10^2=100 operations or CPU cycles to finish working.

Where as, Merge Sort takes O(n log n). Which is clearly lesser than O(n^2). So, lesser the complixity, more efficient the algorithm, i.e. more quickly it can be finished.

Note: here log n means log (base 2) of n

Divide and Conquer Algorithms

These algorithms are very useful and recursive in nature. These algorithms break the given input set or given problem in smaller sets or smaller subproblems. Then, solve the subproblems recursively, and finally combine these solutions to have a final solution for original problem.

To be more precise:

Divide

Divide the problem into smaller sub-problems. Its like big problem is now converted into smaller problems. And it is relatively easy to solve a smaller problem rather than bigger problem.

Conquer

Conquer the subproblems by solving them recursively.

Combine

Combine the solution of smaller sub-problems which becomes solution to original bigger problem.

Merge sort, Quick sort are best example of this approach. Once you learn the basic concept behind this, rest of the problems become very easy for you.

Stable Sort

In sorting, the numbers with the same value appear in the output array in the same order as they do in the input array. For same value numbers/objects, the order among them will remain same.

Related Posts

What FAANG companies expect in their interview from candidates

What FAANG companies expect in their interview from candidates

Its every software engineer’s dream to work with the big FAANG companies…

Magical usage of Bitwise operators - Get optimized solutions for many arithmatic problems

Magical usage of Bitwise operators - Get optimized solutions for many arithmatic problems

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

How to prepare for your next Coding Interview

How to prepare for your next Coding Interview

Here are some tips while preparing for your coding interviews. 1. Do study or…

How to nail your Coding Interview

How to nail your Coding Interview

Here are some tips while giving your coding interviews. 1. Never try to jump to…

List of Sorting Algorithms

List of Sorting Algorithms

This topic is one of the most common studied. When somebody started preparation…

Coding Interview Cheatsheet

Coding Interview Cheatsheet

Latest Posts

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…