Skip to main content

Big-Oh (O) Notation, and sorting in Javascript

Asymptotic notations are classified into three types:

  1. Worst case time complexity: It is a function defined as a result of a maximum number of steps taken on any instance of size n. It is usually expressed in Big O notation.

  2. Average case time complexity: It is a function defined as a result of the average number of steps taken on any instance of size n. It is usually expressed in Big theta notation.

  3. Best case time complexity: It is a function defined as a result of the minimum number of steps taken on any instance of size n. It is usually expressed in Big omega notation.

  4. Space complexity: It is a function defined as a result of additional memory space needed to carry out the algorithm. It is usually expressed in Big O notation.

  1. Big-Oh (O) notation
  2. Big Omega ( Ω ) notation
  3. Big Theta ( Θ ) notation

Default sort() in JavaScript uses insertion sort by V8 Engine of Chrome and Merge sort by Mozilla Firefox and Safari.



 Heap Sort is regarded as an efficient algorithm, with average time complexity of θ(n log(n)).

Heap Sorting algorithm



the solution is to use Quick sort for large dataset.


Popular posts from this blog

API layer in React with Axios

  Why You Need an API Layer  https://semaphoreci.com/blog/api-layer-react 3. Easily handle request cancellation Thanks to the centralized nature of the API layer, you can effortlessly add custom features like cancellation to all API request definitions. Your frontend application performs API calls asynchronously. This means that when calling the same API twice in a short amount of time, the response to the first request may arrive after the response to the second one. Because of this, your application may render inconsistent data. A popular approach to deal with this problem is the debounce technique. The idea behind debounce is to wait a certain amount of time before executing the same operation twice. Implementing this and finding the right debounce time value for each scenario, however, is not easy. For this reason, you should consider API request cancellation. With request cancellation, the new API request simply cancels the previous one of the same type. API request cancellation i

setup prettier / eslint for create-react-app typescript

1. npm i -D prettier  2. create .prettierrc.json { "trailingComma": "all", "tabWidth": 2, "singleQuote": true, "jsxBracketSameLine": true,    "semi": false } 3. npm i -D eslint-config-prettier 4. in package.json, add this: "eslintConfig": { "extends": [ "react-app", "react-app/jest", "prettier" ] }, 5. install extension in VS Code Prettier extension