Comparison of advantages and disadvantages of data structure_linear table_sequential/chain storage

Storage allocation method:

        1. The sequential storage structure uses a continuous storage unit to store the data elements of the linear table at a time

        2. The singly linked list adopts a linked storage structure, and uses a set of arbitrary storage units to store the elements of the linear list

Time performance:

        1. Search: sequential storage structure O(1)

                        Singly linked list O(n)

        2. Insertion and deletion: The sequential storage structure needs to move half the elements of the table on average, and the time complexity is O(n)

                                   After singly linked list finds the pointer of a certain position, the time complexity of insertion and deletion is only O(1)

Space performance:

        1. The sequential storage structure needs to pre-allocate storage space, which is wasteful if divided into large ones, and easy to cause overflow if divided into small ones.

        2. The singly linked list does not need to allocate storage space, as long as there is free space, it can be temporarily allocated, and the number of elements is not limited


         In a word, the sequential storage structure of the linear table and the singly linked list structure have their own advantages and disadvantages. It is impossible to simply say which is better and which is not. It is necessary to comprehensively balance which data structure can better meet and achieve the requirements and performance according to the actual situation. .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325713137&siteId=291194637