Question

this java! a response as soon as possible would be appreciated. thanks again. please say a...

this java! a response as soon as possible would be appreciated. thanks again.

please say a brief statement as to why u chose that answer.

Indicate TRUE OR FALSE for each of the following statements concerning search and sort algorithms

1) Linear search is guranteed to locate 5 in the array [1, 3, 2, 6, 5, 9, 4 ]

2) Binary search is guranteed to locate 5 in the array [1, 3, 2, 6, 5, 9, 4 ]

3) Linear search is guranteed to locate 5 in the array [1, 2, 3, 4, 5, 6, 9]

4) Binary search is guranteed to locate 5 in the array [1, 2, 3, 4, 5, 6, 9]

5) The java standard library only contains searching and sorting algorithms that work for standard java types like int and string. Any new class types require new searching/sorting algorithms to be written

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

1) TRUE : Linear Search is the searching method for finding the element or value in the list given.It is also known as sequential search where the java program uses the method to search key element by sequentially searching for the number in the list.If the number is not found in first place the counter is increamented and the process goes untill the number has been found. Thus in the above given array 1,3,2,6,5,9,4 the counter is increamented untill the 5 is found.

2) False : Binary Search finds the key element by dividing the array into two and considering the value of mid number. At each step an algorithm finds the input key value with the mid element of the array,if key is found it returns the position ,else if the number is less than the key then it checks to the left of the mid number else if it is greater then checks to the right.

Hence in java the above given array [1, 3, 2, 6, 5, 9, 4 ], 5 is not guaranteed to be found as after dividing the given array 6 is the mid element , so if 5 is searched then according to binary search algorithm it is less than mid element adnd thus should fall to the left side ,but in this case it is located to the right side of mid element.

3)TRUE : As java c will check for the 5 in the given array ,it sequentially searches the whole array untillthe key element is found. Therefore in the arary [1,2,3,4,5,6,9] the 5 is guaranteed to be located at the position a[4].

4)TRUE :In this array [1,2,3,4,5,6,9] ,the 5 is guaranteed to be found. As the mid element here is 4 (i,e a[3] = a[6]/[2]. 5 is greater than 4 located to the right side of the mid element and thus can be found at the right side of the mid element 4.

5) FALSE : As java also supports other types like float for searching and sorting .java.util.Arrays.sort(float[ ]) is dfined in the library for sorting floating type numbers in an array.

Add a comment
Know the answer?
Add Answer to:
this java! a response as soon as possible would be appreciated. thanks again. please say a...
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
ADVERTISEMENT