Sorting a binary array (which has only 0 & 1)
Given an array which has only 0’s and 1’s. Write an algorithm which will sort this array. (i.e separate 0’s and 1’s by bringing 0’s before 1’s). Input Array: {0, 1, 1, 0, 0, 0, 0, 1, 1, 0} Output Array: {0, 0, 0, 0, 0, 0, 1, 1, 1, 1}
Shift elements in the array forward by k places
Given an array of m elements and an integer k ( total size of array >= m+k), . Write code to shift all the elements of array forward by k positions. For example: If k = 2 and the Input array is as given below, the the output array should be: The extra spaces will […]
Node with minimum value in a Binary Search Tree
Given a Binary Search Tree (BST), where will you find the node containing minimum value in the Tree? For example: If the tree is as given below Then answer is 1. Write a function that returns the least value in given BST.
Print all interleavings of two strings
Given two strings, write code to print all inter-leavings of these strings. For example: if the two strings are “AB” and “12”, then the output should be: AB12 A1B2 A12B 1AB2 1A2B 12AB Note that the order of characters in the individual strings are not changed in the output.
Check if a number is a palindrome
Given an integer, write code to check if it is a palindrome or not. For example: 24342 is a palindrome but 32767 is not a palindrome. The signature of the function may be as shown below: /** Function returns 1 is num is palindrome and returns 0 otherwise. */ int checkPalindrome(int num);
How many IP addresses are available in IPv6
IPv4 and IPv6 are the addressing schemes used to identify the sender and receiver machine(computer or other device) over the internet. Each host requires an IP address to communicate over the net. IPv4 is the current version of providing addresses (though IPv6 is there for quite some time now). But because of the growth of […]
Check if a Binary Tree is a Sum Tree or not
A Sum-Tree is a Binary tree, where each non-leaf node has a value equal to the sum of its children. For example: the below tree is a Sum-Tree. Write a function that checks whether a given tree is a Sum-Tree or not.
Reversing a doubly linked list
Given a doubly linked list. Write a function that accepts a pointer to the head of the list and reverse the list.
Inorder successor of node in a Binary Tree
Given a pointer to the node in a binary tree, write code to find its inorder successor. You may assume each node to also have a pointer to the parent node (along with pointer to right and left sub-trees). Hence, the structure of Node will be struct Node { int data; Node* lptr; // pointer […]
Difference between TCP & UDP Protocol
What is the difference between TCP & UDP protocols of TCP/IP protocol suite.