The following algorithm takes an input array and the output array has duplicate elements removed. What is the Big-O of this algorithm?

void algo(int[] array), int len){
array = sort(array);
int[] newArray = new int[len];
int pos = 0;
for(int x=0;x int elem = array[x];
if(binarySearch(elem, newArray)==-1){
newArray[pos++] = elem;
}
}

a. O(n log n)
b. O(n^2)
c. O(n)
d. O(n!)


a. O(n log n)
The first array is traversed, and then the second array is traversed to find if the element from the first is in the second. Both are of length n so O(n) * O(n) = O(n^2).

Computer Science & Information Technology

You might also like to view...

Codes in a GUI system may be stored:

A) in a database table. B) as a database function. C) as a pull-down list. D) A and B above. E) A and C above.

Computer Science & Information Technology

Flickr uses the term cloud to describe a configurable gadget that you can use to display some of your Flickr photos as a collage on your blog's sidebar.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

COGNITIVE ASSESSMENT What act addresses the computing and other requirements of individuals in the workplace who have or may develop physical limitations?

A. Physical Limitations Act B. Computer Assistance Act C. Americans with Disabilities Act D. American Support Act

Computer Science & Information Technology

When using LinkedIn, this term is used to describe the people with which you want to communicate.

a. Connections b. Contacts c. Followers d. Associates

Computer Science & Information Technology