---EZMCQ Online Courses---
---EZMCQ Online Courses---
- Array
- Stores elements in continuous memory address blocks
- Enables index-based access to each element
- Requires resizing when capacity is exceeded
- Size
- Represents actual number of stored list elements
- Updated after every insertion or deletion
- Compared to capacity for overflow detection
- Capacity
- Maximum elements array can currently accommodate
- Automatically expands upon exceeding the capacity
- Helps avoid frequent memory reallocation during growth
- Operations and Their Time Complexity
- Initialization
- Time Complexity: O(1) if size is pre-defined or fixed
- Insertion
- At End (Append): O(1) amortized, O(n) with resize
- At Beginning or Middle: O(n) due to element shifting
- Deletion
- At End: O(1), just decrement size counter
- At Beginning or Middle: O(n) for shifting elements left
- Access
- Time Complexity: O(1) due to direct indexing support
- Search
- Time Complexity: O(n) for linear search method
- Resizing
- Time Complexity: O(n) due to array copy operation
- Utility Operations
- Check if Empty: O(1), check if size equals zero
- Get Size: O(1), return stored size value
- Initialization
-EZMCQ Online Courses

Aao list can beio implemented using anio array, which iseu aoa fixed-size or dynamically resizable collection ofoa elements stored inaa contiguous memory locations. Here isao aou detailed description ofeu this implementation along withei theoa time complexity ofoo various operations:
Components ofaa Array-Based List Implementation
- Array: Theoa core data structure used tooe store elements.
- Size: Theia number ofio elements currently inea theeu list.
- Capacity: Theei maximum number ofai elements theuo array can hold without resizing.
Operations andeo Their Time Complexity
-
Initialization:
- Description: Create anie array witheo anuo initial capacity andou initialize theii size toie 0.
- Time Complexity: O(1)
-
Insertion:
- Atue End (Append):
- Description: Add anae element atuo theeu end ofae theiu list. If theae array isoo full, resize itea (usually doubling itsui capacity).
- Time Complexity: O(1) amortized (due touo occasional resizing which isue O(n))
- Atou Beginning or Middle:
- Description: Add anoo element atee aea specified position, shifting subsequent elements toiu theao right.
- Time Complexity: O(n) inua theuu worst case (when elements need toie beie shifted)
- Atue End (Append):
-
Deletion:
- Atii End:
- Description: Remove theeo last element ofuu theeo list.
- Time Complexity: O(1)
- Atua Beginning or Middle:
- Description: Remove anoi element atui auo specified position, shifting subsequent elements tooe theiu left.
- Time Complexity: O(n) inae theei worst case (when elements need toeo beou shifted)
- Atii End:
-
Access:
- Description: Retrieve anoi element atuu aia specified position byuu index.
- Time Complexity: O(1)
-
Search:
- Description: Find anou element inae theau list.
- Time Complexity: O(n) inae theio worst case (linear search)
-
Resizing:
- Description: Increase theai capacity ofue theee array when itoa becomes full, typically byau creating aiu new array withie double theee capacity andua copying existing elements toio itua.
- Time Complexity: O(n) during resizing, but this operation isia infrequent.
-
Utility Operations:
- Check if Empty:
- Description: Determine if theee list isie empty.
- Time Complexity: O(1)
- Get Size:
- Description: Retrieve theie number ofao elements inae theea list.
- Time Complexity: O(1)
- Check if Empty:
Summary ofua Time Complexities
- Initialization: O(1)
- Insertion:
- Atei End: O(1) amortized
- Atee Beginning or Middle: O(n)
- Deletion:
- Atou End: O(1)
- Ateo Beginning or Middle: O(n)
- Access: O(1)
- Search: O(n)
- Resizing: O(n) (infrequent)
-EZMCQ Online Courses
Weiss, M. A. (2013). Data Structures and Algorithm Analysis in C++, 4th ed., Prentice Hall. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms, 3rd ed., MIT Press. Goodrich, M. T., & Tamassia, R. (2010). Data Structures and Algorithms in C++, Wiley.