Skip to content

Latest commit

 

History

History
12 lines (11 loc) · 1 KB

07. time complexity.md

File metadata and controls

12 lines (11 loc) · 1 KB

Time Complexity

  1. List Slicing
    • List slicing with a single index, e.g., my_list[i]: O(1)
    • List slicing with a start and end index, e.g., my_list[i:j]: O(j - i)
    • List slicing with a step size, e.g., my_list[i:j:k]: O((j - i) / k)
  2. Dictionary Lookups
    • Dictionary lookups, i.e., searching for a key and retrieving the corresponding value, are typically O(1) on average. Python dictionaries use a hash table data structure for efficient key-value storage and retrieval.
    • In some cases, if there are hash collisions or other factors, the worst-case time complexity of a dictionary lookup could be O(n), but this is rare in practice.
  3. Set Operations
    • Set operations such as adding an element, removing an element, or checking for membership are generally O(1) on average. Sets in Python are implemented using a hash table, similar to dictionaries.
    • The time complexity for set operations remains constant on average, but there can be variations depending on factors like hash collisions.