Daily Hustle

Roli Agrawal
3 min readMar 16, 2022

I am starting to write this blog to track my progress of learning and documenting for future reference.

To be a better developer we should not only write code for sake of it but it should be easy to understand, scalable, reliable. For that, I will be summarizing the content of each chapter of the Clean Code Book.

Day 1 :

What I have learned today in brief: Naming conventions from Clean Code

  • The name should tell the intent
  • Use Searchable Names
  • Use Pronounceable Name
  • Don’t encode type in names Ex : phoneString, paymentInt
  • Avoid Prefixes to Names Ex: IshapeFactory
  • Don’t use the same name to mean two different things
  • Use Domain-Specific Name Ex: JobQueue, nameBuilder
  • Avoid Too Long Names

Day 2:

What I have learned today in brief: Heap Data Structure

a Heap is a special type of binary tree. A heap is a binary tree that meets the following criteria:

  • Is a complete binary tree;
  • The value of each node must be no greater than (or no less than) the value of its child nodes.

Classification of Heap

There are two kinds of heaps: Max Heap and Min Heap.

  • Max Heap: Each node in the Heap has a value no less than its child nodes. Therefore, the top element (root node) has the largest value in the Heap.
  • Min Heap: Each node in the Heap has a value no larger than its child nodes. Therefore, the top element (root node) has the smallest value in the Heap.

A Heap has the following properties:

  • Insertion of an element into the Heap has a time complexity of O(\log N)O(logN);
  • Deletion of an element from the Heap has a time complexity of O(\log N)O(logN);
  • The maximum/minimum value in the Heap can be obtained with O(1)O(1) time complexity.

First, we will cover Insertion in Max Heap and Min Heap:

Max Heap Insertion :

Suppose the Heap is a Max-Heap as:10/    \5      3/ \2   4The new element to be inserted is 15.Process:Step 1: Insert the new element at the end.10/    \5      3/ \    /2   4  15Step 2: Heapify the new element following bottom-upapproach.-> 15 is more than its parent 3, swap them.10/    \5      15/ \    /2   4  3-> 15 is again more than its parent 10, swap them.15/    \5      10/ \    /2   4  3Therefore, the final heap after insertion is:15/    \5      10/ \    /2   4  3

Min Heap Insertion

Suppose the Heap is a Min-Heap as:2/    \3      4/ \5   6The new element to be inserted is 1.Process:Step 1: Insert the new element at the end.2/    \3      4/ \.    /5   6.   1Step 2: Heapify the new element following bottom-upapproach.-> 1 is less than its parent 4, swap them.2/    \3      1/ \.    /5   6.   4-> 1 is again more than its parent 2, swap them.2/    \3      1/ \.    /5   6.   4Therefore, the final heap after insertion is:1/    \3      2/ \.    /5   6.   4

In case of any query please put ur comments. See you soon :)

--

--