0% found this document useful (0 votes)
16 views

Assignment1-Basic Thinking

This document provides a training program that includes four problems to solve: counting zeroes in an array, evaluating a polynomial, finding a duplicate number in an array, and merging two sorted arrays into one sorted array without extra space. The problems cover basic common sense, math, and data structures concepts.

Uploaded by

Venu D
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Assignment1-Basic Thinking

This document provides a training program that includes four problems to solve: counting zeroes in an array, evaluating a polynomial, finding a duplicate number in an array, and merging two sorted arrays into one sorted array without extra space. The problems cover basic common sense, math, and data structures concepts.

Uploaded by

Venu D
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Top-20 Training Program

(Basic Thinking)
Apply basic commonsense/math/data structures to solve the following
problems.

Problem1: Count Zeroes


Given an array that contains some number of contiguous zeroes at the start, followed by
some arbitrary integers other than zero. Write an efficient function that returns the
number of zeroes in the given array.
Function Prototype:
int countZeroes(int []a, int n)
Example
Input: 0 0 0 0 0 3 2 8 11 10 15 22
Output: 5

Problem2: Polynomial Evaluation


Given a real number x, and a sequence of real numbers c0, c1, …cn, Write an efficient
function to find out the value of following polynomial of degree ‘n’:
pn (x) = cn xn + c n-1 xn-1 + … + c2 x2 + c1 x + c0
Function Prototype:
double EvalPolynom(int[ ] coef, int x, int n)

Problem3: Find Any Duplicate Number


a) Given an array of N integers in which each element is between 1 and N-1, write an
efficient function to determine the any duplicated integer. You may destroy the array.
What are the time and space complexities of your solution?
Function Prototype:
int FindDuplicate(int[ ]a)

b) Write an efficient function to solve the above problem if the given array is read only.
What are the time and space complexities of your solution?

Problem4: Merge Arrays


Given an array of size M+N in which first M numbers are sorted in non-decreasing order
and last N slots are empty. Also given an another array of size N which is sorted in non-
decreasing order. Write an efficient function to merge these two arrays without using any
extra space so that the array of M+N size is sorted.
Function Prototype:
void Merge(int[ ] a1, int[ ] a2, int m, int n) // array a1 is of size m+n
Copyright © Algorithmica
www.algorithmica.co.in
Ph: +91-9246582537

You might also like