Find non repeating character string Develop an algorithm to print the first none repeating character in a string for example the first none repeating character in the string "baby" is "a" Algorithm A brute force method requires us to use two nested loops for character comparison. The moment we find a match we break the

Running time of nested loop Given the following pattern matching algorithm which decides whether there is an occurrence of a pattern of size (m) in a text of size (n). The algorithm compares the pattern in a given location in the text checking all characters from left to right. //Includes #include <iostream> //STD using namespace

Merge sort c++ string Given a character string in small letter case. Write a C++ function to sort the string using Merge Sort Algorithm. Merge sort c++ implementation Merge sort is a popular sorting algorithm that runs in O(nlogn). It uses divide and concur technique so it keeps dividing the input array into two halves

Problem Given a square two dimensional integer array of size (n). Both rows and columns are sorted in ascending order. Give an algorithm to search for a particular element in the array in O(Log(n)) time complexity. Assume the array has no duplicates. Solution This problem is a follow up from the previous post. Modified binary

Problem Given a square two dimensional integer array of size (n). Both rows and columns are sorted in ascending order. Write an efficient code to search for a particular element in the array. Assume the array has no duplicates. Solution A brute force solution is to loop through the entire array until we find the

Pairs with sum problem Given an array of integers A[N]. Find all pairs of integers in the array which sum to a given value (v) Solution Let us try to solve this problem using brute force approach Code for sum of pairs method Here is the code in Perl # Given value$v = 6; # Given

Array shuffle algorithm Given an array of 2n integers in the following format a1 a2 a3 ... an b1 b2 b3 ... bn. Rearrange the array as follows a1 b1 a2 b2 a3 b3 ... an bn taking into consideration the following restrictions: 1. Arrange the array in place i.e. do not use any additional

Problem Given an array of N integers. The array is expected to contain positive as well as negative numbers. Find the maximum contiguous subsequence sum (MCSS) of the array. For example the MCSS of {2, -4, 1, 2} is 3 which is the sum of the subsequence {1, 2}. A brute force approach requires 3

Maximum contiguous subsequence sum problem Given an array of N integers. The array is expected to contain positive as well as negative numbers. Find the maximum contiguous subsequence sum (MCSS) of the array. For example the MCSS of {2, -4, 1, 2} is 3 which is the sum of the subsequence {1, 2}. A brute

Fibonacci numbers problem Write a program to compute the Fibonacci sequence number of a given integer. Your algorithm must run in linear time ie O(N). What is the fibonacci sequence Definition: Fibonacci number of (N) is the sum of Fibonacci numbers of (N-1) and (N-2). In other words, the fibonacci numbers list formula: Fibonacci(N) =