Aditya Chatterjee's Blog, page 150

October 26, 2021

Different Ways to find element in Vector in C++ STL

In this article, we have explained Different Ways to find element in Vector in C++ STL which includes using std::find(), std::find_if, std::distance, std::count and Linear Search.

Table of contents:

Introduction to Vector in C++ and STLHow do we find an element using STL?Approach 1: Return index of the element using std::find()Use std::find_if() with std::distance()Use std::count()Linear search

Let us get started with Different Ways to find element in Vector in C++ STL.

Introduction to Ve...
 •  0 comments  •  flag
Share on Twitter
Published on October 26, 2021 14:40

reCAPTCHA Verification (+ How to add it to HTML?)

In this article, we have explored the idea of reCAPTCHA Verification, how to setup a Google reCAPTCHA account and how to add reCAPTCHA to any HTML form.

Table of contents:

What is Google reCAPTCHA?How to set-up your Google reCAPTCHA account?How to get your Google reCAPTCHA Keys?How to integrate reCAPTCHA V3 into your HTML forms?

Let us get started with reCAPTCHA Verification.

What is Google reCAPTCHA?

Before explaining what reCAPTCHA is, you should understand what CAPTCHA is.

CAPTCHA stands...

 •  0 comments  •  flag
Share on Twitter
Published on October 26, 2021 02:00

Trie Data Structure in Rust

Let's go back into Data structures for a while. Enough theory, let's code something ourselves :D

Table of contents

What is a Trie?Initial ideas for implementationActual Implementation

To revise the operations in Trie Data Structure in general, go through this article. Following it, you may continue with this article where we implement Trie Data Structure in Rust Programming Language.

What is a Trie?

A Trie, also called a digital tree or a prefix tree is a data structure, resembling the Bina...

 •  0 comments  •  flag
Share on Twitter
Published on October 26, 2021 01:07

Recovering a Binary Search Tree that has two nodes swapped

In this article, we will be developing and implementing an algorithm that recovers a Binary Search Tree (BST) that had two of its nodes swapped accidentally.

Table of contents:

Examining the Problem StatementSolving the ProblemFind two swapped elements in a sorted arrayConclusion

To practice more Binary Tree problems, go through this list of Binary Tree Problems.
This is similar to Leetcode Problem 99. Recover Binary Search Tree. Let us get started with Recovering a Binary Search Tree that ...

 •  0 comments  •  flag
Share on Twitter
Published on October 26, 2021 00:49

ZigZag Conversion of String with N rows

In this article, we have solved the problem of ZigZag Conversion of String with N rows. We take a string and a number N (rows) as input and distribute the string in ZigZag fashion among N rows and print the final string.

Table of contentsIntroduction to Problem StatementMethod 1Method 2Time and Space ComplexityOverview

This is similar to Leetcode Problem 6. ZigZag Conversion. Let us get started with ZigZag Conversion of String with N rows.

Introduction to Problem Statement

In this article...

 •  0 comments  •  flag
Share on Twitter
Published on October 26, 2021 00:14

October 25, 2021

std::swap function in C++

In this article, we have explained the use of std::swap function in C++ with multiple C++ code examples covering primitive data types to User defined classes.

Table of contents:

What is Swapping?What is std::swap in C++?C++ Code Examples of std::swap

To understand different techniques to swap two variables (beyond the basic technique), go through this article. It is a must read.

What is Swapping?

Swapping refers to the exchange of two or more objects. In programming, data may be swapped betw...

 •  0 comments  •  flag
Share on Twitter
Published on October 25, 2021 23:59

October 24, 2021

Karger’s algorithm to find Minimum Cut

In this article, we will explore how the Karger's algorithm works to find the minimum cut in a graph and its C implementation. This is a randomized algorithm based on Graphs.

Table of contents:

What is the minimum cut?Karger's AlgorithmSuccess Probability and Time complexityCode Implementation of Karger's algorithm

Pre-requisite: Randomized algorithm, Minimum Cut

Let us get started with Karger’s algorithm to find Minimum Cut.

What is the minimum cut?

The minimum cut in a graph refers to t...

 •  0 comments  •  flag
Share on Twitter
Published on October 24, 2021 03:12

Maximum points on a line

In this article, we have explored an insightful approach/ algorithm to find the maximum number of points on a straight line. This problem finds many uses in computational geometry.

TABLE OF CONTENTSPROBLEM STATEMENT DEFINITIONSOLUTION ANALYSISMETHOD-1 NAIVE ALGORITHMApproachAlgorithmPseudocodeComplexityMETHOD-2 USING MAPSApproachAlgorithmPseudocodeComplexityCOMPARISON OF APPROACHESAPPLICATIONS

Pre-requisite: Computational Geometry

Let us get started with Maximum points on a...

 •  0 comments  •  flag
Share on Twitter
Published on October 24, 2021 03:07

October 23, 2021

Scope Resolution :: in C++

[image error]

In this article, we have explored the idea of Scope Resolution operator :: in C++ which is used widely in C++ implementations to access a class inside another class, in multiple inheritance and many more.

Table of contents:

Basics of Scope Resolution :: in C++Implementation of C++ example using scope resolutionDifferent ways to use Scope Resolution :: in C++To define a function outside a classTo access a class’s static variablesIn case of multiple InheritanceFor namespaceRefer to a clas...
 •  0 comments  •  flag
Share on Twitter
Published on October 23, 2021 13:32

Adjacency Matrices Explained: A Representation of Graphs

In this article, we have explained the idea of Adjacency Matrix which is good Graph Representation. We have presented it for different cases like Weighted, undirected graph along with implementation and comparison with Adjacency List.

Table of contents:Introduction to graph representationAdjacency Matrices explainedCase 1: Unweighted, undirected graphCase 2: Unweighted, directed graphCase 3: Weighted, undirected graphCase 4: Weighted and directed graphC++ ImplementationComparison: Adjac...
 •  0 comments  •  flag
Share on Twitter
Published on October 23, 2021 09:47