Problem Write a C++ function that takes a character as input and returns true if the second significant bit of the binary representation of the character is set (i.e equals to 1) otherwise return false. Solution This is a bitwise operations problem. First you need to shift the character one digit to the right then
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. (1) Assuming (m) is much smaller
Problem You have the following function signature int Contains(char* s1, char* s2, int n1, int n2) where s1, s2 are two strings and n1, n2 are their respective lengths. The function should return 1 if the s1 contains s2 otherwise it returns 0. For example if s1 = abcdefg and s2 = acg then it
Problem Write a C++ function to check string for repeated characters. Algorithm Using brute force we can start with the first character then compare it to the rest of the characters. If we can find a match then the string does have repeated characters otherwise we move to the next character and so on. If
Problem Write a C++ function that takes two strings of the same length as input and return true if the strings are anagrams otherwise returns false. Two strings are anagrams if they are permutations of each other ignoring spaces and capitalization. For example “CAT” and “ACT” are anagrams. Assume the input strings have small letter
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
Given a sorted array of (n) integers that has been rotated an unknown number of times. Give a log(n) algorithm that finds an element in the array. Assume the array has no duplicates.
Maximum of two numbers without comparison Write a C++ function which takes two positive integers x and y as input then return x if x > y otherwise return y. Assume x is not equal to y. You are not allowed to use any comparison operator or any if statement. Solution: maximum of two numbers
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