educative.io

Insertion and Deletion of array at tail

If we implement array as the list in python and we maintain array.size(determines the size of array), array.tail(determines the end position where the element can be inserted), and array.head(determines the front position), we can perform insert and delete at the tail in the array in O(1) time without even using append() and pop() methods. Insertion and deletion at the front take O(n) time because of the movement of the elements of right in case of insertion and to left in case of deletion. Can you explain how are insertion and deletion at the tail take O(n) time?


Type your question above this line.

Course: https://www.educative.io/collection/5642554087309312/5634727314718720
Lesson: https://www.educative.io/collection/page/5642554087309312/5634727314718720/5696228427825152

Hi @Jibran_Mohammad,
When we delete or insert at the end/tail, then the list has to be searched from the start to the end and pass through each and every node so that the time complexity becomes O(n) in the linked lists. Hope you understand.
Thanks for reaching us.