Aditya Chatterjee's Blog, page 165

July 7, 2021

Struct vs Class in C++

C++ is a vast language and it houses many data types just for the ease of the end user. Struct and Class are two of them. In this article, we have covered the points of differences between them.

Table of Contents:

Recap (Structures and Classes)Difference between struct and class in C++Myths and Misconceptions about struct in C language and class in C++Recap : Structures

A structure is a user-defined data type which is used to group items of same or different data types into a single type. I...

 •  0 comments  •  flag
Share on Twitter
Published on July 07, 2021 23:31

June 29, 2021

Sidecar Design Pattern in System Design

In this article, we have explored Sidecar Design Pattern in System Design along with its advantages and disadvantages and a real System Design example using Sidecar Design Pattern.

Table of Content:

IntroductionIssues in traditional design patternsWhat is a SideCar design pattern?Shared VolumeShared NetworkAdvantages of SideCar DesignDisadvantages of SideCar DesignSystem Design ExampleIntroduction

Containers are rising in popularity as it helps package an application and developers can...

 •  0 comments  •  flag
Share on Twitter
Published on June 29, 2021 08:51

Types of views in Binary tree

In this article, we have explored the different types of views of the Binary Tree (like Left View) and discussed how to find them.

Binary tree: A tree whose elements have at most 2 children is called a binary tree. A Binary Tree node contains following parts- Data, Pointer to left child and Pointer to right child.

Different Types of Views in Binary Tree are :

Left ViewRight ViewTop ViewBottom View

Let us now discuss all of them one by one.

Left View of Binary Tree

Left view of a Binary Tree...

 •  0 comments  •  flag
Share on Twitter
Published on June 29, 2021 08:34

Time and Space Complexity of Bucket Sort

Time and Space Complexity of Bucket Sort

In this article, we have explained the Time and Space Complexity analysis of Bucket sort along with its algorithm, space complexity and time complexity for worst case, average case and best case.

Table of Contents

Introduction to Bucket SortAlgorithmTime complexity analysisWorst case time complexityAverage case time complexityBest case time complexitySpace complexityComparison with other sorting algorithms

In short,

Time complexity: O(n + k)Space Complexity: O(n + k)Worst case: O(n²)...
 •  0 comments  •  flag
Share on Twitter
Published on June 29, 2021 08:25

June 28, 2021

Array vs Linked List [Differences Explained]

This article explain the differences between Array and Linked List (Array vs Linked List) in depth along with key points that will help you in deciding which one to use for a specific problem.

Table of Contents:

Differences between Array and Linked ListsBasics of Array and Linked ListsWhen to use Array over Linked List?When to use Linked List over Array?Differences between Array and Linked Lists

The Differences between Array and Linked Lists are as follows:

Memory allocated for array is c...
 •  0 comments  •  flag
Share on Twitter
Published on June 28, 2021 02:34

June 25, 2021

Number of expressions that evaluate to value K

In this problem, we have to form expressions using + and - and find the number of expressions that evaluate to K. This can be solved efficiently using Dynamic Programming and is an extension of Count Subset Problem.

Table of Contents:

Problem StatementIntuition to solve itStepsBrute Force ApproachMemorizationUsing Dynamic ProgrammingExplanation of the logicFurthur optimization?Problem Statement

Problem Statement : Given a list of integers and another integer K, place + or - before eac...

 •  0 comments  •  flag
Share on Twitter
Published on June 25, 2021 07:09

June 24, 2021

Bit Array [Explained with example]

In this article, we have explained Bit Array which is a Data Structure used in various problems to represent combinatorial information in an array in a compressed way. We have presented a code example of Bit Array in Java as well.

Table of contents:

Basics of Bit ArrayPopulation or Hamming weightWhy bit array is used?Bit Array in JavaSparse vs Dense Bit arraysBasics of Bit Array

Bit Array is a data structures that compactly stores Boolean values or bits in the form of an array. The bits c...

 •  0 comments  •  flag
Share on Twitter
Published on June 24, 2021 23:37

Idea of zero copy [with example]

In this article, we have explained the idea of zero copy intuitively with code examples. This is an important idea to design efficient systems.

Table of contents:

Pre-requisitesProblem statementIdea of Zero CopyApplications of Zero CopyCodes & examplesSetup environment to run the codeTry itReferences

Learn via Audio:

Pre-requisites:

FILE handling in C, system call (GNU/Linux preferred), kernel space, user-space, context switches, sockets in networking

Problem statement:

It is usual to ...

 •  0 comments  •  flag
Share on Twitter
Published on June 24, 2021 08:27

June 23, 2021

Passing a vector to a function in C++

In this article, we have covered how to pass a vector to a function as function agrument in C++ with variants like 1D vector, 2D vector, 3D vector, global vector and global vector by value. We have also, covered how to return a vector from a function.

Table of contents:

Passing a 1D vector to the FunctionPassing a 2D Vector to the functionPassing a 3D vector to the FunctionPassing a global vector to the functionPassing a global vector by valueHow to return a Vector from a function?Passi...
 •  0 comments  •  flag
Share on Twitter
Published on June 23, 2021 09:02

June 20, 2021

Insert element at bottom of Stack [Explained]

In this article, we have explained how to insert an element at the bottom of Stack using standard stack operations like push and pop. We have covered two approaches: iterative and recursive.

Table of Contents:

Problem Statement / IntroductionNaive approachRecursive approachApplication of stack & adding elements at bottomProblem Statement / Introduction

Stack is a linear data structure. It follows LIFO (Last in First Out) order. It has two major operations push and pop:

Push: Adds an eleme...
 •  0 comments  •  flag
Share on Twitter
Published on June 20, 2021 23:10