PHP Code to Find Second Largest Number in Array

Write a PHP code to find second largest number in array. Given an unsorted array, we have to write a PHP program to find the second largest number in an array.

Apart from solving this problem. We have to focus on time complexity. As the time complexity of an algorithm is very important in terms of how efficient your algorithm is.

Find GCD of Two Numbers using Recursion – Java Code

How to find GCD of two numbers. In this tutorial, I am going to discuss multiple approaches to find GCD of two numbers using Recursion.

Given two input integers, we have to write a code to find GCD of two numbers using recursion.

For example:

Input  n1 : 36    n2 : 54

Output 18

Explanation :

The divisiors of 36 are 1, 2, 3, 4, 6, 9, 12, 18, 36  and the divisiors of 54 are 1,  2,  3,  6,  9,  18,  27,  54.

Common divisors are 1, 2, 3, 6, 9, 12 and 18.

The GCD (Greatest Common Divisior) for 36 and 54 is 18.

For this program, I assume you are familiar with the concept of recursion. If you don’t know about recursion then check my previous post on recursion vs iteration.