Problem Description
Display only the first 3 rows of the given employees DataFrame.
Key Insights
- For a DataFrame, built-in functions such as head() can be utilized to extract the first few rows.
- In non-Pandas environments, list slicing or iterating through the first fixed number of elements achieves the same result.
- The problem is straightforward and involves no complex operations.
Space and Time Complexity
Time Complexity: O(1) — Only three rows are accessed regardless of the total data size. Space Complexity: O(1) — No extra space is required beyond storing the reference to the three rows.
Solution
The solution involves accessing the first three rows of the DataFrame or array-like data structure. In Python, Pandas’ head(3) function directly retrieves these rows. In other programming languages, the approach typically involves slicing or iterating over the data structure for exactly three elements. Since the number to extract is fixed, the operation is constant in time and space.