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 searchLet us get started with Different Ways to find element in Vector in C++ STL.
Introduction to Ve...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...
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 ImplementationTo 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...
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 arrayConclusionTo 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 ...
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 ComplexityOverviewThis is similar to Leetcode Problem 6. ZigZag Conversion. Let us get started with ZigZag Conversion of String with N rows.
Introduction to Problem StatementIn this article...
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::swapTo 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...
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 algorithmPre-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...
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 APPROACHESAPPLICATIONSPre-requisite: Computational Geometry
Let us get started with Maximum points on a...
October 23, 2021
Scope Resolution :: in C++
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...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...