Algorithms and Recursion Flashcards

1
Q

What is the grandfather of all sorting algorithms?

A

Bubble Sort

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

What is involved in a bubble sort?

A

Compare adjacent elements, if the one on the left is larger swap to the right and continue

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

After one complete pass with a bubble sort algorithm, what will always be true?

A

The largest value will be in the last element.

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

How many comparisons are made on each pass of a bubble sort?

A

array.length - 1

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

What must your loop continuation condition be in a bubble sort?

A

i < array.length - 1

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

What is a major downside of the bubble sort?

A

Because it compares (n-1) elements each pass, and does (n-1) passes, even if the array was already sorted it still needs to compare (n-1)^2 times.

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

How many comparisons are done in a bubble sort? (passes and individual included)

A

(array.length - 1) * (array.length - 1)

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

What is the LCC for an enhanced bubble sort?

A

i < array.length - (h + 1); Where h is the counter of the outer loop

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

How does a “short-circuit” work?

A

Track number of swaps done with a counter, if zero then use a break statement.

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

How does a selection sort work?

A

Find the smallest value in an array and swap with the left-most element

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

What kind of search algorithm just starts at element 0 and compares every element?

A

Linear search

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

To use a binary search algorithm, what must first be done?

A

Sort the array

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

How does the binary search algorithm work?

A

Look at middle element and compare with value wanted. If value is larger, repeat process to the right. If smaller, to the left until value found.

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

What is it called when a method calls itself?

A

Recursion

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

What is an example of a problem best solved using recursion?

A

Traversal of a binary tree

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

Anything that can be done recursively can also be done using what?

A

A loop

17
Q

What is the name of the last method call when using recursion?

A

Base Case or Stopping Case

18
Q

What part of memory are the recursive method calls held in?

A

Method Call Stack

19
Q

What is a major drawback of using recursion?

A

Uses substantial resources due to memory.