CS50 Week 3 Flashcards
What happens if you try to access an element beyond the bounds of an array?
A segmentation fault
What function will convert a char to a value?
atoi(s)
What is a simple but effective debugging technique?
printf()
What is the clang argument that allows for gdb debugging?
-ggdb3
After compiling, how do you open GDP?
gdb debug
where debug is the name of the program being debugged.
What is a breakpoint in gdb?
A point at which the program pauses executing
Where is a convenient place to put the first breakpoint?
main()
How do you step line by line through your code in gdb?
next
How do you reenter the last command you typed?
hit enter with no command.
How do you start your program running from within gdb?
run
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
How do you display the code before and after your current position?
list
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.
How do you set a breakpoint in gdb
break functionName
What is a linear algorithm?
An algorithm of n complexity.
It will execute n times where n is the size of the input.
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.
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.
What is the complexity of bubble sort?
n^2
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.
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
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.
What is the complexity of insertion sort?
n^2
What is the best case scenario for bubble sort?
n
What is the best case scenario for selection sort?
n^2
What is the worst case scenario for linear search?
n
What is the worst case scenario for binary search?
log(n)
What is the best case scenario for binary search?
1
What is the best case scenario for linear search?
1
In GDB, how do you display the active variables?
info locals
How do you deactivate a breakpoint in GDB
disable
How do you tell GDB to finish running the program, without going line by line?
continue