Server Side Programming Articles

Page 1909 of 2109

Rearrange array in alternating positive & negative items with O(1) extra space in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 02-Nov-2021 795 Views

We are given an integer type array containing both positive and negative numbers, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that there will be a positive number that will be surrounded by negative numbers. If there are more positive and negative numbers, then they will be arranged at the end of an array.Let us see various input output scenarios for this −Input − int arr[] = {-1, -2, -3, 1, 2, 3}Output − Array before Arrangement: -1 -2 -3 1 2 3 Rearrangement of an array in alternating positive & negative ...

Read More

How to create a base R plot without axes but keeping the frame of the plot?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 465 Views

To create a base R plot without axes but keeping the frame of the plot, we can set axes argument to FALSE and frame.plot argument to TRUE.For example, if we have a vector called V and we want to create a plot of V without axes but with the frame of the plot then, we can use the command given below −plot(V,axes=FALSE,frame.plot=TRUE)Check out the below example to understand how it works.ExampleConsider the following snippet −x

Read More

Rearrange an array to minimize sum of product of consecutive pair elements in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 02-Nov-2021 541 Views

We are given a positive integer type array, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that when we multiply an element with its alternative element and then add all the resultant elements then it should return the minimum sum.Let us see various input output scenarios for this −Input − int arr[] = {2, 5, 1, 7, 5, 0, 1, 0}Output − Rearrangement of an array to minimize sum i.e. 7 of product of consecutive pair elements is: 7 0 5 0 5 1 2 1Explanation − we are given an integer array ...

Read More

Rearrange an array such that every odd indexed element is greater than its previous in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 02-Nov-2021 276 Views

We are given a positive integer type array, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that all the elements present at an odd index should value greater than the element presents at an even index and print the result.Let us see various input output scenarios for this −Input − int arr[] = {2, 1, 5, 4, 3, 7, 8}Output − Array before Arrangement: 2 1 5 4 3 7 8 Rearrangement of an array such that every odd indexed element is greater than it previous is: 1 4 2 5 3 ...

Read More

How to find the variance of frequency data in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 590 Views

If we have frequency data then we first need to find the total data or complete data by repeating the values up to the frequency corresponding to each value after that we can apply var function on this complete data.For Example, if we have a data frame called df that contains two columns say X and Frequency then we can find the total data by using the command given below −Total_data

Read More

Rearrange an array such that arr[i] = i in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 02-Nov-2021 519 Views

We are given a positive integer type array, let's say, arr[] of any given size such that elements in an array should value greater than 0 but less than the size of an array. The task is to rearrange an array in such a manner that if arr[i] is ‘i’, if ‘i’ is present in an array else it will set the arr[i] element with the value -1 and print the final result.Let us see various input output scenarios for this −Input − int arr[] = {0, 8, 1, 5, 4, 3, 2, 9 }Output − Rearrangement of an array such that ...

Read More

How to find the autocorrelation values from ACF plot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 4K+ Views

The autocorrelation plot or ACF plot is a display of serial correlation in data that changes over time. The ACF plot can be easily created by using acf function.For example, if we have a vector called V then we can create its autocorrelation plot by using the command acf(V). If we want to extract autocorrelation values then we would need to save the plot values in an object by using the below command. This will not create the plot.Autocorrelation_x

Read More

How to find the row means for each matrix stored in an R list?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 426 Views

To find the row mean of all matrices stored in an R list, we can use sapply function along with rowMeans function.For example, if we have a list called LIST that contains some matrices then the row means for each matrix can be found by using the following command −sapply(LIST,rowMeans)Check out the below example to understand how it works.ExampleFollowing snippet creates the matrices −M1

Read More

How to find the median of frequency data in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 2K+ Views

If we have frequency data then we first need to find the total data or complete data by repeating the values up to the frequency corresponding to each value after that we can apply median function on this complete data.For Example, if we have a data frame called df that contains two columns say X and Frequency then we can find the total data by using the following command −Total_data

Read More

Rearrange an array such that 'arr[j]' becomes 'i' if 'arr[i]' is 'j' in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 02-Nov-2021 364 Views

We are given a positive integer type array, let's say, arr[] of any given size such that elements in an array should value greater than 0 but less than the size of an array. The task is to rearrange an array in such a manner that if arr[j] is ‘j’ then arr[j] becomes ‘i’ and print the final result.Let us see various input output scenarios for this −Input − int arr[] = {3, 4, 1, 2, 0}Outpu t− Array before Arrangement: 3 4 1 2 0 Rearrangement of an array such that arr[j] becomes i if arr[i] is j is: 4 ...

Read More
Showing 19081–19090 of 21,090 articles
Advertisements