How to Calculate Power using Recursion | Pow(x, n)

In this tutorial, I am going to discuss how to calculate power using recursion.

Problem statement – Write a code to implement function pow(x, n), which calculates x raised to the power n (i.e. x^n). In this problem, We don’t have to use in-built function Math.pow.

For example:

Example 1:

Input:   x = 2.00000,    n = 3
Output:  8

Example 2:

Input: x = 2.10000,     n = 3
Output: 9.26100

Example 3:

Input: x = 2.00000,   n = -2
Output: 0.25000

Segregate 0s and 1s in an Array – Java Code

How to Segregate 0s and 1s in an Array.

Given an array of 0s and 1s in a random order. We have to write a code to segregate 0s on the left side and 1s on the right side of the array.

Basically, we have to sort an array of 0s and 1s.

For example –

Input array   =  [0, 1, 0, 1, 0, 0, 1]
Output array = [0, 0, 0, 0, 1, 1, 1]

In an input array 0s and 1s are in an unsorted order. The output is the sorted order of 0s and 1s.