Data Structure and Algorithm Overview
1. Algorithm Complexity: Definition and Importance
Examination of the complexity of an algorithm is
crucial to understand its efficiency.
Different algorithms can have varying efficiencies,
even if they produce the same result.
2. Space Complexity: Definition and Examples
Space complexity refers to the amount of memory
used by an algorithm.
Examples:
Array: fixed amount of memory for storing
elements
Linked list: varying amount of memory based
on number of nodes
3. Time Complexity: Definition and Examples
Time complexity refers to the time taken by an
algorithm to run based on the size of the input.
Examples:
Constant time: O(1)
Linear time: O(n)
Quadratic time: O(n^2)
4. Time Complexity of Loops and Conditions
, Understanding the time complexity of different
control flow structures, such as loops and conditions,
is essential for accurate algorithmic analysis.
5. Comparing Time and Space Complexity
Balancing time and space complexity is key to
building efficient algorithms.
6. Relationship between Program Time and Input Size
The time taken by an algorithm often increases with
the size of the input.
7. Analyzing Time Efficiency of Programs
Techniques for analyzing time efficiency:
Counting operations: determining the number
of operations required to run the algorithm
Working with asymptotic notation: Big O,
Omega, and Theta
Multiple Choice Questions
Question 1
What is the primary difference between space and time
complexity?
A. Space complexity measures memory usage, while
time complexity measures execution time.
B. Space complexity measures execution time, while
time complexity measures memory usage.
, C. Both measure memory usage, but space complexity
is more detailed.
D. Both measure execution time, but time complexity is
more detailed.
Answer: (A) Space complexity measures memory usage,
while time complexity measures execution time.
Question 2
Which of the following is NOT a common time
complexity notation?
A. O(1)
B. O(n)
C. O(n^2)
D. O(n!)
Answer: (D) O(n!)
Question 3
An algorithm with a time complexity of O(1) is generally
considered to be:
A. Very inefficient
B. Moderately efficient
C. Highly efficient
D. Dependent on input size
Answer: (C) Highly efficient
, Question 4
Why is it important to analyze the time complexity of an
algorithm?
A. To determine the best programming language for
implementation.
B. To predict the algorithm's performance for different
input sizes.
C. To optimize memory usage.
D. To choose the correct data structure.
Answer: (B) To predict the algorithm's performance for
different input sizes.
Question 5
Which data structure typically has a fixed amount of
memory usage?
A. Array
B. Linked list
C. Both array and linked list
D. Neither array nor linked list
Answer: (A) Array
Question 6
How does the size of the input generally affect the time
taken by an algorithm?
A. The time taken decreases as the input size
increases.