In this post, we will implement KMP Algorithm in C, C++ and Java programming language.
Write an efficient algorithm to implement strstr function in Java which returns the index of first occurrence of a string in another string.
Given a BST, write an efficient function to search a given key in it. The algorithm should return the parent node of the key and print if the key is left or right node of the parent node. If the key is not present in the BST, the algorithm should be able to determine that.
Given a device having left, right, top and bottom buttons and a OK button to enter a text from a virtual keypad having alphabets from A-Y arranged in a 5×5 grid as shown below. We need to find the shortest route in device to construct the given string if we start from the top-left position …
Given a M x N matrix where each cell have non-negative cost associated with it, count number of paths to reach last cell (M-1, N-1) of the matrix from its first cell (0, 0) such that path has given cost. We can only move one unit right or one unit down from any cell. i.e. …
Given a text, find all occurrences of a given pattern in it.
Given an array of integers, find out minimum and maximum element present using minimum comparisons.
Given an array, find peak element in it. A peak element is an element that is greater than its neighbors.
Given a sorted binary array, efficiently find the number of 1’s in it.
Given a nearly sorted array such that each of the N elements may be misplaced by no more than one position from the correct sorted order, efficiently search a given element in it. Report if the element is not present in the input array.
Given a sorted array of integers, find floor and ceil of a given number in it. The floor and ceil map the given number to the largest previous or the smallest following integer, respectively.
Given a sorted array of distinct non-negative integers, find smallest missing element in it.