Relative Sort Array in Python

Arnab Chakraborty
Updated on 18-May-2020 05:54:15

798 Views

Suppose we have two arrays arr1 and arr2, the elements of arr2 are unique, and all elements in arr2 are also present in arr1. We have to sort the elements of arr1 in such a way that the relative ordering of items in arr1 are the same as in arr2. If there are some elements that are not present in arr2, they should be placed at the end of arr1 in ascending order. So if the arr1 is like [2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19], and arr2 is like [2, 1, 4, 3, 9, 6], ... Read More

Difference Between Sums of Odd Position and Even Position Nodes of a Binary Tree in Java

Mahesh Parahar
Updated on 16-May-2020 14:54:17

247 Views

Problem StatementWith a given binary tree, write a program to find the difference between sum of nodes at odd position and even position. Assume root at level 0, odd position, left/right child of root at level 2, left child at odd position and right child at even position and so on.Example    5    / \   2   6 / \ \ 1 4 8 / / \ 3 7 9 Sum of nodes at odd positions = ... Read More

Difference Between Sums of Odd Level and Even Level Nodes of a Binary Tree in Java

Mahesh Parahar
Updated on 16-May-2020 14:50:36

442 Views

Problem StatementWith a given binary tree, write a program to find the difference between sum of nodes at odd level and even level. Assume root at level 1, left/right child of root at level 2 and so on.Example        5       /   \       2     6      /  \     \     1     4    8    /    /  \   3    7    9 Sum of nodes at odd level = 5 + 1 + 4 + 8 = 18 Sum of ... Read More

Difference Between Sums of Odd and Even Digits

Mahesh Parahar
Updated on 16-May-2020 14:49:21

584 Views

Problem StatementWith a given long integer n, write a program to find the difference between sum of the odd digits and even digits to be 0 or not. Index starts from 0.Examplen = 1212112 Sum of odd position elements = 2 + 2 + 1 = 5 Sum of even position elements = 1 + 1 + 1 + 2 = 5 Difference = 5 - 5 = 0 Output = YesExample Live DemoFollowing is the program in Java to find the required output.class JavaTester {    public static int difference(int n){       return (n % ... Read More

Difference Between Sum of Squares and Square of Sum of First N Natural Numbers

Mahesh Parahar
Updated on 16-May-2020 14:45:24

1K+ Views

Problem StatementWith a given number n, write a program to find the difference between sum of the squares of and square of sum first n natural numbers.Examplen = 3 Squares of first three numbers = 3x3 + 2x2 + 1x1 = 9 + 4 + 1 = 14 Squares of sum of first three numbers = (3 + 2 + 1)x(3 + 2 + 1) = 6x6 = 36 Difference = 36 - 14 = 22Example Live DemoFollowing is the program in Java to find the required difference.public class JavaTester {    public static int difference(int n){   ... Read More

Difference Between Strong Entity and Weak Entity

Mahesh Parahar
Updated on 16-May-2020 14:36:04

15K+ Views

Strong EntityStrong Entity is independent to any other entity in the schema. A strong entity always have a primary key. In ER diagram, a strong entity is represented by rectangle. Relationship between two strong entities is represented by a diamond. A set of strong entities is known as strong entity set.Weak EntityWeak entity is dependent on strong entity and cannot exists without a corresponding strong. It has a foreign key which relates it to a strong entity. A weak entity is represented by double rectangle. Relationship between a strong entity and a weak entity is represented by double diamond. The ... Read More

Difference Between out and ref Keyword in C#

Mahesh Parahar
Updated on 16-May-2020 14:16:00

19K+ Views

out keywordout keyword is used to pass arguments to method as a reference type and is primary used when a method has to return multiple values. ref keyword is also used to pass arguments to method as reference type and is used when existing variable is to be modified in a method. Following is the valid usage of ref and out keywords in C#.Example Live Demousing System.IO; using System; public class Program {    public static void update(out int a){       a = 10;    }    public static void change(ref int d){       d = 11; ... Read More

Difference Between readonly and const Keyword in C#

Mahesh Parahar
Updated on 16-May-2020 14:14:55

12K+ Views

readonly keywordreadonly keyword is used to define a variable which can be assigned once after declaration either during declaration or in constructor. const keyword is used to define a constant to be used in the program. Following is the valid usage of a readonly and const keywords in C#.Example Live Demousing System.IO; using System; public class Program {    public const int VALUE = 10;    public readonly int value1;    Program(int value){       value1 = value;    }    public static void Main() {       Console.WriteLine(VALUE);       Program p1 = new Program(11); ... Read More

Difference Between Relational Algebra and Relational Calculus

Mahesh Parahar
Updated on 16-May-2020 14:13:49

20K+ Views

Relational AlgebraRelational algebra is a procedural query language, which takes instances of relations as input and yields instances of relations as output. It uses operators to perform queries. An operator can be either unary or binary. They accept relations as their input and yield relations as their output. Relational algebra is performed recursively on a relation and intermediate results are also considered relations.The fundamental operations of relational algebra are as follows -SelectProjectUnionSet differentCartesian productRenameRelational CalculusIn contrast to Relational Algebra, Relational Calculus is a non-procedural query language, that is, it tells what to do but never explains how to do it.Relational ... Read More

Differences Between Data Paths

Mahesh Parahar
Updated on 16-May-2020 11:35:42

1K+ Views

Data PathsCPU has two sections, data section and control section. Data section is also called data paths. Registers, ALU and interconnection bus collectively constitutes a data path. Data paths are of three types:Single CycleMultiple CyclePipelineFollowing are some of the important differences between Single Cycle, Multiple Cycle and Pipeline data paths.Sr. No.KeySingle CycleMultiple CyclePipeline1CycleSingle Cycle has one CPI (Clock Cycle Per Instruction).Multiple Cycle has variable CPIs.Pipeline has fixed no. of CPIs.2Instruction divisionIn single cycle, instruction is not divided per CPI.In multiple cycle, an instruction can be divided in arbitrary steps.In pipline, an instruction is divided one step per pipeline stage.3Instruction divisionIn ... Read More

Advertisements