Design a time algorithm, Data Structure & Algorithms

Q. An, array, A comprises of n unique integers from the range x to y(x and y inclusive where n=y-x). Which means, there is only one member that is not in A. Design an O(n) time algorithm to find that number.       

 

Ans:

The algorithm to find the number that is not array A where n contains n

unique (n = x - y):

find(int A[],n,x,y)

{

int i,missing_num,S[n]; for(i=0, i

{if(S[i] == -999)

{

missing_num = i + x;

break;

}

}

}

Posted Date: 7/10/2012 3:39:56 AM | Location : United States







Related Discussions:- Design a time algorithm, Assignment Help, Ask Question on Design a time algorithm, Get Answer, Expert's Help, Design a time algorithm Discussions

Write discussion on Design a time algorithm
Your posts are moderated
Related Questions
The best algorithm to solve a given problem is one that requires less space in memory and takes less time to complete its execution. But in practice it is not always possible to


write an algorithm given each students name and grade points for six courses.find his grade point average and group students into the gpa groups 3.5

What are the different ways of representing a graph? The different ways of representing a graph is: Adjacency list representation: This representation of graph having of an

We have discussed already about three tree traversal methods in the earlier section on general tree. The similar three different ways to do the traversal -inorder , preorder, and p

Write steps for algorithm for In-order Traversal This process when implemented iteratively also needs a stack and a Boolean to prevent the execution from traversing any portion

In the array implementation of the lists, we will use the array to hold the entries and a separate counter to keep track of the number of positions are occupied. A structure will b

Best - Fit Method: - This method obtains the smallest free block whose  size is greater than or equal to get such a block by traversing the whole free list follows.

How sparse matrix stored in the memory of a computer?

Two-dimensional array is shown in memory in following two ways:  1.  Row major representation: To achieve this linear representation, the first row of the array is stored in th