Aditya Chatterjee's Blog, page 170

May 9, 2021

Different ways to initialize an array in C++

Arrays: A simple way is to represent the linear relationship between the elements represented using sequential memory locations. We have covered two types of arrays:

standard Array declaractionArray container in Standard Template Library (STL) in C++

Different ways to initialize an array in C++ are as follows:

Method 1: Garbage valueMethod 2: Specify valuesMethod 3: Specify value and sizeMethod 4: Only specify sizeMethod 5: memsetMethod 6: memcpyMethod 7: wmemsetMethod 8: memmoveMeth...
 •  0 comments  •  flag
Share on Twitter
Published on May 09, 2021 07:13

May 8, 2021

Variants of Stable Marriage Problem

In this article, we will take a look at the variants of stable marriage problem. We have already discussed the Stable Marriage problem and it's solution (Gale Shapley Algorithm) in detail in a seperate article. Here, we will be looking at certain parameters or conditions that are added to the existing problem to make it more generic and real world. This includes indifference and incomplete lists.

Gale and Shapley proved that for any instance of the Classical Stable Marriage problem, there exists...

 •  0 comments  •  flag
Share on Twitter
Published on May 08, 2021 17:11

Convert one string to another by changing all occurrence of a character to another

In this article, We will be solving Check if one string can be converted to another by changing all occurrence of a character to another character problem using the Union and Find algorithm. In this problem we are given two strings str1 and str2, our job is to check whether the string str1 can be converted to string str2 by converting all the occurrences of a character to another character.

For example:

Input: str = “wxxyww”; str1 = “xyyzxx”Output: YesExplanation: The mappings of the character...
 •  0 comments  •  flag
Share on Twitter
Published on May 08, 2021 16:55

Back Propagation (Intuitively)

Back Propagation is one of the most important topics of Neural Net Training. It is the process of tuning the weights of neural network and is based on the rate of error of previous epoch. If we tune the weights properly then we can ensure the low error rates.

Back propagation started to create a buzz after a paper by David Rumelhart, Geoffrey Hinton, and Ronald Williams was published in 1986. It is the short form of "back propagation of errors".This led to a revolution because the neural net pro...

 •  0 comments  •  flag
Share on Twitter
Published on May 08, 2021 16:48

3D Vectors in C++

3D Vectors in C++

We will explore 3D Vectors in C++ in depth.
Vector is used in C++ to store items in consecutive memory locations dynamically. We can resize the vector in between program execution.
Vector is part of C++ Standard template library (STL library).

1D vector contains multiple elements,
2D vector contains multiple 1D vectors as rows and
3D vector contains multiple 2D vectors.

Therefore, we can say that 3D vector is vector of vector of vector.

3D Vectors in C++

Initializing 3D Vector1. Normal Initialization:

Generally...

 •  0 comments  •  flag
Share on Twitter
Published on May 08, 2021 06:13

Maximum XOR of two numbers in an array using Trie

Given a list of numbers we need to identify a pair of numbers in the list such that the XOR of those numbers is the maximum possible over all the pairs. If there are M elements with each element of order N, then brute force approach will take O(M^2 logN) time while Trie solution will take O(M logN) time.

Introduction

Given an array A of N integers, we need to find A[i], A[j] such that A[i] XOR A[j] is the maximum over all i and j, where 1, 1 and i≠j.

Here, by XOR operation, x XOR y, we mean the ...

 •  0 comments  •  flag
Share on Twitter
Published on May 08, 2021 03:45

May 7, 2021

Find k-th smallest element using QuickSelect algorithm

Given an initial unsorted list of N elements, we want to quickly find the k-th smallest element. For example, for the list {7, 4, 1, 5, 6}, the first smallest is 1, second smallest is 4 and so on.

An easy approach is to sort the elements in O(N logN) and select the k-th element as our solution. But we do we really need to sort the entire list?
Quickselect is an approach where we use divide and conquer and find the k th smallest element in an average O(N) time.

Quickselect algorithm

Quickselect w...

 •  0 comments  •  flag
Share on Twitter
Published on May 07, 2021 17:26

May 6, 2021

Longest Alternating Subsequence

What is an alternating sequence?
A sequence a1, a2, a3,... an is called alternating if it follows any one of the conditions given below.

a1 a3 a2 ... an

What is a subsequence?
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

The Problem

Given an array, find the length of the longest alternating subsequence.

Example 1Input:5 10 7 22Output:4Explanation:5 7 Example 2Input:11 4 26...
 •  0 comments  •  flag
Share on Twitter
Published on May 06, 2021 14:17

Applications of Binary Tree

Binary Tree is one of the most used Tree Data Structure and is used in real life Software systems.

Following are the Applications of Binary Tree:

Binary Tree is used to as the basic data structure in Microsoft Excel and spreadsheets in usual.Binary Tree is used to implement indexing of Segmented Database.Splay Tree (Binary Tree variant) is used in implemented efficient cache is hardware and software systems.Binary Space Partition Trees are used in Computer Graphics, Back face Culling, Collis...
 •  0 comments  •  flag
Share on Twitter
Published on May 06, 2021 13:18

Programmatic TableView using Swift

Programmatic TableView using Swift

Hello everyone in this article we are going to see how to create a table view in swift code without using visual designer.

What is a table view

A tableview is also known as ListView takes an array of items as input and present it as a list to the user. User can perform actions like select,swipe to delete,add,delete rows etc.

Why programmatic UI

Apple provided Storyboard for UI Design which makes it easier for beginner to create simple user interface.But when it comes to customization storyboard ...

 •  0 comments  •  flag
Share on Twitter
Published on May 06, 2021 09:46