Assignment
Assignment
1. Push all the zeros of a given array to the end of the array. In place only. Ex 1,2,0,4,0,0,8 become 1,2,4,8,0,0,0. 2. Given a 2D array, all rows and all columns sorted. Find an integer x from the 2D array. 3. Find the no which is most repeated in an array and its frequency in O(n) 4. Given N pair of parenthesis. Write an algorithm which would print out all possible permutations possible with those
parenthesis given that parenthesis are in correct order (i.e. every open parenthesis is matched with closed parenthesis) For .e.g. N =3 should give:
()()() (()()) ()(()) (())() ((()))
5. Given a tree, write algorithm to verify whether it is a BST or not? 6. Write a function f(n) which computes the number of scoring sequences that add up to score n. 7. Given an array, write a function to return the kth largest number in the array. Should do in O (n) time complexity. 8. How many comparisons are required to sort an array of length 5 if a straight selection sort is used and the array is
already sorted in the opposite order?
10. Write a function to make the largest number from the digits of a given number.
Example: Number: 32441 Output: 44321 function prototype: C/C++: int biggestNumber(int number) Java: int biggestNumber(int number) Note: Use minimum, constant space
11. Given an array A which has only 0's and 1's in sorted order; find the occurrence of first '1' in A.
Example: A [] = 00001111, returns 5.
12. Write a function which takes a string S and a pattern P and an integer i, and returns the ith occurrence of P in S.
Example: S = "abcabcefgabc", P = "abc", i =3, Returns 10 Source: http://www.careercup.com/page?pid=algorithm-interview-questions&n=2