Deap is defined as a data structure which has no element or key value at the root node. It is formed by implementing the following rules −There is no element at root node that indicates root node is empty.Left subtree of the deap shall indicate min heap.Right subtree of deap shall indicate max heap.Thus, correctness to the following statement can be provided mathematically by a deap structure −If the left sub tree and right sub tree of certain nodes are non-empty, and their corresponding nodes can be represented by ‘a’ and ‘b’ respectively, then −a.KeyValue
A min-max heap is defined as a complete binary tree containing alternating min (or even) and max (or odd) levels. Even levels are denoted as for example 0, 2, 4, etc, and odd levels are denoted as 1, 3, 5, etc.We consider in the next points that the root element is at the first level, i.e., 0.Example of Min-max heapFeatures of Min-max heapEach node in a min-max heap is associated with a data member (usually called key) whose value is implemented to calculate the order of the node in the min-max heap.The root element is the minimum element in the ... Read More
A double-ended priority queue(DEPQ) or interval heap features the following operations −isEmpty()This function performs to check if DEPQ is empty and returns true if empty.size()This function performs to return the total number of elements present in the DEPQ.getMin()This function performs to return the element having lowest priority.getMax()This function performs to return the element having maximum priority.put(z)This function performs to insert the element z in the DEPQ.removeMin()This function performs to remove an element with smallest priority and returns this element.removeMax()This function performs to remove an element with highest priority and returns this element.The operations isEmpty(), size(), getMin(), and getMax() consume O(1) ... Read More
An interval heap is same as an embedded min-max heap in which each node contains two elements. It is defined as a complete binary tree in whichThe left element is smaller than or equal to the right element.Both the elements define a interval which is closed.Interval represented by any node other than the root is a sub-interval of the parent node.Elements on the left hand side represent a min heap.Elements on the right hand side represent a max heap.Depending on the number of elements, two cases are permitted -Even number of elements: In this case, each node contains two elements ... Read More
Left-Child Right-Sibling Representation is a different representation of an n-ary tree where instead of maintaining a pointer to each and every child node, a node holds just two pointers, first a pointer to its first child, and the other pointer to its immediate next sibling. This new transformation not only eliminates the need of prior knowledge of the number of children a node has, but also restricts the number of pointers to a maximum of two, so making it so much simpler to code.At each node, link or connect children of same parent from left to right.Parent should be linked ... Read More
To create a sorted merged array of two unsorted arrays, at first, let us create two unsorted arrays−int[] arr1 = new int[] {50, 22, 15, 40, 65, 75}; int[] arr2 = new int[] {60, 45, 10, 20, 35, 56};Let us now create a new resultant array, that would have the merged array−Exampleint count1 = arr1.length; int count2 = arr2.length; int [] resArr = new int[count1 + count2]; Now, we will merge both the arrays in the resultant array resArr: while (i < arr1.length){ resArr[k] = arr1[i]; i++; k++; } while (j < arr2.length){ resArr[k] = arr2[j]; ... Read More
The BinaryOperator interface represents an operation upon two operands of the same type, producing a result of the same type as the operands.Following are the methods −Modifier and TypeMethod and DescriptionmaxBy(Comparator
The CaseFormat class is a utility class for converting between various ASCII case formats −Modifier and TypeMethod and DescriptionObjectclone()Overrides Cloneable.booleanequals(Object obj)Overrides equals.String.format(double number)Specialization of format.abstract StringBufferformat(double number, StringBuffer toAppendTo, FieldPosition pos)Specialization of format.Stringformat(long number)Specialization of format.abstract StringBufferformat(long number, StringBuffer toAppendTo, FieldPosition pos)Specialization of format.ExampleLet us now see an example to implement the CaseFormat class with java file GuavaTester.java −import com.google.common.base.CaseFormat; public class GuavaTester { public static void main(String args[]) { GuavaTester tester = new GuavaTester(); tester.testCaseFormat(); } private void testCaseFormat() { String data = "test_data"; ... Read More
NumberFormat helps you to format and parse numbers for any locale. It is the abstract base class for all number formats.Following are some of the methods of the NumberFormat class−Modifier and TypeMethod and DescriptionObjectclone()Overrides Cloneable.booleanequals(Object obj)Overrides equals.String.format(double number)Specialization of format.abstract StringBufferformat(double number, StringBuffer toAppendTo, FieldPosition pos)Specialization of format.Stringformat(long number)Specialization of format.abstract StringBufferformat(long number, StringBuffer toAppendTo, FieldPosition pos)Specialization of format.ExampleLet us now see an example to implement the NumberFormat class − Live Demoimport java.text.NumberFormat; import java.util.Locale; public class Demo { public static void main(String[] args) { NumberFormat n = NumberFormat.getCurrencyInstance(Locale.FRANCE); double points = 2.15; ... Read More
The Byte class wraps a value of primitive type byte in an object.Following are the fields for Byte class−static byte MAX_VALUE − This is constant holding the maximum value a byte can have, 27-1.static byte MIN_VALUE − This is constant holding the minimum value a byte can have, -27.static int SIZE − This is the number of bits used to represent a byte value in two's complement binary form.static Class TYPE − This is the Class instance representing the primitive type byte.ExampleLet us now see an example − Live Demoimport java.lang.*; public class Demo { public static void main(String[] args){ ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP