Programming Articles

Page 1186 of 2547

Given a sorted array of 0's and 1's, find the transition point of the array in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 779 Views

Given an array of sorted numbers containing only 0s and 1s, find the transition point. A transition point is the index of the first ‘1’ appearing in the array. For example, Input-1 −N = 6 arr[ ] = {0, 0, 0, 0, 1, 1}Output −4Explanation − Since in the given array containing 0’s and 1’s we can see that the element at the index ‘4’ is having the number ‘1’.Input-2 −N = 5 arr[ ] = {0, 0, 1, 1, 1}Output −2Explanation − In the given array containing 0’s and 1’s, we can see that the element at the index ...

Read More

Deleting a binary tree using the delete keyword in C++ program

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 3K+ Views

In this tutorial, we are going to learn how to delete a binary tree using the delete keyword.We are going to use a destructor member function to delete the binary. The destructor member function is invoked automatically when the object goes out of the scope or it is destroyed by calling delete.The destructor member function has the name as a class with tilde (~) before it.Let's see the steps to solve the problem.Write a class called Node.Write a constructor function that accepts data for the node.Write a destructor function.Delete the left node.Delete the right node.Print the current node data.Initialize the ...

Read More

Check if two strings are anagram of each other using C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 2K+ Views

Let’s Suppose we have given two strings ‘a’ and ‘b. We have to check that the given two strings are anagram of each other or not. Two Strings are said to be anagram of each other if one string contains the same character as another.For ExampleInput-1 −a= anagram b= gnaramaOutput −TrueExplanation − String ‘gnarama’ has the same character as String ‘anagram’ has. Hence we return True.Input-2 −a= programmer b= mprogretmrqpOutput −FalseExplanation − String ‘b’ has more characters than the string ‘a’ and thus we can say that the length of the string is different. Thus we return False.The approach used ...

Read More

How to check if a list element is greater than a certain value in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

If we have a list that contains numeric elements and we want to check whether the elements are greater than a certain value then as.numeric function can be used. The output of the function will be in 0/1 format where 0 represents FALSE and 1 represents TRUE. For example, if we have a list called LIST then to check whether elements in LIST are greater than 2 can be done as as.numeric(LIST>2).Example1List15)Output[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0Example2List22)Output[1] 1 1 1 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 1 0

Read More

How to truncate a numerical vector to a specified number of decimal places in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

The truncation means removing the number of decimal places but not rounding. For example, if we have a value 5.1742145 then truncating to one decimal place will be 5.1 and rounding will be 5.2. In R, we can do this by using trunc function as shown in the below examples.Examplex1

Read More

How to create a classification model using svm for multiple categories in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 445 Views

SVM is a supervised machine learning algorithm which can be used for both classification or regression challenges but mostly we use it for classification. The classification using svm can be done for two or more categories as well. In R, we can use simply use svm function of e1071 package.ExampleConsider the iris data −str(iris)Output'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 ...

Read More

How to find the table of ordered frequencies of vector elements in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 524 Views

We can create table of frequencies of a vector element by using table function and the ordering can be done by using sort function. If we want to order the frequencies in decreasing order then decreasing argument can be used. For example, if we have a vector x then the table of ordered frequencies can be created as sort(table(x)).Examplex1

Read More

How to remove duplicate rows and sort based on a numerical column an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 736 Views

If we have duplicate rows in an R data frame then we can remove them by using unique function with data frame object name. And if we want to order the data frame with duplicate rows based on a numerical column then firstly unique rows should be found then order function can be used for sorting as shown in the below examples.ExampleConsider the below data frame −x1

Read More

How to replace upper triangular matrix with lower triangular matrix and vice versa in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

The upper triangular matrix can be replaced with lower triangular matrix by transposing the whole matrix and extracting upper triangular matrix from it then storing it in the original matrix. For example, if we have a matrix M then upper triangular matrix of M can be replaced with lower triangular matrix by using the below code −M1[upper.tri(M1)]

Read More

How to divide row values of a numerical column based on categorical column values in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 471 Views

If we have a categorical column that has two or more categories and a numerical column then we might want to divide the one category numerical value from other category numerical value. This can be done by using divide sign / but we need to use the proper subset of the values.ExampleConsider the below data frame −x1

Read More
Showing 11851–11860 of 25,466 articles
Advertisements