Ch. 9 random Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Unit Testing

A

piece of code that passes arguments to function to be tested. Calculates value expected value and compares it to the actual value. Checks whether they are equal and records result

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

Unit

A

Smallest component of a program that can be tested

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

Benefits of unit testing

A

-fast
-identifies bugs easily
-makes it easy for members to check each others code
-provides documentation
-provides confidence that code works as intended

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

Recursion

A

breaking problem down into subsets of problem.

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

Recursive function

A

function that calls itself. Passes a subset of the function as an argument. Breaks down into smaller subsets of itself until a stopping point is reached: a base case. e.g. factorial

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

parts of recursive function

A
  1. define recursive function
  2. define base case
  3. specify value to be returned when base case is reached
  4. specifying operation to be done with each returned value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Searching algorithms

A

-Linear Search
-Binary Search

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

Linear search

A

Iterates through each item in a list and compares each one to a key until this key is found

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

what is the final print of this code:
for i in range(6):
print(i)

A

5

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

Binary Search

A

requires list to be sorted. Selects middle value and if the key isn’t the value it checks if it’s higher or lower. It then searches the corresponding half of the list in the same manner by selecting the middle card. This repeats until the key is found or determined to not be present.

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

Selection Sort

A

finds smallest item in a list and places it in first position. The next smallest item is then found and placed in second position. This repeats for all items in the list

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

Insertion Sort

A

Start by ordering two items. Then add subsequent items into the correct position within the sorted items

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

Bubble Sort

A

Compare two items at a time and swap their positions if required. Continue through list for each pair. List may not be sorted after one pass so more passes are done on the list until it is fully sorted.

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

Quick Sort

A

Assigns an item in the list to be the pivot value. All other items in the list are sorted into sublists as either above or below this value. These two sublists get their own pivot values and the cycle repeats until there is only one item in every sublist. The list is now sorted. Can be implemented recursively.

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

Benefits of recursion

A
  1. clearer code since it usually uses less lines. Coding quicksort iteratively would require manually making recursion 2. Alignment with problem structure. Algorithms like quicksort involve dividing a problem into smaller parts so recursion is a natural fit.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly