What is the worst case time complexity of inserting n elements into an empty linked list, if the linked list needs to be maintained in sorted order ?

**(A)** Θ(n)

**(B)** Θ(n log n)

**(C)** Θ(n^{2})

**(D)** Θ(1)

**Answer:** **(C)** **Explanation:** This question is ambiguous: “needs to be maintained in sorted order”, there are two possible cases:

- Needs to be maintained in
*sorted order on each step (after each insertion)*.

When we are inserting*an element*in to empty linked list and to perform sorted order list of every element will take O(n^{2}).

Each Insertion into a sorted linked list will take θ(n) and hence the total cost for n operations is θ(n^{2}). - Needs to be maintained in
*sorted order on final step (only after all insertion)*.

When we are inserting all elements into an empty linked list and to perform a sorted list (using merge sort) after inserting all elements will take O(n log n) time.

Official answer by GATE is Θ(n^{2}).

Quiz of this Question

## Recommended Posts:

- GATE | GATE CS 2020 | Question 40
- GATE | Sudo GATE 2020 Mock III (24 January 2019) | Question 15
- GATE | Sudo GATE 2020 Mock III (24 January 2019) | Question 16
- GATE | Sudo GATE 2020 Mock III (24 January 2019) | Question 17
- GATE | Sudo GATE 2020 Mock III (24 January 2019) | Question 18
- GATE | Sudo GATE 2020 Mock III (24 January 2019) | Question 19
- GATE | Sudo GATE 2020 Mock III (24 January 2019) | Question 20
- GATE | Sudo GATE 2020 Mock III (24 January 2019) | Question 21
- GATE | Sudo GATE 2020 Mock III (24 January 2019) | Question 22
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 47
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 48
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 49
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 22
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 1
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 2
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 3
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 4
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 5
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 6
- GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 7