Adjacency Lists in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 13:45:56

4K+ Views

The graph is a non-linear data structures. This represents data using nodes, and their relations using edges. A graph G has two sections. The vertices, and edges. Vertices are represented using set V, and Edges are represented as set E. So the graph notation is G(V, E). Let us see one example to get the idea.In this graph, there are five vertices and five edges. The edges are directed. As an example, if we choose the edge connecting vertices B and D, the source vertex is B and destination is D. So we can move B to D but not ... Read More

Comparison of Sorting Methods in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 13:43:07

7K+ Views

Here we will see some sorting methods. There are 200+ sorting techniques. We will see few of them. Some sorting techniques are comparison based sort, some are non-comparison based sorting technique.Comparison Based Soring techniques are bubble sort, selection sort, insertion sort, Merge sort, quicksort, heap sort etc. These techniques are considered as comparison based sort because in these techniques the values are compared, and placed into sorted position in ifferent phases. Here we will see time complexity of these techniques.Analysis TypeBubble SortSelection SortInsertion SortMerge SortQuick SortHeap SortBest CaseO(n2)O(n2)O(n)O(log n)O(log n)O(logn)Average CaseO(n2)O(n2)O(n2)O(log n)O(log n)O(log n)Worst CaseO(n2)O(n2)O(n2)O(log n)O(n2)O(log n)some sorting algorithms are ... Read More

Comparison of Searching Methods in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 13:39:01

5K+ Views

In different cases, we perform different searching schemes to find some keys. In this section we will see what are the basic differences between two searching techniques, the sequential search and binary search.Sequential SearchBinary SearchTime complexity is O(n)Time complexity is O(log n)Finds the key present at first position in constant timeFinds the key present at center position in constant timeSequence of elements in the container does not affect.The elements must be sorted in the containerArrays and linked lists can be used to implement thisIt cannot be implemented directly into the linked list. We need to change the basic rules of ... Read More

Stack ADT in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 13:36:02

26K+ Views

The abstract datatype is special kind of datatype, whose behavior is defined by a set of values and set of operations. The keyword “Abstract” is used as we can use these datatypes, we can perform different operations. But how those operations are working that is totally hidden from the user. The ADT is made of with primitive datatypes, but operation logics are hidden.Here we will see the stack ADT. These are few operations or functions of the Stack ADT.isFull(), This is used to check whether stack is full or notisEmpry(), This is used to check whether stack is empty or ... Read More

Convex Hull Example in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 13:34:33

2K+ Views

Here we will see one example on convex hull. Suppose we have a set of points. We have to make a polygon by taking less amount of points, that will cover all given points. In this section we will see the Jarvis March algorithm to get the convex hull.Jarvis March algorithm is used to detect the corner points of a convex hull from a given set of data points.Starting from left most point of the data set, we keep the points in the convex hull by anti-clockwise rotation. From a current point, we can choose the next point by checking ... Read More

Optimal Binary Search Trees in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 13:03:53

2K+ Views

A set of integers are given in the sorted order and another array freq to frequency count. Our task is to create a binary search tree with those data to find minimum cost for all searches.An auxiliary array cost[n, n] is created to solve and store the solution of sub problems. Cost matrix will hold the data to solve the problem in bottom up manner.Input − The key values as node and the frequency.Keys = {10, 12, 20} Frequency = {34, 8, 50}Output − The minimum cost is 142.These are possible BST from the given values.For case 1, the cost ... Read More

Reverse Array Up to a Given Position in Python

Hafeezul Kareem
Updated on 27-Aug-2019 13:02:36

881 Views

In this tutorial, we will learn how to reverse an array upto a given position. Let's see the problem statement.We have an array of integers and a number n. Our goal is to reverse the elements of the array from the 0th index to (n-1)th index. For example, Input array = [1, 2, 3, 4, 5, 6, 7, 8, 9] n = 5 Output [5, 4, 3, 2, 1, 6, 7, 8, 9]Procedure to achieve the goal. Initialize an array and a number Loop until n / 2. Swap the (i)th index and (n-i-1)th elements.Print the array you will get the result.Example## initializing array and ... Read More

Negative Binomial Distribution in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 12:54:07

176 Views

The Negative Binomial Distribution is a random number distribution that will produce integers according to a negative binomial discrete distribution. This is known as Pascal’s distribution So the negative binomial distribution can be written as$$P\lgroup i\arrowvert k,p\rgroup=\lgroup \frac{k+i-1}{i}\rgroup p^{k}\lgroup 1-p\rgroup^{i}$$Example Live Demo#include #include using namespace std; int main(){    const int nrolls = 10000; // number of rolls    const int nstars = 100; // maximum number of stars to distribute    default_random_engine generator;    negative_binomial_distribution distribution(3,0.5);    int p[10]={};    for (int i=0; i

Remove Leading Zeros from an IP Address in Python

Hafeezul Kareem
Updated on 27-Aug-2019 12:52:36

596 Views

In this tutorial, we are going to write a program which removes leading zeros from the Ip address. Let's see what is exactly is. Let's say we have an IP address 255.001.040.001, then we have to convert it into 255.1.40.1. Follow the below procedure to write the program.Initialize the IP address.Split the IP address with. using the split functionConvert each part of the IP address to int which removes the leading zeros.Join all the parts by converting each piece to str.The result is our final output.Example## initializing IP address ip_address = "255.001.040.001" ## spliting using the split() functions parts = ip_address.split(".") ## ... Read More

Geometric Distribution in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 12:50:58

422 Views

The Geometric Distribution is a discrete probability distribution for n = 0, 1, 2, …. having the probability density function.$$P\lgroup n\rgroup=p\lgroup1-p\rgroup^{n}$$The distribution function is −$$D\lgroup n\rgroup=\displaystyle\sum\limits_{i=0}^n P\lgroup i \rgroup=1-q^{n+1}$$Example Live Demo#include #include using namespace std; int main(){    const int nrolls = 10000; // number of rolls    const int nstars = 100; // maximum number of stars to distribute    default_random_engine generator;    geometric_distribution distribution(0.3);    int p[10]={};    for (int i=0; i

Advertisements