22.3k views
5 votes
An array UnsortedInt consists of integers in random order. Another array SortedInt consists of a sorted list of integers.

Which of the given options is faster in SortedInt array than UnsortedInt arrays?

A-inserting a new element
B-searching for a new element
C-Computing the mean of elements

a)only A

b)only C

c)A, B, and C

d)only B

e)A and B only

1 Answer

6 votes

Answer:

B. searching for a new element.

Step-by-step explanation:

Searching for an element in a sorted array is denoted as:

O(log n)

It uses a binary search algorithm to seek for the element in the array. So it gives only a logarithmic increase as the search moves up the array.

To Insert a new element to an array, it tries to arrange the new element orderly is the array, checking from one element to another to see the position it fits.

It is denoted as O (n), and is slower than inserting in an unsorted array, which is denoted as O (1), because it does not care of the position of the new element.

The speed for computing the mean in both sorted and unsorted are the same.

User Ilya E
by
4.0k points