Coding Fundamentals 1 — Questions and Answers
Question 1: What is the time complexity of searching for an element in a balanced binary search tree (BST)?
- O(1)
- O(log n) (Correct answer)
- O(n)
- O(n log n)
Correct answer: O(log n)
In a balanced binary search tree, each comparison effectively halves the search space. This logarithmic reduction in the number of elements to check leads to a time complexity of O(log n) for search, insertion, and deletion operations. This efficiency makes balanced BSTs highly effective for managing ordered data.
Question 2: Which SQL query retrieves all rows from a table named employees where the salary is greater than 5000?
- SELECT * FROM employees WHERE salary = 5000;
- SELECT * FROM employees WHERE salary > 5000; (Correct answer)
- SELECT salary FROM employees WHERE salary > 5000;
- SELECT employees FROM salary WHERE > 5000;
Correct answer: SELECT * FROM employees WHERE salary > 5000;
The `SELECT *` clause specifies that all columns should be retrieved from the `employees` table. The `WHERE salary > 5000` clause then filters these results, ensuring that only rows where the 'salary' column has a value strictly greater than 5000 are included in the output. This is the standard SQL syntax for such a conditional selection.
Question 3: Which CSS property is used to create space between the element's content and its border?
- margin
- padding (Correct answer)
- border-spacing
- spacing
Correct answer: padding
In CSS, `padding` is the property used to generate space within an element's box, specifically between its content and its border. This internal spacing pushes the content away from the border, affecting the element's overall size. In contrast, `margin` creates space outside the element's border, separating it from other elements.
Question 4: Which Python library is primarily used for data manipulation and analysis?
- NumPy
- Pandas (Correct answer)
- Matplotlib
- Scikit-learn
Correct answer: Pandas
Pandas is a powerful and widely used open-source Python library specifically designed for data manipulation and analysis. It provides data structures like DataFrames and Series, which are highly efficient for handling tabular data, performing operations like filtering, grouping, merging, and cleaning datasets. While NumPy is foundational for numerical computing, Pandas builds upon it to offer more high-level data handling capabilities.
Question 5: Which HTTP status code indicates that the resource was not found?
- 200
- 301
- 404 (Correct answer)
- 500
Correct answer: 404
The HTTP status code 404 Not Found is a standard response code indicating that the server could not find the requested resource. This means the URL is recognized, but the resource itself (e.g., a specific webpage or file) does not exist at that location. It's a common error seen when a link is broken or a page has been moved.
What is the time complexity of searching for an element in a balanced binary search tree (BST)?