Find the Intersection Point of Two Linked Lists in Java

Dev Prakash Sharma
Updated on 23-Feb-2021 18:42:34

635 Views

A Linked List is a linear data structure in which each node has two blocks such that one block contains the value or data of the node and the other block contains the address of the next field.Let us assume that we have a linked list such that each node contains a random pointer which is pointing to the other nodes in the list. The task is to find the node at which two linked lists intersect each other. If they don’t intersect, then return NULL or empty as output.For ExampleInput-1:Output:2Explanation: Since the given linked list intersects at the node with ... Read More

Find the Nth Ugly Number in Java

Dev Prakash Sharma
Updated on 23-Feb-2021 18:37:00

1K+ Views

A number whose prime factors are either 2, 3 or 5 is called an Ugly Number.  Some of the ugly numbers are: 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, etc.We have a number N and the task is to find the Nth Ugly number in the sequence of Ugly numbers.For Example:Input-1:N = 5Output:5Explanation:The 5th ugly number in the sequence of ugly numbers [1, 2, 3, 4, 5, 6, 8, 10, 12, 15] is 5.Input-2:N = 7Output:8Explanation:The 7th ugly number in the sequence of ugly numbers [1, 2, 3, 4, 5, 6, 8, 10, 12, 15] is 8.Approach ... Read More

Selection Sort in Go Lang

Dev Prakash Sharma
Updated on 23-Feb-2021 18:27:34

2K+ Views

Selection sort is a sorting algorithm that is used to sort the elements by repeatedly finding the minimum element and placing it at the first in the unsorted part of the array. After placing the minimum element in one end of the array, the array is then divided into two subparts which can be again sorted using the algorithm.For ExampleInputarr[ ] = {2, 9, 4, 3, 5, 1}Output1 2 3 4 5 9ExplanationAfter sorting the given array, it becomes 1, 2, 3, 4, 5, 9Algorithm:Take an array of integers as the input.Find the index of the minimum element by iterating ... Read More

Align Multiple Plots in a Grid Using gridspec Class in Matplotlib

Dev Prakash Sharma
Updated on 23-Feb-2021 18:22:08

975 Views

Aligning the multiple plots in a grid can be very messy and it can create multiple issues like higher width and height or minimal width to align all the plots. In order to align all the plots in a grid, we use GridSpec class.Let us suppose that we have a bar graph plot and we want to align the symmetry of the plot in this sample.First Import all the necessary libraries and plot some graphs in two grids. Then, we will plot a constant error bar and a symmetric and asymmetric error bar on the first grid. In the second ... Read More

Plotting Regression and Residual Plot in Matplotlib

Dev Prakash Sharma
Updated on 23-Feb-2021 18:14:13

2K+ Views

To establish a simple relationship between the observations of a given joint distribution of a variable, we can create the plot for the regression model using Seaborn.To fit the dataset using the regression model, we have to first import the necessary libraries in Python.We will create plots for each regression model, (a) Linear Regression, (b) Polynomial Regression, and (c) Logistic Regression.In this example, we will use the wine quality dataset which can be accessed from here, https://archive.ics.uci.edu/ml/datasets/wine+qualityExampleimport matplotlib.pyplot as plt import seaborn as sns from scipy.stats import pearsonr sns.set(style="dark", color_codes=True) #import the dataset wine_quality = pd.read_csv('winequality-red.csv', delimiter=';') #Plotting ... Read More

Construct Expression Tree in Data Structure

Dev Prakash Sharma
Updated on 23-Feb-2021 18:11:51

8K+ Views

Expression treesExpression trees are those in which the leaf nodes have the values to be operated, and internal nodes contain the operator on which the leaf node will be performed.Example4 + ((7 + 9) * 2) will have an expression tree as followsAlgorithm to Construct an Expression TreeLet T be the expression tree.If T is not NULL:   If T->data is an operand:      return T.data   A = solve(T.left)   B = solve(T.right)   --> Calculate operator for 'T.data' on A and B, and call recursively,       return calculate(A, B, T.data)How to construct an expression tree?To construct an Expression Tree for ... Read More

Daily Temperatures in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 15:26:08

450 Views

Let us suppose we have an array of positive temperatures which represent the temperatures T. The task is to calculate how many days are there for the next warmer temperature in the given list.For exampleInput-1: T = [ 73, 74, 75, 71, 69, 72, 76, 73]Output: [1, 1, 4, 2, 1 ,1 ,0 ,0]Explanation: In the given list of temperatures [73, 74, 75, 71, 69, 72, 76, 73],  the next greater temperature is at Day 1. Similarly, Day 6 is the warmest in all the temperatures, thus the output will be [ 1, 1, 4, 2, 1, 1, 0, 0].Approach to Solve this ... Read More

Capture Pick Event to Activate/Deactivate Line Plots in Matplotlib

Dev Prakash Sharma
Updated on 23-Feb-2021 14:52:11

538 Views

After enabling the pick event property of artists in Matplotlib, the task is to use the pick event to enable and disable the line plots for a given axis in a set of plots.In order to pick a specific line plot, we use Legend.We will use a Binary classification plot to create the ROC Curve. ROC curve or Receiver Operating Characteristics curve is used for diagnostics, weather prediction and other applications. It contains True Negative Rate (TPR) and False Positive Rate (FPR). Using ROC, we will create multiple plots of the curve.Let us Import the libraries first. Here ‘nbAgg’ is used ... Read More

Add Annotations in Matplotlib Plots

Dev Prakash Sharma
Updated on 23-Feb-2021 14:50:37

436 Views

To specify the details of a plot, we use annotations. To create annotations in Matplotlib Plots, we can use the ‘annotate’ method.Exampleimport matplotlib.pyplot as plt import numpy as np #Let us create a plot and use annotation at the point (5,3), x = np.arange(0,4*np.pi,0.1) plt.plot(np.sin(x), 'b-*') a = plt.annotate("(3,0)", xy=(3, 0), xycoords='data', xytext=(4.0,0.5), textcoords='data', arrowprops=dict(arrowstyle="->", color="green", lw=5, connectionstyle=("arc3,rad=0."))) plt.setp(a, size=25) #Display the plot plt.show()Output

Customize Spines of Matplotlib Figures

Dev Prakash Sharma
Updated on 23-Feb-2021 14:48:37

943 Views

When we plot a figure in Matplotlib, it creates four spines around the figure, top, left, bottom and right. Spines are nothing but a box surrounded with the pictorial representation of the grid which displays some ticks and tickable axes on left(y) and bottom(x).Let us see how to customize the spines in a given figure. We will create six figures to see and customize the spines for it.First import the required libraries for the workbook.import numpy as np import matplotlib.pyplot as pltLet us draw graph for sines, theta = np.linspace(0, 2*np.pi, 128) y = np.sin(theta) fig = plt.figure(figsize=(8, 6))Define the ... Read More

Advertisements