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.
- 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?
- 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.
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started