Week 3: Arrays & Computation Complexity and Analysis of Algorithms Flashcards

1
Q

Which of the following statements about arrays is true?

A) Arrays can store elements of different types.
B) Arrays are mutable and can change size dynamically.
C) Arrays store a fixed-size sequential collection of elements of the same type.
D) Arrays are unordered collections.

A

C) Arrays store a fixed-size sequential collection of elements of the same type.

Explanation: Arrays are a basic data structure that stores a fixed-size sequential collection of elements of the same type. They are not mutable and cannot change size dynamically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following is a characteristic of a list in Python?

A) Lists are immutable.
B) Lists are unordered collections.
C) Lists can change size as items are added or removed.
D) Lists do not allow duplicate values.

A

C) Lists can change size as items are added or removed.

Explanation: Lists in Python are mutable sequence containers that can change size as items are added or removed. They are ordered collections and can contain duplicate values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which method is used to add an item to the end of a list in Python?

A) insert()
B) append()
C) extend()
D) add()

A

B) append()

Explanation: The append() method adds an element at the end of the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which method is used to remove the first occurrence of a specified value from a list in Python?

A) pop()
B) remove()
C) delete()
D) clear()

A

B) remove()

Explanation: The remove() method removes the first item with the specified value from the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which method returns the number of elements with the specified value in a list?

A) count()
B) index()
C) len()
D) find()

A

A) count()

Explanation: The count() method returns the number of elements with the specified value in a list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following statements about tuples is true?

A) Tuples are mutable.
B) Tuples are unordered collections.
C) Tuples allow duplicate values.
D) Tuples can change size dynamically.

A

C) Tuples allow duplicate values.

Explanation: Tuples are ordered collections that allow duplicate values. They are immutable, meaning their size and content cannot be changed after creation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of the following best describes a dictionary in Python?

A) A collection of ordered elements.
B) A collection of key-value pairs.
C) A collection of unique values.
D) A collection of immutable elements.

A

B) A collection of key-value pairs.

Explanation: A dictionary in Python is a collection of key-value pairs, where each key is unique and is used to store and retrieve values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which method returns a list of all the keys in a dictionary?

A) keys()
B) values()
C) items()
D) get()

A

A) keys()

Explanation: The keys() method returns a list of all the keys in the dictionary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following best describes an algorithm?

A) A random sequence of steps to solve a problem.
B) A systematic procedure that produces the answer to a question in a finite number of steps.
C) A collection of unordered steps to solve a problem.
D) A sequence of steps that may or may not produce a solution.

A

B) A systematic procedure that produces the answer to a question in a finite number of steps.

Explanation: An algorithm is an organized sequence of clear steps or operations needed to solve a given programming problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following factors is used to choose between different algorithms?

A) The number of lines of code.
B) The efficiency, usually noted by how long an algorithm takes to produce its result.
C) The programming language used.
D) The number of comments in the code.

A

B) The efficiency, usually noted by how long an algorithm takes to produce its result.

Explanation: Efficiency, often measured by the time an algorithm takes to produce its result, is a key factor in choosing between different algorithms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does computational complexity measure?

A) The number of lines of code in an algorithm.
B) The amount of resources (time and space) required to run an algorithm.
C) The number of comments in the code.
D) The programming language used.

A

B) The amount of resources (time and space) required to run an algorithm.

Explanation: Computational complexity measures the amount of resources, such as time and space, required to run an algorithm.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is time complexity?

A) The number of lines of code in an algorithm.
B) The amount of memory required to solve a problem.
C) The number of times an algorithm runs.
D) The number of comments in the code.

A

C) The number of times an algorithm runs.

Explanation: Time complexity is expressed as the number of times an algorithm runs, indicating how the execution time grows with the input size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does Big-O notation describe?

A) The number of lines of code in an algorithm.
B) The limiting behavior of a function when the argument tends toward a particular value or infinity.
C) The number of comments in the code.
D) The programming language used.

A

B) The limiting behavior of a function when the argument tends toward a particular value or infinity.

Explanation: Big-O notation describes the limiting behavior of a function, used to classify the efficiency of algorithms according to how their space and time complexity grows as the input size grows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

hich Big-O notation represents constant time complexity?

A) O(n)
B) O(1)
C) O(n^2)
D) O(log n)

A

B) O(1)

Explanation: O(1) represents constant time complexity, where the time required to execute the algorithm is constant, regardless of the input size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which Big-O notation represents linear time complexity?

A) O(n)
B) O(1)
C) O(n^2)
D) O(log n)

A

A) O(n)

Explanation: O(n) represents linear time complexity, where the time required to execute the algorithm is proportional to the input size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which Big-O notation represents polynomial time complexity?

A) O(n)
B) O(1)
C) O(n^2)
D) O(log n)

A

C) O(n^2)

Explanation: O(n^2) represents polynomial time complexity, where the time complexity increases based on the number of nested loops.

17
Q

Which type of algorithm analysis considers the maximum number of steps required?

A) Best-case
B) Average-case
C) Worst-case
D) Random-case

A

C) Worst-case

Explanation: Worst-case analysis considers the maximum number of steps required for an algorithm to complete, providing an upper bound on the time complexity.

18
Q

Which type of algorithm analysis considers the minimum number of steps required?

A) Best-case
B) Average-case
C) Worst-case
D) Random-case

A

A) Best-case

Explanation: Best-case analysis considers the minimum number of steps required for an algorithm to complete, providing a lower bound on the time complexity.