0
0
Data Structures Theoryknowledge~5 mins

Array operations and their complexities in Data Structures Theory - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the time complexity of accessing an element by index in an array?
Accessing an element by its index in an array takes constant time, O(1), because arrays allow direct access to any element using its position.
Click to reveal answer
intermediate
Why does inserting an element at the end of a dynamic array sometimes take more than O(1) time?
Inserting at the end is usually O(1), but when the array is full, it needs to resize (allocate a bigger array and copy elements), which takes O(n) time. This resizing happens occasionally, so average insertion is still O(1) amortized.
Click to reveal answer
beginner
What is the time complexity of inserting an element at the beginning of an array?
Inserting at the beginning requires shifting all existing elements one position to the right, so it takes O(n) time, where n is the number of elements in the array.
Click to reveal answer
beginner
Explain the time complexity of deleting an element from the middle of an array.
Deleting an element from the middle requires shifting all elements after it one position to the left to fill the gap. This shifting takes O(n) time, where n is the number of elements in the array.
Click to reveal answer
intermediate
What is the difference between worst-case and amortized time complexity in array operations?
Worst-case time complexity is the maximum time an operation can take (e.g., resizing an array during insertion). Amortized time averages the cost over many operations, showing that occasional expensive operations don't affect the average much.
Click to reveal answer
What is the time complexity of accessing the 5th element in an array?
AO(1)
BO(n)
CO(log n)
DO(n^2)
Which operation on an array typically requires O(n) time?
AAccessing an element by index
BAccessing the last element
CInserting at the end (when no resize needed)
DInserting at the beginning
Why does resizing a dynamic array take O(n) time?
ABecause it needs to copy all existing elements to a new larger array
BBecause it deletes all elements
CBecause it sorts the array
DBecause it accesses elements randomly
What is the amortized time complexity of inserting elements at the end of a dynamic array?
AO(n)
BO(1)
CO(n^2)
DO(log n)
Deleting an element from the middle of an array requires:
ANo shifting of elements
BShifting elements to the right
CShifting elements to the left
DSorting the array
Describe the time complexities of accessing, inserting, and deleting elements in an array.
Think about how many elements need to be moved for each operation.
You got /4 concepts.
    Explain why dynamic arrays sometimes need resizing and how it affects operation time.
    Consider what happens when you add more elements than the current space.
    You got /4 concepts.