CSCE4110 - Exam 1 Flashcards
What is an algorithm
a step-by-step procedure for solving a problem or accomplishing some end
statement is true prior to the first iteration
initialization
if it is true before the iteration of the loop it remains true before the next iteration
maintenance
is true at the end of the loop
termination
j=2, therefore A[i:j-1] is A[1], single element=>sorted
initialization
we move elements until proper position of a[j] is found. therefore if a[1:j-1] is sorted after iteration j A[1:j] is sorted
maintenance
ends when j=n+1; therefore based on maintenance criteria A[1:n] is sorted
termination
time complexity of merge sort
theta(n log n)
how to get time complexity of merge sort
split each node by 1/2 and there are log(n)+1 levels
max-heap: parent
floor( i / 2 )
max-heap: left
2(i)
max-heap: right
2(i) + 1
counting sort
one array of the input, one array of indexing each value, one array of input frequency
radix sort
start sorting with least significant digit
bucket sort
sort numbers into linked list based on first digit