Question: Consider the following algorithm, ndOutside, for nding all the elements of an array A of n numbers that are smaller than a given value x

Consider the following algorithm, ndOutside, for nding all the elements of an array A of n numbers that are smaller than a given value x and larger than another given value y, returning the elements found using a queue data structure implemented using a singly-linked list.

Algorithm 3 ndOutside(A,x,y)

1: Q new queue, initially empty

2: for i 0 to n1 do

3: if A[i] < x and A[i] > y then

4: insert(Q,A[i])

5: return Q

...................................................

Give the tightest/best possible characterization, Big-Oh, Big-Theta, or Big-Omega, of the worst-case running time and space complexity of algorithm ndOutside as a function of n. Justify your answer. Assume the implementation of the insert operation on a queue data structure implemented using a singly-linked list takes time linear in the size of the queue and uses a constant amount of space.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!