Problem Description
Given a DataFrame named employees with columns name and salary, create a new column called bonus that contains the doubled value of the salary for each employee.
Key Insights
- The task involves simple column-wise arithmetic on a DataFrame.
- It leverages vectorized operations available in many programming languages/libraries.
- The operation does not require any additional data structures; just iterating over the existing rows.
- Performance is efficient as each row is processed exactly once.
Space and Time Complexity
Time Complexity: O(n), where n is the number of rows in the DataFrame. Space Complexity: O(n), if a new DataFrame copy is created; however, if done in-place the extra space usage is O(1).
Solution
The solution is straightforward: iterate over the DataFrame and create a new column bonus where each value is the salary value multiplied by 2. In languages with built-in DataFrame support (like Python with Pandas), use vectorized operations to achieve this in one line. For other languages, simulate the DataFrame structure with collections/arrays and update each element accordingly.