Chapter 5 Flashcards

1
Q

What is searching?

A

Looking through a file to see if a particular piece of data exists

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

What is sorting?

A

Putting items of data into a particular order - alphabetical or numerical.

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

What is bubble sort?

A

An algorithm to sort an unordered list by comparing adjacent items and swapping them if needed.

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

How does bubble sort work?

A

1) Start at the beginning of the list.
2) Compare the first and second values. Swap if necessary.
3) Compare the second and third values. Swap if necessary.
4) Continue working up the list untill the end.
5) If the list still isn’t sorted, start the next pass by going to the beginning.
6) extra pass to check

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

Advantages of bubble sort (2)

A

Simplest

easiest to code

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

Disadvantages of bubble sort (1)

A

Slowest

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

What insertion sort?

A

An algorithm used to sort lists by examining each item in turn and inserting it into its correct position.

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

How does insertion sort work?

A

1) If there is only one item in the list then stop
2) Start with the second item and compare it to the first and swap if necessary
3) compare the third and second and swap if necessary. Repeat step 2.
4) Compare the third and fourth and swap if necessary. Repeat step 3.
5) Continue till the last element.

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

Advantages of insertion sort (3)

A

Simple
easy to code
Twice as fast as bubble sort

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

Disadvantages of insertion sort

A

Slower than merge sort

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

What is merge sort?

A

A sorting algorithm which sorts lists bu recursively dividing a list smaller and smaller untill the size of each list is one, and then add them up together while sorting them.

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

How does merge sort work?

A

1) if there is only one item in the list then stop
2) Divide the list into 2 parts
3) Recursively divde these lists untill the size of each becomes one
4) Recursively merge the lists with the items in order

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

Advantages of merge sort (1)

A

Fastest of the three algorithms

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

Disadvantages of merge sort (2)

A

Hardest to code

Harderst on the processor

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

How does linear search work?

A

Start at the beginning of the list
move through each element until you find the search criterion
or reach the end of list

Does not need the list to be sorted first

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

How to calculate average number of passes for linear search?

A

1+x / 2

X = number of elements on the list

17
Q

How does binary search work?

A
  • Select middle element and compare to search criterion
  • If it matches, stop
  • if it is lower than the search criterion, descard left half and if higher discard right half.
  • Repeat until search criterion is found or the list length is one.

Requires list to be sorted

18
Q

How to find the average number of passes for binary search?

A

(Log2(x) + 1) / 2

19
Q

Which is faster on average binary or linear?

A

Binary