Objectives
- Understand how Objects in arrays work through the lens of big O.
- Explain why adding elements to the beginning of an array is costly.
- compare and contrast the runtimes for arrays and objects, but also they're built in methods.
Objects
<aside>
<img src="/icons/light-bulb_gray.svg" alt="/icons/light-bulb_gray.svg" width="40px" />
Note : we will use Typescript in this section to learn OOP using Java click here
</aside>
When to use objects
- when you don’t need order
- when you need fast access / insertion and removal
Why ? because when we talk about fast we mean Constant Time [ O( 1 ) ]
Big O of Object
- Insertion - O( 1 )
- Removal - O( 1 )
- Searching - O( n )
- Access - O( 1 )
When you don’t any ordering , objects are an excellent choice!
Big O of Object Methods
- Object.keys - O( n )
- Object.values - O( n )
- Object.entries - O( n )