I apologize, but as a text-based AI, I cannot directly create and provide a PDF file. I do not have the functionality to generate or save files in PDF format.
However, I can give you the text in a format that you can easily copy and paste into a document editor (like Microsoft Word, Google Docs, LibreOffice Writer) and then save as a PDF.
Here's the text again, formatted for easy copy-pasting:
Answers to DSA Questions
1. Define time and space complexity with an example.
Time Complexity: Measures the runtime of an algorithm as input size grows.
Example: A linear search has O(n) time complexity (checks each element once).
Space Complexity: Measures memory usage by an algorithm as input size grows.
Example: A program using a single variable has O(1) space complexity.
2. What is the difference between linear search and binary search? Give an example.
Linear Search:
Checks elements sequentially.
Time: O(n).
Example: Search for 5 in [3, 1, 4, 5, 9] (checks 3 → 1 → 4 → 5).
Binary Search:
Works on sorted arrays; divides search interval in half.
Time: O(log n).
Example: Search for 5 in [1, 3, 4, 5, 9] (mid=4, then right half to find 5).
3. Define time complexity. Why is it important in algorithm analysis?
Definition: Time complexity quantifies how runtime grows with input size (e.g., O(n log n), O(n)).
Importance: Helps compare algorithm efficiency and choose the best one for a problem.
4. What is space complexity? Explain with a small example.
Definition: Space complexity measures memory usage by an algorithm as input size grows.
Example: A recursive factorial function uses O(n) space (due to recursion stack).
5. Define recursion. Mention one problem where recursion is effective.
Definition: A function that calls itself to solve smaller subproblems.