search and sort Flashcards

1
Q

What is sequential (linear) search?

A

A method that checks each element in a list one-by-one.

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

What is the time complexity of sequential search?

A

O(n)

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

What is binary search?

A

A method that divides a sorted array in half repeatedly to find a target.

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

When can binary search be used?

A

Only on sorted arrays or ArrayLists.

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

What is the time complexity of binary search?

A

O(log n)

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

How does binary search work?

A

Check middle

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

What happens if target not found in binary search?

A

Eventually returns -1 or a “not found” flag.

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

What is insertion sort?

A

A sorting method that builds a sorted list one item at a time.

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

What is the time complexity of insertion sort?

A

O(n^2) worst case

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

What is selection sort?

A

A sorting method that repeatedly selects the smallest element.

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

How does selection sort work?

A

Find smallest

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

What is the time complexity of selection sort?

A

O(n^2) in all cases

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

What is merge sort?

A

A divide-and-conquer algorithm that splits

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

What is the time complexity of merge sort?

A

O(n log n)

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

How does merge sort work?

A

Divide list

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

What is the benefit of merge sort over selection/insertion?

A

It’s faster for large datasets (O(n log n) vs. O(n^2)).

17
Q

Is merge sort recursive?

18
Q

Which sort is best for nearly-sorted data?

A

Insertion sort.

19
Q

Which sort is the easiest to implement?

A

Selection sort — it’s conceptually simple.

20
Q

Which sort requires extra memory?

A

Merge sort — due to the temporary arrays used in merging.

21
Q

What’s a stable sort?

A

A sort that maintains relative order of equal elements.

22
Q

Is selection sort stable?

23
Q

Is insertion sort stable?

24
Q

Is merge sort stable?

25
Which sort is used in Java's built-in sort methods?
TimSort (a hybrid of merge and insertion
26
How does sort choice affect performance?
Big O notation gives a theoretical view