Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Title: Introduction to Algorithms

1. Question: What is an algorithm?


Answer: An algorithm is a step-by-step procedure or formula for solving a problem. It is a
sequence of finite instructions, typically to perform a computation or solve a specific problem.

2. Question: Describe the characteristics of a good algorithm.


Answer: A good algorithm should have the following characteristics:
- Clear and Unambiguous: Each step should be precisely defined.
- Well-Defined Inputs and Outputs: The algorithm should specify the input and the expected
output.
- Finite and Terminating: The algorithm should have a finite number of steps and must
terminate after producing the required output.
- Feasible: It should be possible to execute each step with the available resources.
- Efficient: It should make optimal use of resources, including time and space.

3. Question: What is the difference between a linear search and a binary search?
Answer:
- Linear Search: Checks each element of the list sequentially until the desired element is
found or the list ends. It has a time complexity of O(n).
- Binary Search: Efficiently finds an element by repeatedly dividing the sorted list in half and
comparing the target value to the middle element. It has a time complexity of O(log n).

4. Question: Explain the concept of Big O notation.


Answer: Big O notation is used to describe the performance or complexity of an algorithm,
specifically the worst-case scenario. It expresses how the runtime or space requirements of an
algorithm grow relative to the input size. Common Big O complexities include O(1), O(log n),
O(n), O(n log n), and O(n²).

5. Question: Describe the merge sort algorithm.


Answer: Merge sort is a divide-and-conquer algorithm that divides the input array into two
halves, recursively sorts each half, and then merges the two sorted halves to produce the final
sorted array. It has a time complexity of O(n log n).

You might also like