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 Complexity

Let us get started with Reverse bits of an Integer.

Problem statement

Given 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...

 •  0 comments  •  flag
Share on Twitter
Published on November 18, 2021 23:16

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 Complexity

Let us get started with reversing a 32 bit Integer.

Problem Statement

Given 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
...

 •  0 comments  •  flag
Share on Twitter
Published on November 18, 2021 11:04

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...
 •  0 comments  •  flag
Share on Twitter
Published on November 18, 2021 07:07

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 Complexity

Prerequisite: Binary Search, Linear Search

Understanding the problem statement

An 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...

 •  0 comments  •  flag
Share on Twitter
Published on November 18, 2021 02:49

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...

 •  0 comments  •  flag
Share on Twitter
Published on November 18, 2021 02:34

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 ListConclusion

Prerequisite: 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...
 •  0 comments  •  flag
Share on Twitter
Published on November 18, 2021 00:05

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 List

Prerequisite: Linked List, Bubble Sort

Introduction to Linked List

A 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...

 •  0 comments  •  flag
Share on Twitter
Published on November 17, 2021 22:59

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 Block

Topics 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...
 •  0 comments  •  flag
Share on Twitter
Published on November 17, 2021 05:10

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.

Anonymous 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...

 •  0 comments  •  flag
Share on Twitter
Published on November 17, 2021 04:44

Control Flow in Java

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...

 •  0 comments  •  flag
Share on Twitter
Published on November 17, 2021 03:55