Monday, August 3, 2020

Closures in Javascript

closure is the combination of a function and the scope object in which it was created. Closures let you save state

An example

function ageRelaxation(a) {
  return function(b) {
    return a + b;
  };
}
var boy2 = ageRelaxation(2);
var girl5 = ageRelaxation(5); boy2(18); // This results 20 girl5(20); // This results 25

Friday, June 12, 2020

Raspberry Pi 4 Enable SSH without having Display/HDMI Monitor

When there is no HDMI monitor available for Raspberry Pi 4 and you want to enable SSH (as if it was not done before) Here are the steps to perform to enable SSH without a Monitor connected to Raspberry pi.

  • Switch off Power of Raspberry Pi
  • Remove the SD card from Raspberry Pi
  • Insert the SD card into SD card reader and connect to other computer. Check for that SD card mounts automatically.
  • Goto to the SD card boot folder from file explorer/manager. Or you can use command line
  • Create new file and save it as ssh without any extension, inside the boot folder. (Just an empty ssh file in boot folder)
  • Eject the SD card from computer and put it back to the Raspberry Pi.
  • Power on your Raspberry Pi board. On boot Raspberry Pi checks for the ssh file and ssh will be enabled.

Thats it, connect to the Raspberry pi board using the below command from other computer on network.

ssh username@192.xxx.xxx.101 (username@Raspberrypi ip address) 

Use any network scanner to find your pi IP address)



Wednesday, September 18, 2019

Time Complexities

Common Data Structure Operations

Data Structure Time Complexity Space Complexity
Average Worst Worst
Access Search Insertion Deletion Access Search Insertion Deletion
Array Θ(1) Θ(n) Θ(n) Θ(n) O(1) O(n) O(n) O(n) O(n)
Stack Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)
Queue Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)
Singly-Linked List Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)
Doubly-Linked List Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)
Skip List Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(n) O(n) O(n) O(n) O(n log(n))
Hash Table N/A Θ(1) Θ(1) Θ(1) N/A O(n) O(n) O(n) O(n)
Binary Search Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(n) O(n) O(n) O(n) O(n)
Cartesian Tree N/A Θ(log(n)) Θ(log(n)) Θ(log(n)) N/A O(n) O(n) O(n) O(n)
B-Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
Red-Black Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
Splay Tree N/A Θ(log(n)) Θ(log(n)) Θ(log(n)) N/A O(log(n)) O(log(n)) O(log(n)) O(n)
AVL Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
KD Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(n) O(n) O(n) O(n) O(n)

Array Sorting Algorithms

Algorithm Time Complexity Space Complexity
Best Average Worst Worst
Quicksort Ω(n log(n)) Θ(n log(n)) O(n^2) O(log(n))
Mergesort Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(n)
Timsort Ω(n) Θ(n log(n)) O(n log(n)) O(n)
Heapsort Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(1)
Bubble Sort Ω(n) Θ(n^2) O(n^2) O(1)
Insertion Sort Ω(n) Θ(n^2) O(n^2) O(1)
Selection Sort Ω(n^2) Θ(n^2) O(n^2) O(1)
Tree Sort Ω(n log(n)) Θ(n log(n)) O(n^2) O(n)
Shell Sort Ω(n log(n)) Θ(n(log(n))^2) O(n(log(n))^2) O(1)
Bucket Sort Ω(n+k) Θ(n+k) O(n^2) O(n)
Radix Sort Ω(nk) Θ(nk) O(nk) O(n+k)
Counting Sort Ω(n+k) Θ(n+k) O(n+k) O(k)
Cubesort Ω(n) Θ(n log(n)) O(n log(n)) O(n)