You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Sort array of strings alphabetically using Arrays.sort()
🧠 Logic:
- Initialize a string array with various programming language names.
- Use `Arrays.sort()` to perform lexicographical (dictionary order) sorting.
- Print each string from the sorted array using enhanced for loop.
Signed-off-by: Somesh diwan <[email protected]>
6. What is the time complexity of the Arrays.sort() method used in the program?
35
-
The time complexity of Arrays.sort() for an array of strings is O(n log n), where n is the number of elements in the array. This is because it uses the dual-pivot Quicksort algorithm for non-primitive types.
36
+
The time complexity of Arrays.sort() for an array of strings is O(n log n), where n is the number of elements in the
37
+
array.
38
+
39
+
This is because it uses the dual-pivot Quicksort algorithm for non-primitive types.
36
40
37
41
10. How does the Arrays.sort() method compare strings internally? Discuss how it uses lexicographical order.
38
42
Arrays.sort() internally uses the compareTo() method of the String class.
39
-
The compareTo() method compares strings lexicographically by comparing their Unicode values character by character. If one string is a prefix of the other, the shorter string is considered smaller.
40
-
*/
43
+
The compareTo() method compares strings lexicographically by comparing their Unicode values character by character.
44
+
If one string is a prefix of the other, the shorter string is considered smaller.
0 commit comments