Object.assign() in JavaScript

vineeth.mariserla
Updated on 20-Aug-2019 14:42:35

687 Views

Object.assign()This method is used to copy one or more source objects to a target object. It invokes getters and setters since it uses both 'get' on the source and 'Set' on the target. It returns the target object which has properties and values copied from the target object. This method does not throw on null or undefined source values.syntaxObject.assign(target, ...source objects);It takes source objects and a target object as parameters and push the source objects into the target object and display the target object.Example-1In the following example, the properties from the source objects  "obj1", "obj2", and "obj3" were pushed into ... Read More

Add One to Number Represented as Array of Digits in C

Arnab Chakraborty
Updated on 20-Aug-2019 14:25:16

327 Views

In this section we will see one interesting problem. Suppose one number is given. We have to increase this number by 1. This is extremely simple task. But here we will place the number as an array. each digit of that number is placed as an element of the array. If the number is 512, then it will be stored as {5, 1, 2}. And also we have to increase the number using recursive approach. Let us see the algorithm to get the clear idea.Algorithmincrement(arr, n, index) −Initially the default value of index is 0 begin    if index < ... Read More

C++ vs Java vs Python: A Comparative Overview

Arnab Chakraborty
Updated on 20-Aug-2019 14:22:45

419 Views

Here we will see some basic differences between C++, Java and the Python. At first we will see the C++ and Java differences, then the Java and Python differences.TopicC++JavaMemory ManagementIt uses pointers, structures, unions and referencesIt does not support pointers. It supports references. It also supports Threads, interfacesLibrariesLow level functional librariesWide range of library, with various functionalitiesMultiple InheritanceSupports multiple inheritance using normal classesSupports multiple inheritance with only interfaces (pure abstract classes)Operating OverloadingOperator overloading is supportedDoes not support operator overloadingProgram HandlingFunctions and variables can reside outside of the classesFunctions, variables can only be there inside classes or packagesPortabilityCode is dependent on ... Read More

Baum-Sweet Sequence in C Program

Arnab Chakraborty
Updated on 20-Aug-2019 14:00:18

195 Views

Here we will see the Baum Sweet Sequence. This sequence is one binary sequence. If a number n has an odd number of contiguous 0s, then nth bit will be 0, otherwise nth bit will be 1.We have a natural number n. Our task is to find the n-th term of Baum Sweet sequence. So we have to check whether it has any consecutive block of zeros of odd length.If the number is 4 then the term will be 1, because 4 is 100. So it has two (even) number of zeros.AlgorithmBaumSweetSeqTerm (G, s) −begin    define bit sequence seq ... Read More

Binary Search Using Pthread in C Program

Arnab Chakraborty
Updated on 20-Aug-2019 13:18:47

576 Views

We know that the binary search approach is one of the most suitable and effective sorting algorithm. This works on sorted sequence. The algorithm is simple, it simply finds the element from middle, then divide the list by two parts, and moves either towards the left sublist, or right sublist.We know the algorithm of it. Now we will see how to use binary search technique in multithreading environment. The number of threads depends on number of cores are present in the system. Let us see the code to get the idea.Example#include #define MAX 16 #define MAX_THREAD 4 using namespace ... Read More

Binary Representation of Next Greater Number with Same Number of 1's and 0's in C Program

Arnab Chakraborty
Updated on 20-Aug-2019 13:15:25

303 Views

Suppose we have one binary number, that is representation of a number n. We have to find binary representation of a number which is smallest but larger than n, and it also has same number of 0s and 1s. So if the number is 1011 (11 in decimal), then the output will be 1101 (13). This problem can be found using the next-permutation calculation. Let us see the algorithm to get the idea.AlgorithmnextBin(bin) −Begin    len := length of the bin    for i in range len-2, down to 1, do       if bin[i] is 0 and bin[i+1] ... Read More

BFS Using Vectors and Queue in C as per CLRS Algorithm

Arnab Chakraborty
Updated on 20-Aug-2019 13:10:19

368 Views

In CLRS book the BFS algorithm is described using vectors and queue. We have to implement that algorithm using C++ STL. Let us see the algorithm at first.AlgorithmBFS(G, s) −begin    for each vertex u in G.V - {s}, do       u.color := white       u.d := infinity       u.p := NIL    done    s.color := green    s.d := 0    s.p := NIL    Q := NULL    insert s into Q    while Q is not null, do       u = delete from Q       for ... Read More

Betrothed Numbers in C Program

Arnab Chakraborty
Updated on 20-Aug-2019 13:06:54

596 Views

Here we will see the Betrothed number. This is a pair of numbers, such that the sum of the proper divisors of one number is one more than the other number. We have to find these pairsFor an example, the pair is like (48, 75). So the divisors of 48 is {1, 2, 3, 4, 6, 8, 12, 16, 24} and sum is 76. Similarly, the divisors of 75 is {1, 3, 5, 15, 25} so sum is 49.AlgorithmBetrothedPairs (n) −begin    for num in range 1 to n, do       sum := 1       for ... Read More

Auxiliary Space with Recursive Functions in C Program

Arnab Chakraborty
Updated on 20-Aug-2019 13:00:00

415 Views

Here we will see how the auxiliary space is required for recursive function call. And how it is differing from the normal function call?Suppose we have one function like below −long fact(int n){    if(n == 0 || n == 1)       return 1;    return n * fact(n-1); }This function is recursive function. When we call it like fact(5), then it will store addresses inside the stack like below −fact(5) ---> fact(4) ---> fact(3) ---> fact(2) ---> fact(1)As the recursive functions are calling itself again and again, addresses are added into stack. So if the function is ... Read More

Area of the Biggest Possible Rhombus Inscribed in a Rectangle in C

Arnab Chakraborty
Updated on 20-Aug-2019 12:53:32

147 Views

Here we will see one problem, where one rectangle is given. We have to find the area of largest rhombus that can be inscribed in the rectangle. The diagram will be look like below −The length of the rectangle is ‘l’ and breadth is ‘b’ So the area of the rhombus is −Source Code#include #include using namespace std; float area(float l, float b) {    if (l < 0 || b < 0) //if the values are negative it is invalid       return -1;    float area = (l*b) /2;    return area; } int main() {    float l = 20.0, b = 7;    cout

Advertisements