Aditya Chatterjee's Blog, page 144
November 18, 2021
Reverse bits of an Integer
In this article, we have explored an efficient algorithm to Reverse bits of an Integer. The challenge is to do this in-place without using auxiliary memory.
Table of contents:
Problem statementAlgorithm to reverse bitsPseudocodeCodeStep by Step ExplanationTime and Space ComplexityLet us get started with Reverse bits of an Integer.
Problem statementGiven a 32 bit unsigned integer N, we have to reverse bits of a the given 32 bits unsigned integer
**Ex: **
lets N = 255 (0b 0000000000000000...
Reverse Integer
In this article, we will explore an efficient algorithm to reverse a 32 bit Integer. This involve edge cases where the reverse integer is out of bounds.
Table of contents:
Problem StatementAlgorithm to reverse a NumberPseudocodeCodeExplanationTime and Space ComplexityLet us get started with reversing a 32 bit Integer.
Problem StatementGiven a 32 bit number we have to reverse digit of that 32 bit integer and print reversed 32 bit number.
Example:
Input: 34924
Output: 42943
Input: -93432
...
GCD Sort of an Array
In this article, we have explored an insightful approach/ algorithm to sort an array by comparing the Greatest Common Divisor of two of the elements.
Reading time: 25 minutes | Coding time: 25 minutes
TABLE OF CONTENTSPre-requisitesProblem statement definitionIntuition (Arriving at the solution)OptimizationAlgorithmPsuedocodeImplementationJAVA codePython codeC++ codeTime-complexity analysisSpace-Complexity analysisPRE-REQUISITESEucledian AlgorithmGreatest Common DivisorFac...Search element in rotated sorted array
In this article, we have explored how to search an element in a Rotated Sorted Array efficiently in O(logN) time with constant space O(1).
Table of contents:
Understanding the problem statementEfficient SolutionTime and Space ComplexityPrerequisite: Binary Search, Linear Search
Understanding the problem statementAn array is a collection of items stored at contiguous memory locations. The idea is to store various or multiple items of the same type together. This makes it easier to calculate...
Publish a Rust Library as Crates
So! Let's go through the whole process of: Writing up some Rust code to get the current time, format it and display on the console, maybe add some kind of functionality to guess how much time there is between 2 dates and publish it as a Crates.
Table of contents:
ThoughtsCode time!Publishing on Crates.ioThinking time (no pun intended)So we want to make a little library that lets us print the current system time, maybe in several formats. Let's start with that much. Quick search through the...
Quick Sort on Linked List
In this article, we have explained how to implement Quick Sort on Linked List and if it is as efficient as Quick Sort on Array.
Table of contents:
Introduction to Linked ListIntroduction to Quick SortQuickSort on Linked ListQuickSort on Linked List vs ArrayTime and Space Complexity of Quick Sort on Linked ListConclusionPrerequisite: Quick Sort, Linked List
Before we begin discussing how to perform quicksort on linked lists, let's define what a linked list is and what quicksort is.
Introd...November 17, 2021
Bubble Sort on Linked List
In this article, we have presented the approach to implement Bubble Sort on Singly Linked List and Doubly Linked List along with implementations in C and C++.
Table of contents:
Introduction to Linked ListIntroduction to Bubble SortBubble Sort on Linked ListPrerequisite: Linked List, Bubble Sort
Introduction to Linked ListA linked list is a linear data structure, in which the elements are not stored at contiguous memory locations.It consists of nodes where each node contains a data field a...
Static Initialization Block in Java
We all must the idea of the Constructor in Java. But the difference is, the Static Initialization Block is a set of instructions that are run only once when the class is loaded into memory. On the other hand, constructors are run each time a new instance of a class is created. We will explore this later.
Static Initialization BlockTopics that we will cover here:
What is Static Initialization Block In Java?How can we create a static initialization block?Properties or Features of Static Initi...Anonymous Class in Java
We know that Java language mainly follows the OOPs concept (From Java 1.8, we get functional programming.). So there is no anonymous function in Java.
But we can create Anonymous objects by extending the concept of the inner class.
Topics that we will cover here:
What is Anonymous classes?How to create Anonymous class?Double Brace Initialization.When to use it?What is Anonymous classes?Java Anonymous inner class is an inner class without a name and for which only a sin...
Control Flow in Java

Java Compiler executes the code in accordance of the order of their appearance , the order followed is top to bottom, hence the code at top is executed prior to the code below it. However , Java provides users with certain statements that facilitate them to control the flow of their program. Such statements are called Control Flow Statements. They are quite crucial for the smooth functioning of any program and are one of the most important features of Java language.
There are prominently three t...