|
|
|
|
|
by twawaaay
1453 days ago
|
|
Please, read the question. It stipulates that elements are selected at random. You select k integers at random. Some of them might be inserted faster into linked list, but when you average it over k integers you will still be slower because inserting into array will be faster, on average. Just think what happens if the integer is inserted at the END of the list (same probability...) You need to slowly iterate over entire linked list. While you quickly land at the result with a binary search on an array and then pay almost no cost inserting it there. If you think about it, ON AVERAGE, you have to search through half of the list (if you are linked list) or move half of the array (if you are an array). |
|