Is bit shifting O(1) or O(n)?

Some instruction sets are limited to one bit shift per instruction. And some instruction sets allow you to specify any number of bits to shift in one instruction, which usually takes one clock cycle on modern processors (modern being an intentionally vague word). See dan04’s answer about a barrel shifter, a circuit that shifts more … Read more

Big-O of list slicing

Getting a slice is O(i_2 – i_1). This is because Python’s internal representation of a list is an array, so you can start at i_1 and iterate to i_2. For more information, see the Python Time Complexity wiki entry You can also look at the implementation in the CPython source if you want to.