Question: java programming. 1. What is the order of each of the following tasks in the worst case? a. Computing the sum of the first n

java programming.

1. What is the order of each of the following tasks in the worst case?

a. Computing the sum of the first n even intgers by using a for loop

b. Displaying all n integers in an array

c. Displaying all n integers in a sorted linkedlist

d. Displaying all n names in a circular linkedlist

e. Displaying one array element

f. Displaying the last integer in a linkedlist

g. Searching an array of n integers for a particular value by using a binary search

h. Sorting an array of n integers into descending order by using a mergesort

i. Adding an item to a stack of n items

j. Adding an item to a queue of n items

.2. Consider a sequential search of n data items.

  1. If the data items are sorted into ascending order, how can you determine that your desired item is not in the data collection without always making n comparisons?

  1. What is the order of the sequential search algorithm when the desired item is not in the data collection? Do this for both sorted and unsorted data, and consider the best, average, and worst cases.

  1. Show that if the sequential search algorithm finds the desired item in the data collection, the algorithms order does not depend upon whether or not the data items are sorted.

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!