CS50 Week 3 Flashcards

1
Q

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

A

A segmentation fault

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

What function will convert a char to a value?

A

atoi(s)

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

What is a simple but effective debugging technique?

A

printf()

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

What is the clang argument that allows for gdb debugging?

A

-ggdb3

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

After compiling, how do you open GDP?

A

gdb debug

where debug is the name of the program being debugged.

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

What is a breakpoint in gdb?

A

A point at which the program pauses executing

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

Where is a convenient place to put the first breakpoint?

A

main()

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

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

A

next

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

How do you reenter the last command you typed?

A

hit enter with no command.

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

How do you start your program running from within gdb?

A

run

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

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

A

print i

where i is the name of the variable

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

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

A

list

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

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

A

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.

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

How do you set a breakpoint in gdb

A

break functionName

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

What is a linear algorithm?

A

An algorithm of n complexity.

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

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

What is a logarithmic algorithm?

A

An algorithm of log(n) complexity.

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

17
Q

What is bubble sort?

A

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
Q

What is the complexity of bubble sort?

A

n^2

19
Q

What is selection sort?

A

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
Q

What is the complexity of selection sort?

A

(n(n-1))/2

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

21
Q

What is insertion sort?

A

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
Q

What is the complexity of insertion sort?

A

n^2

23
Q

What is the best case scenario for bubble sort?

A

n

24
Q

What is the best case scenario for selection sort?

A

n^2

25
Q

What is the worst case scenario for linear search?

A

n

26
Q

What is the worst case scenario for binary search?

A

log(n)

27
Q

What is the best case scenario for binary search?

A

1

28
Q

What is the best case scenario for linear search?

A

1

29
Q

In GDB, how do you display the active variables?

A

info locals

30
Q

How do you deactivate a breakpoint in GDB

A

disable

31
Q

How do you tell GDB to finish running the program, without going line by line?

A

continue