## Check if Given Number is power of 2.

Objective: Given a number, write a program to find if number is power of two. Example: N = 5 Output: false. N = 8 Output: true (23) N = 512 Output: true (29) Approach:...

Objective: Given a number, write a program to find if number is power of two. Example: N = 5 Output: false. N = 8 Output: true (23) N = 512 Output: true (29) Approach:...

Objective: Given an array of integers, write a program to rotate the array in cyclic manner by one. Example: Int a [] = {1, 2, 3, 4, 5} Output: {2, 3, 4, 5, 1}...

What is Heap Sort?? Heap sort is comparison based sorting algorithm. Heap sort is considered as improved selection sort, it divides the input into sorted and unsorted region. The improvement from selection sort is...

Objective: Write a program to print first n numbers in Fibonacci series. Fibonacci number: First two Fibonacci numbers are defined as 0 and 1 and every number after the first two is the sum...

A rectangle is a quadrilateral with four right angles. Say rectangle is given with side’s length A and B Area of Rectangle = A * B Perimeter of rectangle = 2(A+B) Code: Run This Code Output: Area of Rectangle:...

Objective: Given an array of integers A[] which is sorted in two parts (both parts are individually sorted), find no of reverse pairs means no of (i, j) pairs where i belongs to the...

Objective: Given a String, write a java program to reverse the string using Stack Example: Input: “tutorial horizon” Output: “noziroh lairotut” Recommended: Please read Stack Data Structure before continue to read. Approach: Initialize a...

What is Stack?? Stack is an abstract data type (ADT) and very useful in programming. In computer science, a stack is an abstract data type that serves as a collection of elements. Majorly all the operations are done at only one...

Earlier we have seen what Dijkstra’s algorithm is and how it works. In this article we will see its implementation using adjacency list and Priority Queue. Prerequisites: Adjacency List Priority Queue Dijkstra’s Algorithm basics...

In this article we will discuss about what is bubble sort, why it is considered as one of the simplest sorting algorithm, what its complexity, how we can improve the bubble sort algorithm. What...

Objective: Given the base and height of a triangle, using math formula for calculating the area of triangle, write an java program to calculate the triangle area. Area of a Triangle: (Base * Height)/2...

Objective – Given a number, Write a program to get the sum of digits in a number till it become a single digit. Example: N = 999 -> 9+9+9 = 27-> 2+7 = 9...

Objective: Given a number n, write a program to calculate Log2n without using built-in function. Example: N = 32 Log232 = 5 N = 64 Log264 = 6 Approach: Initialize result = 0. Keep...

Objective: Given a number, write a program to check if the number is prime or not. Prime Number: A number is called a prime number when number is not divisible by 1 or by...

Objective: Given a number N, write a program to print first N prime numbers. What is Prime number:?? A prime number (or a prime) is a natural number greater than 1 that cannot be...