@@ -636,36 +636,36 @@ The result of the worst case time complexities are as follow:
636636
637637| Implementation | Insert | Lookup | Delete | Verify Deletion |
638638| -------------- | -------- | --------: | -------: | ----------------: |
639- | List | 0(1)avg | 0(n) | 0(n) | 0(n) |
640- | Set | 0(1)avg | 0(1)avg | 0(1)avg | 0(1)avg |
639+ | List | 0(n) | 0(n^2 ) | 0(n^2 ) | 0(n^2) |
640+ | Set | 0(n) | 0(n) | 0(n) | 0(n) |
641641
642642: Worst case time complexities for all operations and implementations studied in this experiment. {.responsive}
643643
644644## Insert
645- - Set remains at constant 0(1 ).
646- - List is also constant 0(1 ) as it is appending at the end.
647- - Even though both are at 0(1 ), List is comparatively a lot faster than set at pure appending hence it is faster than set.
645+ - Set remains at 0(n ).
646+ - List is also 0(n ) as it is appending at the end.
647+ - Even though both are at 0(n ), List is comparatively a lot faster than set at pure appending hence it is faster than set.
648648
649649## Lookup
650- - Set remains at constant 0(1 )
651- - List provide worst case time complexity of 0(n) when doubling the list size.
650+ - Set remains at 0(n )
651+ - List provide time complexity of 0(n^2 ) when doubling the list size.
652652- Set is faster constantly for the both small and large data sizes compared to list.
653653
654654## Delete
655- - Set remains at constant 0(1 ).
656- - List provide worst case time complexity of 0(n).
655+ - Set remains at 0(n ).
656+ - List provides time complexity of 0(n^2 ).
657657- For the smaller data both are almost similar for the deletion but as the data increases the list falls behind due to the shifting.
658658
659659## Verify Deletion
660- - Set remains at constant 0(1 ).
661- - List provide worst case time complexity of 0(n).
660+ - Set remains at 0(n ).
661+ - List provide time complexity of 0(n^2 ).
662662- Set is faster constantly for the both small and large data sizes compared to list.
663663
664664## Conclusion
665665
666666Set is demonstrably faster than list because it uses a hash table while lists use dynamic arrays. Other than append(insert)
667- which amortize 0(1 ) due to python geometrically growing capacity, List must look at every element or need to shift for other
668- operations which results in 0(n).
667+ which is 0(n ) due to python geometrically growing capacity, List must look at every element or need to shift for other
668+ operations which results in 0(n^2 ).
669669- If you need fast, random insert, delete and lookup of vertices or edges use ** Set** .
670670- If you truly just need to build up nodes or neighbors and then walk them sequentially use ** List** .
671671
0 commit comments