CS50 Flashcards
what is the input to any computer?
elictiricity
what does electricity represent in computers?
zeros and ones
what is the highest you can count with 3 light bulbes?
up to 7 as we count from 0 and we have 8 patterns to count
how did we count that 123 is one hundred and twenty 3?
because from the right to the left we use the base of 10 3 * 1 + 10^0 2 * 10 + 10^1 1 * 100 + = 10^2 123
what is the base to calculate in binary systems?
2 ^ 0 1
2 ^1 2
2^ 2 4
how to represent letters in binary?
we use numbers to represent each letter
what is a byte?
8 bits
what is a bit?
a zero or a one
how many letters can u represent with a byte?
256
what is an algorithm?
it’s a step by step instruction to solve a problem
what is a compiler?
a software that converts source code to machine code?
what is machine code?
it’s the language of zeros and ones
how is the code evaluated?
from right to left
how many bytes in an int?
4 bytes (32 bits)
what is an unsigned integer?
it’s not a new data type it’s just a qualifier for int meaning it changes it’s properties containing only positive values
how many bytes does char take?
1 byte (8 bits)
how many bytes does a float take?
4 bytes (32 bits)
how many bytes does a double take?
8 bytes (64 bits)
when is && evaluates to true?
when all of the operands evaluate to true
when is || evaluate to true?
when only one condition is true
what happens when you don’t break in switch case?
u fall down the cases after one of them evaluates to true
how many steps in compiling?
preprocessing:
copies functions prototypes any #include to current file
compiling:
converts source code to assembly code
assembling:
converts assembly code to machine code zeros and ones
linking:
links our zeros and ones to the original C language zeros and ones and other libraries
what is an array?
a sequence of contiguous values stored back to back
can u initialize an array with a variable?
no it must be a constant
what is the null character?
\0 8 zero bits
when can we describe an algorithm in theta?
if the upper bound is the same as the lower bound
what is the complexity of linear search?
O(n)
sigma(1)
what is psuedo code for linear search?
starting from first element till last
if we find element then exit
otherwise move to next element
what is the main idea of binary search?
divide and conquer
each loop divide it by half
what is the condition to do binary search?
elements must be sorted
what is the complexity of binary search?
O(log n)
sigma (1)
what is psuedo code for binary search?
repeat until subarray of size 0 (start and end are crossed)
calculate the current middle point of the current array if the target is at middle
or if the target is less than what’s at the middle, repeat but change the endpoint to be just the left of the middle
or if the target is more than what’s at the middle, repeat but change the start point to be just the right of the middle
what is the main idea of bubble sort?
move higher elements to the right and lower value elements to the left
what is psuedo code for bubble sort?
set swap counter to non-zero repeat until is swap counter not zero set counter to zero look at adjacent pairs if not in order swap them and increase counter by one
what is the complexity of bubble sort?
O(n2)
sigma(n)
what is the main idea of selection sort?
find the smallest element in an unsorted list and add it to the end of the sorted list
what is psuedo code for selection sort?
repeat until no unsorted elements remain:
search the unsorted part of the data to find the smallest element
swap the smallest value with the first element of the unsorted part
what is the complexity of selection sort?
O(n2)
simga(n2)