Sortingn And Searching Flashcards

1
Q

What is a linear search most effective for?

A

Small or unsorted lists where simplicity is more important than speed.

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

What is the time complexity of a linear search?

A

O(n) — it checks each item until the target is found or the end is reached.

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

What is the time complexity of a binary search?

A

O(log n) — the list is halved with each step, making it much faster than linear search for large datasets.

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

What is the main drawback of binary search?

A

The data must be sorted beforehand — if not, it won’t work correctly.

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

What does a sort algorithm do?

A

It arranges data into a specific order — usually ascending or descending.

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

What are the steps of the bubble sort algorithm?

A
  1. Compare two adjacent items
  2. Swap them if they are in the wrong order
  3. Repeat until no swaps are needed (the list is sorted)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the worst-case time complexity of bubble sort?

A

O(n²) — very inefficient for large lists.

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

What are the steps of merge sort?

A
  1. Divide the list into halves
  2. Recursively sort each half
  3. Merge the sorted halves together
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the time complexity of merge sort?

A

O(n log n) — efficient for large lists.

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

What are the pros and cons of merge sort?

A

• Pros: Fast and reliable for large lists
• Cons: Uses more memory and can be harder to implement

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

Why is understanding sorting and searching algorithms important in Computer Science?

A

Because they are fundamental to handling data efficiently and are used in many real-world applications (e.g., search engines, databases).

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