Given with a binary tree containing nodes and the task is to find the product of all the nodes of a given binary tree.In a binary tree, there is a root node which is the master node of all the nodes in a tree. A node contains data part, left pointer which will further create left subdirectory and a right pointer which will help in creating right subdirectory. So to traverse the tree, we can take a temporary pointer that will associate with left pointer to traverse left subdirectory or right pointer to traverse the right sub directory.Input Output Nodes are-: 10, ... Read More
Given with a binary tree containing nodes and the task is to find the product of all the leaf nodes of a given binary tree.Leaf nodes are the end nodes which don’t have any children. In a tree, a node can act as a parent node or child node except the root node which can only be a parent node. So the nodes with right and left pointer as NULL are the leaf nodes.Input Output Leaf nodes are -: 23, 34, 25 Product-: 23*34*25 = 19550ApproachInput the node dataTraverse all the nodes starting from the root node and going to either left ... Read More
Given with the tree of nodes with data in a string format and the task is to find the product of the nodes at k-th level in a binary tree. Every node of a tree contains three things i.e. data part, left pointer for left subtree and right pointer for right subtree.Level of binary tree starts from number 0 and it can go till ‘n’ which can be any positive number. So, we are given with the level ‘k’ and program must calculate the product of the nodes at given ‘k’ level.In the binary tree, if let’s say we are ... Read More
Given with two players let’s say A and B both are trying to get a penalty for winning the match. Given with four integer variables a, b, c, d so the probability of A getting the penalty first is a / b and probability of B getting the penalty first is c / d.The one who scores the penalty first will win the match and as per the given problem statement program must find the probability of A winning the match.Input a = 10, b = 20, c = 30, d = 40Output probability is 0.5333Inputa = 1, b = 2, c ... Read More
Given with an array of size ’n’ and the task is to find the probability of the given element k if available in an array.Traverse the entire array till ‘n’ which is equals to the number of elements in an array and search for the given element or key ‘k’. If the element is present in an array than calculate its probability else print 0.Input arr[] = { 1, 2, 3, 4, 5, 6} K = 5Output probability of a key 5 in an array is :0.166Input arr[] = { 1, 2, 3, 4, 5, 6, 7 } K = 8Output probability of a ... Read More
Given with two different arrays and the task is to find the probability of the random pair chosen to be the maximum weighted pair.A Pair will contain one element from let’s say array1 and another element form another array let’s say array2. So the program must find the probability of the pair that will contain first element to be the maximum element of array 1 and second element to be the maximum element of array 2 hence forming the maximum weighted pair.Input arr1[] = { 2, 23 } arr2[] = { 10, 3, 8 }Output probability of maximum pair : 0.166667Explanation set of ... Read More
Function overloading is also known as method overloading. Function overloading is the feature provided by the concept of polymorphism which is widely used in object-oriented programming.To achieve function overloading, functions should satisfy these conditions −Return type of functions should be sameName of the functions should be sameParameters can be different in type but should be same in numberExampleint display(int a); int display(float a); // both the functions can be overloaded int display(int a); float display(float b); //both the functions can’t be overloaded as the return type of one function is different from anotherlet’s discuss the functions that can’t overloaded in ... Read More
In this article we will be discussing the working, syntax and examples of multimap::find() function in C++ STL.What is Multimap in C++ STL?Multimaps are the associative containers, which are similar to map containers. It also facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a multimap container there can be multiple elements associated with the same key. The data is internally always sorted with the help of its associated keys.What is multimap::find()?multimap::find( ) an inbuilt function in C++ STL, which is defined in header file. find() searches elements ... Read More
Often, we get data frames that are not of same size that means some of the rows or columns are missing in any of the data frames. Therefore, to merge these types of data frames we can merge them with all of their values and convert the missing values to zero if necessary. This can be done by using merge function and replacement of missing values NA to zeros should be done by using single square brackets.ExampleConsider the below data frames −> C1 df1 df1 C1 1 A 2 B 3 C 4 D 5 E 6 F 7 G ... Read More
In our daily life, often we want to know what will be date after some number of days. This is also required in professional life, especially in those professions where we work on projects and have tight deadlines. To find the date after a number a certain number of days we can just use plus sign after reading the date with as.Date.Example> as.Date("2001-01-01")+30 [1] "2001-01-31" > as.Date("2020-06-30")+30 [1] "2020-07-30" > as.Date("2020-06-30")+50 [1] "2020-08-19" > as.Date("2020-06-30")+100 [1] "2020-10-08" > as.Date("2020-06-30")+120 [1] "2020-10-28" > as.Date("2020-06-30")+15 [1] "2020-07-15" > as.Date("2020-06-30")+45 [1] "2020-08-14" > as.Date("2020-06-30")+40 [1] "2020-08-09" > as.Date("2020-12-25")+20 [1] "2021-01-14" > as.Date("2020-12-25")+300 [1] ... Read More