Comparable interface is inside which of the following Java package? ANS java.lang.*
Which of the following abstract methods is inside Comparable interface? ANS public int
compareTo(Object obj)
Comparator interface is inside which of the following Java package? ANS java.util.*
Which of the following abstract methods is inside Comparator interface? ANS public int compare(Object
o1, Object o2)
int compare(Object o1, Object o2)
This method compares o1 and o2, and it returns a positive integer if o1 is greater than o2, i.e. in
lexicographical order, o1 is after o2. ANS True
For the following segment of code, variable result will be a negative number.
String x1 = "CSE205";
String x2 = "CSE100";
int result = x1.compareTo(x2); ANS False
For the following segment of code, variable result will be a negative number.
String x1 = "CSE205";
String x2 = "ASU";
int result = x2.compareTo(x1); ANS True
32 teams qualified for the 2018 World Cup. If the names of the teams were arranged in sorted order (an array),
how many items in the array would binary search have to examine to find the location of a particular team in
the array, in the worst case? ANS At most 6
In 2019, there were 193 member states in the United Nations. If the names of these states were stored inside a
one dimensional array. About how many names would linear search examine to locate a particular name in the
array, in the worst case? ANS No more than 193