Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 353 of 377

Irregular Arrays in Data Structure

Arnab Chakraborty
Arnab Chakraborty
Updated on 10-Aug-2020 1K+ Views

Here we will see the Irregular arrays. Before discussing the irregular arrays, we have to know what are regular arrays. The regular arrays are that kind of arrays, where the number of columns in each row is same. Or in other words, when each row is holding same number of elements, then that is regular arrays. The following representation is a regular array.From the definition of regular array, we can understand what are the irregular arrays. So in irregular arrays, each row may or may not contain same number of elements. This kind of irregular arrays can also be represented ...

Read More

Array of Arrays Representation in Data Structure

Arnab Chakraborty
Arnab Chakraborty
Updated on 10-Aug-2020 829 Views

In this section we will see another representation of multidimensional arrays. Here we will see the Array of Arrays representation. In this form, we have an array, that is holding the starting addresses of multiple arrays. The representation will be look like this.This is a two-dimensional array x of size [7 x 8]. Each row is represented as a single onedimensional array. The initial array is holding the addresses of these single arrays. They are array of addresses, so we can say that, it is an array of pointers. Each pointer is holding addresses of another arrays.create this kind of ...

Read More

Heterogeneous Arrays in Data Sturcture

Arnab Chakraborty
Arnab Chakraborty
Updated on 10-Aug-2020 2K+ Views

As we know the arrays are homogeneous by definition. So we have to put data of same type in an array. But if we want to store data of different type, then what will be the trick? In C like old languages, we can use unions to artificially coalesce the different types into one type. Then we can define an array on this new type. Here the kind of object that an array element actually contains is determined by a tag. Let us see one structure like this −struct Vehicle{    int id;    union {       Bus ...

Read More

Array Doubling in Data Structure

Arnab Chakraborty
Arnab Chakraborty
Updated on 10-Aug-2020 2K+ Views

Sometimes we create array using dynamic memory allocation. If the array is allocated using dynamic memory allocation technique, we can double the size of array by performing some operations.Suppose initial array size was 5.Array01234Element 1Element 2Element 3Element 4Element 5After array doubling, the size is −0123456789Element 1Element 2Element 3Element 4Element 5Element 6Element 7Element 8Element 9Element 10To double the size of array arr of size n, arr[0…n-1]. At first we have to create one new array of size say m. Then copy n elements from arr to the new array. Finally change the value of arr to point to the new array.To ...

Read More

Substitution Method in Data Structure

Arnab Chakraborty
Arnab Chakraborty
Updated on 10-Aug-2020 7K+ Views

Here we will see how to use substitution method to solve recurrence relations. We will take two examples to understand it in better way.Suppose we are using the binary search technique. In this technique, we check whether the element is present at the end or not. If that is present at middle, then the algorithm terminates, otherwise we take either the left and right subarray from the actual array again and again. So in each step the size of the array decreases by n / 2. Suppose the binary search algorithm takes T(n) amount of time to execute. The base ...

Read More

Counting Cache Misses in Data Structure

Arnab Chakraborty
Arnab Chakraborty
Updated on 10-Aug-2020 377 Views

In algorithm analysis we count the operations and steps. This is basically justified when computer takes more time to perform an operation than they took to fetch the data needed for that operation. Nowadays the cost of performing an operation is significantly lower than the cost of fetching data from memory.The run time of many algorithms is dominated by the number of memory references (number of cache misses) rather than by the number of operations. So, when we will try to desing some algorithms, we have to focus on reducing not only the number of operations but also the number ...

Read More

Operation Counts Method in Algorithm

Arnab Chakraborty
Arnab Chakraborty
Updated on 10-Aug-2020 4K+ Views

There are different methods to estimate the cost of some algorithm. One of them by using the operation count. We can estimate the time complexity of an algorithm by choosing one of different operations. These are like add, subtract etc. We have to check how many of these operations are done. The success of this method depends on our ability to identify the operations that contribute most of the time complexity.Suppose we have an array, of size n [0 to n - 1]. Our algorithm will find the index of largest element. We can estimate the cost by counting number ...

Read More

Find index i such that prefix of S1 and suffix of S2 till i form a palindrome when concatenated in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 24-Jul-2020 221 Views

ConceptWith respect of given two strings S1 and S2 of equal lengths, our task is to determine an index i such that S1[0…i] and S2[i+1…n-1] give a palindrome when concatenated together. Ithas been seen that if it is not possible to determine such an index then print -1.InputS1 = “pqrsu”, S2 = “wxyqp”Output1S1[0..1] = “pq”, S2[2..n-1] = “ypq”S1 + S2 = “pqyqp” indicates is a palindrome.InputS1 = “pqrst”, S2 = “qprqz”Output-1MethodAt first, we iterate from 0 to n (length of the string) and copy ith character from S1 to another string (assume it is S).After that we take another temporary ...

Read More

Shortest Distance from All Buildings in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Jul-2020 758 Views

Suppose we want to make a house on an empty land which reaches all buildings in the shortest amount of distance. We can only move four directions like up, down, left and right. We have a 2D grid of values 0, 1 or 2, where −0 represents an empty land which we can pass by freely.1 represents a building which we cannot pass through.2 represents an obstacle which we cannot pass through.So, if the input is like102010000000100then the output will be 7 as Given three buildings are present at (0, 0), (0, 4), (2, 2), and an obstacle is at ...

Read More

Find LCA in Binary Tree using RMQ in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Jul-2020 256 Views

ConceptThe article explains a method to solving the problem of finding the LCA of two nodes in a tree by reducing it to a RMQ problem.Examples Lowest Common Ancestor (LCA) of two nodes a and b in a rooted tree T is defined as the node located farthest from the root that has both a and b as descendants.For example, according to below diagram, LCA of node D and node I is node B.We can apply so many approaches to solve the LCA problem. These approaches differ with respect of their time and space complexities.Range Minimum Query (RMQ) is applied on ...

Read More
Showing 3521–3530 of 3,768 articles
« Prev 1 351 352 353 354 355 377 Next »
Advertisements