Aditya Chatterjee's Blog, page 206
May 31, 2020
Binary GCD Algorithm
The Binary GCD algorithm or Stein's algorithm, is an algorithm that calculates two non-negative integer's largest common divisor by using simpler arithmetic operations than the standard euclidean algorithm and it reinstates division by numerical shifts, comparisons, and subtraction operations.
Examples: Input: x = 12,y = 72
Output : 12
Input: x = 33, y = 34
Output: 1
Algorithm
The Binary GCD Algorithm for calculating GCD of two numbers x and y can be given as follows:
If both x and y ...
String Class (java.lang.String) in Java
The java.lang.String class in Java provides a lot of methods to work on string. By the help of these methods, we can perform operations on string such as trimming, concatenating, converting, comparing, replacing strings etc.
String is a sequence of characters, for e.g. “Hello” is a string of 5 characters. In java, string is an immutable object which means it is constant and can cannot be changed once it has been created.
JAVA String Class
There are two ways to create a String object:
By strin...
Auto Key Cipher
Autokey (Autoclave) Cipher is a Symmetric polyalphabetic (Polyceaser) substitution cipher. This algorithm is about changing plaintext letters based on secret key letters. Each letter of the message is shifted along some alphabet positions. The number of positions is equal to the place in the alphabet of the current key letter.
Note: Cipher text is also called as encrypted text(don't confuse). And we're assuming index starting from 0 not 1.
Example Test Cases
Case-1:
Input:
Enter the Single Key ...
Play Fair Cipher
Play Fair Cipher comes under a Substitution cipher's category and this cipher was the first practical digraph substitution cipher. In play fair cipher unlike traditional cipher, we encrypt a pair/digraph of alphabets (digraphs) instead of a single alphabet.
Sample Test Case:
Key: "harry"
Plain Text: "My Name is Ravi"
Encrypted Text: "SF KBLF MO YRUK"
Decrypted Text: "MY NAME IS RAVI"
Note:*
Assume above test case throughout the discussion/process.
Choose characters either be lowercase or up...
May 30, 2020
Finding the Largest Element in an Array

We are given an integer array of size N or we can say number of elements is equal to N. We have to find the largest/ maximum element in an array. The time complexity to solve this is linear O(N) and space compexity is O(1). Our efficient approach can be seen as the first step of insertion sort. In fact, this can be extended to find the k-th largest element which will take O(K * N) time and using this to sort the entire array will take O(N^2) time.If we have extra information, we can take its ad...
How is 'this' reference in Java used?
The 'this' keyword in Java is a reference (which means it manages some relation) to the current object where it is called (can be constructor,function etc). It helps to keep the control of scope to access variables or any other elements. this keyword is very powerful and widely used in complex Java application.
Usage of 'this'
Here is given the 6 usage of java this keyword.
this can be used to refer current class instance variable.
this can be used to invoke current class method.
this() can be...
Bernoulli Naive Bayes
Bernoulli Naive Bayes is a variant of Naive Bayes. So, let us first talk about Naive Bayes in brief. Naive Bayes is a classification algorithm of Machine Learning based on Bayes theorem which gives the likelihood of occurrence of the event. Naive Bayes classifier is a probabilistic classifier which means that given an input, it predicts the probability of the input being classified for all the classes. It is also called conditional probability.
Two important assumptions made for Naive Bayes Cla...
begin() and end() in Array C++ STL
In this article, we have explored begin() and end() functions in Array container of C++ STL in depth. We have covered the basic idea of iterators as well as both functions deal with iterators.
Array is a container whose size is fixed. Container is an object that holds same datatype.Array size cannot be allocated dynamically.
SYNTAX of array container:
array array_name;
This above code creates an empty array of object_type and its size equals to array_size. However, array can also be created wi...
May 28, 2020
How I mastered Machine Learning as a Fresher?
![]()
“Karma of humans is Artificial Intelligence”
Let's quickly run through the topics this post covers:
Introduction to my background so that you can understand how I started to understand ML on my own.
We'll commence with the question "why" because before diving deep into something, we must understand the essence of it.
Then we'll cover the essentials that one must know, to get an extensive insight into machine learning.
We then proceed to see "what" exactly is machine learning, and get rid of a...
Different ways of Initializing multimap in C++
Multimaps in C++ STL are similar to maps in C++. The only difference is that maps cannot contain duplicate keys, whereas multimaps can contain multiple similar keys. It is a container that holds key-value pairs (like maps), and allows multiple entries with the same key.
Syntax for multimap :
template , //multimap::key_compare
class Alloc = allocator > //multimap::allocator_tpe
> class multimap;
The different ways to initialize multimaps are:
Method 1: Inserting usin...


