This is an in-place comparison-based sorting algorithm. Here, a sub-list is maintained which is always sorted. For example, the lower part of an array is maintained to be sorted. An element which is to be 'insert'ed in this sorted sub-list, has to find its appropriate place and then it has to be inserted there. Hence … Continue reading Insertion Sort
List of Standard Algorithms
Sorting Algorithms Bubble Sort Insertion Sort Selection Sort Merge Sort Quick Sort Heap Sort Shell Sort Bucket Sort Merge sort for linked list String Algorithms 1. Longest Common Substring 2. Longest Common Subsequence 3. Longest Palindrome Substring 4. Longest Palindrome Subsequence 5. All permutations of given string. (Handle duplicates) 6. All permutations of given … Continue reading List of Standard Algorithms
Bubble Sort
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. Example: First Pass: ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1. ( 1 5 … Continue reading Bubble Sort
Stack Data Structure – Introduction
A stack is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle. A stack is a limited access data structure - elements can be added and removed from the stack only at the top. push adds an item to the top of the stack, pop removes the item … Continue reading Stack Data Structure – Introduction
CISCO Interview Questions
Programming Questions 1. Write a code for bubble sort. 2. Find the nth bit of a number. 3. Given a 8 bit register with values ranging from 0-100. How much bits can be allocated for precision. 4. Difference between void main(); and void main(void) 5. List all Permutation of a String. Approach & code. 6. … Continue reading CISCO Interview Questions
Interview Experience @Amazon Bangalore, SDE-1
1st Round: Written 1) Given a singly linked list of characters, write a function that returns true if the given list is palindrome, else false. 2) Given an n x n matrix, where every row and column is sorted in increasing order. Given a number x, how to decide whether this x is in the … Continue reading Interview Experience @Amazon Bangalore, SDE-1
Dynamically Allocate/Deallocate 3D Array
1. Spiral printing of 2D matrix 2. Find Index of 0 to be replaced with 1 to get longest continuous sequence of 1s in a binary array 3. Vertical Sum in a given Binary Tree 4. Maximum element in an array which is first increasing and then decreasing 5. Serialize and Deserialize a Binary Tree … Continue reading
Given a string with some ‘?’ where ? can be 0 or 1. Print all possible strings by substituting ? with 0/1.
Given a string with some ‘?’ where ? can be 0 or 1. Print all possible strings by substituting ? with 0/1. Eg: I/p Amaz??n, o/p Amaz00n, Amaz10n, Amaz01n, Amaz11n Hint: At every position, we have 2 choice - we either place 0 or 1 at that position.
Connect nodes at same level
Write a function to connect all the adjacent nodes at the same level in a binary tree. Structure of the given Binary Tree node is like following. struct node{ int data; struct node* left; struct node* right; struct node* nextRight; } Initially, all the nextRight pointers point to garbage values. Your function should set these … Continue reading Connect nodes at same level