Question

Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....

Please Use your keyboard (Don't use handwriting) Thank you..

I need new and unique answers, please. (Use your own words, don't copy and paste)

Discussion Topic: Assume that you are given an unsorted array that contains 100 items, and you have been asked to write/propose an efficient searching algorithm. Which algorithm would you choose and why? What are the possible trad-offs of the selected algorithm if the array size is increased (e.g., 9000 items)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I tried my level best to answer this. Is there any improvement required comment to the answer.

Ans:

if the array is unsorted then there is no option then to use linear search.If you want to do multiple search then you can first sort the items and then do binary search.

Choosing the linear search will have the time complexity of (O(n)).

linear search algorithm:

public static int search(int arr[], int x)

    int n = arr.length;

    for(int i = 0; i < n; i++)

        if(arr[i] == x)

            return i;

    return -1;

if the size of array is increased the time to search an element will increase.

Add a comment
Know the answer?
Add Answer to:
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT