After few months of gap posting an algo. The current post is pending from long time, and many readers (e.g. here, here, here may be few more, I am not keeping track of all) are posting requests for explanation of the below problem.
Read More »Given an array of n positive integers. Write a program to find the sum of maximum sum subsequence of the given array such that the intgers in the subsequence are sorted in increasing order.
Read More »Given an unsorted array of nonnegative integers, find a continous subarray which adds to a given number.
Read More »Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n.
Read More »Given a sequence, find the length of the longest palindromic subsequence in it. For example, if the given sequence is “BBABCBCAB”, then the output should be 7 as “BABCBAB” is the longest palindromic subseuqnce in it.
Read More »scanf family functions support scanset specifiers which are represented by %[]. Inside scanset, we can specify single character or range of characters.
Read More »Hamiltonian Path in an undirected graph is a path that visits each vertex exactly once. A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian Path such that there is an edge (in graph) from the last vertex to the first vertex of the Hamiltonian Path.
Read More »Pattern Searching | Set 6 (Efficient Constructtion of Finite Automata)
Leave a comment | Filed under MiscIn the previous post, we discussed Finite Automata based pattern searching algorithm. The FA (Finite Automata) construction method discussed in previous post takes O((m^3)*NO_OF_CHARS) time. FA can be constructed in O(m*NO_OF_CHARS) time.
Read More »Given an undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent vertices of the graph are colored with same color. Here coloring of a graph means assignment of colors to all vertices.
Read More »The C99 standard allows variable sized arrays (see this). But, unlike the normal arrays, variable sized arrays cannot be initialized.
Read More »Given a number x and two positions (from right side) in binary representation of x, write a function that swaps n bits at given two positions and returns the result.
Read More »Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char txt[]) that prints all occurrences of pat[] in txt[]. You may assume that n > m.
Read More »The following is a description of the instance of this famous puzzle involving n=2 eggs and a building with k=36 floors.
Read More »Write a function to check whether two given strings are anagram of each other or not.
Read More »Given a Directed Graph and two vertices in it, check whether there is a path from the first given vertex to second.
Read More »Create a data structure twoStacks that represents two stacks. Implementation of twoStacks should use only one array, i.e., both stacks should use the same array for storing elements. Following functions must be supported by twoStacks.
Read More »Given a Binary Tree, find the maximum sum path from a leaf to root.
Read More »Given a directed graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least one cycle, else return false.
Read More »Given two Linked Lists, create union and intersection lists that contain union and intersection of the elements present in the given lists. Order of elments in output lists doesn’t matter.
Read More »You are given two balanced binary search trees e.g., AVL or Red Black Tree. Write a function that merges the two given balanced BSTs into a balanced binary search tree.
Read More »Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit.
Read More »Breadth First Traversal (or Search) for a graph is similar to Breadth First Traversal of a tree (See mthod 2 of this post).
Read More »Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack.
Read More »Write a function Add() that returns sum of two integers. The function should not use any of the arithmetic operators (+, ++, –, -, .. etc).
Read More »Depth First Traversal (or Search) for a graph is similar to Depth First Traversal of a tree. The only catch here is, unlike trees, graphs may contain cycles, so we may come to the same node again. To avoid processing a node more than once, we use a boolean visited array.
Read More »