Flashcards in CS50 Week 3 Deck (31):

1

## What happens if you try to access an element beyond the bounds of an array?

### A segmentation fault

2

## What function will convert a char to a value?

### atoi(s)

3

## What is a simple but effective debugging technique?

### printf()

4

## What is the clang argument that allows for gdb debugging?

### -ggdb3

5

## After compiling, how do you open GDP?

###
gdb debug

where debug is the name of the program being debugged.

6

## What is a breakpoint in gdb?

### A point at which the program pauses executing

7

## Where is a convenient place to put the first breakpoint?

### main()

8

## How do you step line by line through your code in gdb?

### next

9

## How do you reenter the last command you typed?

### hit enter with no command.

10

## How do you start your program running from within gdb?

### run

11

## How do you check the value of a variable at the point that you are in the code, while within gdb?

###
print i

where i is the name of the variable

12

## How do you display the code before and after your current position?

### list

13

## How do you move execution by execution within a function call, using gdb? This is distinct from the command "next"

###
step

step will be distinct from next only if you are at a function call, in which case it will follow the function instead of going to the next line of code in the sequence.

14

## How do you set a breakpoint in gdb

### break functionName

15

## What is a linear algorithm?

###
An algorithm of n complexity.

It will execute n times where n is the size of the input.

16

## What is a logarithmic algorithm?

###
An algorithm of log(n) complexity.

It will execute log(n) number of times, where n is the size of the input.

17

## What is bubble sort?

### A sorting technique that starts at the first two values of a non-sorted sequence and compares them. If the numbers are out of order, it swaps the first and second values. Then it compares the second and third values, and does the same. It does this until the entire sequence can be read with no swaps.

18

## What is the complexity of bubble sort?

### n^2

19

## What is selection sort?

### The algorithm reads each value in a non-sorted sequence and remembers the smallest number. It then swaps the smallest number with the first number in the sequence. It then repeats this process on the unsorted elements of the sequence until all are sorted.

20

## What is the complexity of selection sort?

###
(n(n-1))/2

This ends up being very close to n^2, so we say n^2

21

## What is insertion sort?

### An algorithm that sorts the elements in place. It examines each element in a non-sorted list, and places it in the appropriate position in a sorted list.

22

## What is the complexity of insertion sort?

### n^2

23

## What is the best case scenario for bubble sort?

### n

24

## What is the best case scenario for selection sort?

### n^2

25

## What is the worst case scenario for linear search?

### n

26

## What is the worst case scenario for binary search?

### log(n)

27

## What is the best case scenario for binary search?

### 1

28

## What is the best case scenario for linear search?

### 1

29

## In GDB, how do you display the active variables?

### info locals

30

## How do you deactivate a breakpoint in GDB

### disable

31