To learn the basics of the Queue visit our previous post on implementing Queue using linked list. In case the Queue is implemented using Linked list Enqueue (insertion) is about inserting a new node at the end and Dequeue (removing an element) is about deleting the first node. But, for array, things are little different.

Given a Singly linked list. Write functions to insert at different positions in the list: At start of the linked list. At end of the linked list. After k nodes from the start of list. After k nodes from the end of linked list. Insert in a sorted linked list.

Stack is a collection of objects where objects are inserted and removed in the Last-In-First-Out order. Element inserted at the end will be deleted first. It is a limited access data structure which essentially allows two operations push and pop. Push: Inserting data at the top of stack. Pop: deleting data from the top of stack. The […]

A better implementation of Stack is usually using linked list unless you are sure of the number of elements in array. But if you are just starting with data structures and are not familiar with linked list, you can try implementing stack in an array. While using array to implement stack is easy, it has limitation that […]

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 […]

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 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 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 […]