Selection Sort

Selection sort is an in-place, comparison sorting algorithm. Like bubble sort it also divides the given array in two sub arrays sorted and unsorted, divided by an imaginary wall. Initially all the elements will be in the unsorted list. Each pass will pick the smallest element from the unsorted list and add it at the end […]

Optimized bubble sort algorithm

What is Bubble Sort. Write algorithm of mention the Time & Space complexity of the Algorithm. Also suggest improvements which will improve the best case running time of Algorithm to O(n). Solution: Bubble Sort is a sorting algorithm which compares two adjacent elements and swap them if they are not in the right order. To […]

Binary Search or Half-interval search

Binary search is a Divide & Conquer algorithm used to search for an element in the array. It requires the array to be sorted. If array is not sorted then the only way to search in the array is Linear search. Binary search divide the number of elements to be searched in two halves in […]

Linear Search in detail

Linear search or Sequential search is a method for finding a particular value in a linear list of values (Array or Linked List). It is done by checking each of its elements, one at a time in list, until the desired one is found or the list is exhausted. Problem definition (for array) Given an Array […]

Check if all leaf nodes are at the same level

Given a binary tree write a function to check if all leaf nodes of the tree are at the same level. For example, In all the below trees, the leaf nodes are at same level: But in the below tree the leaf nodes are not at the same level: A A A / \ / […]

Check if a Binary Tree is Complete Binary Tree

A Complete Binary Tree is a Binary Tree where each level is completely filled. For example, all the trees below are complete Binary trees Height=1 Height=2 Height=3 ——– ——– ——– A A A / \ / \ B C B C / \ / \ D E F G And the trees below are not […]

Printing something without modifying main

The below C++ code will print “Hello World”. #include <iostream> int main() { cout<<“Hello World”; } Without modifying main function, add code to print “Ritambhara” before “Hello World”. You cannot add/remove any statement to main function

Find the output of C++ Program

What will be the output of the below C++ program: // Template Function – Not taking class template <class T, int i> int myFun(){ T x = 10; i = 20; } int main(){ fun<int, 4>(); return 0; }