Java Questions Q1: If the list in the accompanying figure was sorted using selec
ID: 3717018 • Letter: J
Question
Java Questions
Q1: If the list in the accompanying figure was sorted using selection sort, which two elements would be swapped first?
A. 5 and 16
B. 65 and 16
C. 5 and 45
D. 7 and 30
Q2: In a sequential search, how many key comparisons would have to be made on the list in the accompanying figure to find the number 5?
A. 4
B. 5
C. 7
D. 8
Q3: If the list in the accompanying figure was sorted, what would be the middle element?
A. 7
B. 16
C. 24
D. 45
Q4: On average in a sequential search, how many comparisons would have to be made to find an element in the list in the accompanying figure?
A. 2
B. 5
C. 6
D. 8
Q5: In a sequential search, how many key comparisons would have to be made on the list in the accompanying figure to find the number 24?
A. 1
B. 2
C. 3
D. 4
Q6: Why can’t a binary search be used on the list as it appears in the accompanying figure?
A. Because the list is too big
B. Because the list is not sorted
C. Because it is a list of integers
D. A binary search can be used on the list
0 1 2 3 4 5 6 7 8 9 List: 16 30 24 7 25 62 45 5 65 50Explanation / Answer
Q1.
In Selection sort, first of all the smallest number is searched and then it is swapped with the first element of the array.
Here in this case,
Smallest element =5
First element= 16
Answer : A
Q2.
In sequential search, elements are processed one by one from the beginning of the array.
Here it will start from element 16 and processed till element 5
So no. of comparisons till element 5 will be 8.
Answer : D
Q3.
Sorted array is 5,7,16,24,25,30,45,50,62,65
As middle element index=
Here middle index=(0+9)/2=4
So it will be 25
Q4.
Average no of comparisons will be (n+1)/2
Here n is the size of the array
Here (10+1)/2=5
Answer : B
Q5.
24 is at the 3rd position from starting, so it will take 3 comparisons.
Answer: c
Q6.
Binary search algorithm takes sorted array as input, so the answer is Option B.
Answer B
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.