Searching And Sorting Algorithms Flashcards

1
Q

Can linear search be used in ordered or unordered

A

Both

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

How does linear search work

A

Every number in the list is checked in the order of the list until the number is found

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

Is linear search slow or fast

A

Linear search is slow unless you get lucky however in a computer algorithm there tends to be lots of numbers so it would be long

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

Does binary search work on unordered or ordered lists

A

Ordered lists

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

How does binary search work

A

You find the midpoint by adding the smallest and largest position in the list and divide by 2 if it’s a decimal you round up. If the midpoint is the number you are looking for the search ends. If not then you see if the midpoint is less than or more than and then which ever it is you eliminate the opposite for example if greater than you remove the smaller numbers. Next you repeat this process until your number is found

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

Is binary search fast or slow

A

It is fast when using long lists

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

Disadvantages of binary search

A

It is very slow on short lists
The list has to be ordered

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

Does bubble sort work on ordered or unordered list

A

Unordered

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

Show how bubble sort works

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

Does bubble sort work on short or long lists

A

Short

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

Advantages of bubble sort

A

Simple to understand
Effective for very small data sets or almost-sorted lists

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

How does merges sort work (e.g. with an 8 number list)

A

First divide all the numbers in the list until there is 8 sub lists.
Next merge the sub lists into 4 sub lists and order the numbers
Next merge into 2 sub lists and order them
Finally merge into one list and order them

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

Advantages of merge sort

A

Efficient for large datasets

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

Insertion sort

A

(6 0) 4 8 1 5
0 (6 4) 8 1 5
0 4 (6 8) 1 5
0 4 6 (8 1) 5
0 4 6 1 (8 5)
(0 4) 6 1 5 8
0 (4 6) 1 5 8
0 4 (6 1) 5 8
0 4 1 (6 5) 8
0 4 1 5 (6 8)
(0 4) 1 5 6 8

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

Disadvantage of merge sort

A

Uses more memory as more space is needed to merge the lists

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

Advantages of insertion sort

A

simple to use
Fast for short lists
Needs very little memory

17
Q

Disadvantages of insertion sort

A

Slow on long lists