Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet
Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet
Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
!<br />
procedure insertion_sort( " a<br />
# i<br />
for j := 2 to n<br />
i := 1<br />
while a j > a i<br />
i := i + 1<br />
t := a j<br />
for k := 0 to j-i-1<br />
a j-k := a j-k-1<br />
a i := t<br />
!<br />
{ " a<br />
# i<br />
n<br />
$<br />
%<br />
&i=1<br />
n<br />
$<br />
%<br />
&i=1<br />
is in increasing order}<br />
: reals, n>1)<br />
This is not a very efficient sorting algorithm either. However, it is easy to see<br />
that at the j th step that the j th element is put into the correct spot. The worst case<br />
time is O(n 2 ). In fact, insertion_sort is trivially slower than bubble_sort.<br />
47<br />
Number theory is a rich field <strong>of</strong> mathematics. We will study four aspects briefly:<br />
1. Integers and division<br />
2. Primes and greatest common denominators<br />
3. Integers and algorithms<br />
4. Applications <strong>of</strong> number theory<br />
Most <strong>of</strong> the theorems quoted in this part <strong>of</strong> the textbook require knowledge <strong>of</strong><br />
mathematical induction to rigorously prove, a topic covered in detail in the next<br />
chapter. !<br />
48