Introduction - CMPS 101 Algorithms and Abstract Data Types...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CMPS 101 Algorithms and Abstract Data Types Introduction to Algorithm Analysis Summary of the Theory Side of this Course Mathematical Preliminaries o Asymptotic growth rates of functions o Some common functions and their properties o Induction Proofs o Recurrences Standard ADTs o Elementary Data Structures like Stacks, Queues, and Lists o Graphs and Directed Graphs o Priority Queues o Disjoint Sets o Binary Search Trees and Red-Black Trees o Dictionaries o Hash Tables Algorithms Associated with these ADTs o Sorting and Searching o Breadth First Search, Depth First Search, Shortest Paths, Minimum Weight Spanning Trees o Insertion and Deletion in Balanced Trees Run Time Analysis of these Algorithms Some Sorting Algorithms A classic problem in Computer Science is that of sorting a collection of objects in increasing order. We assume for the moment that the objects to be sorted are stored in an array A of fixed length n . ) , , , , ( 3 2 1 n A A A A A K = Our convention is that array indices range from 1 to ] [ length A n = (not 0 to 1 - n , as in many computer languages). We denote the subarray with indices ranging from i to j by ) , , ( ] [ j i A A j i A K L = . If j i > this is understood to denote the empty array, i.e. an array of length 0. We begin by analyzing two algorithms that solve this problem: Insertion Sort and Merge Sort . InsertionSort( A ) 1.) for 2 j to n 2.) temp j A 3.) 1 - j i 4.) while 0 > i and temp i A < 5.) i i A A + 1 6.) 1 - i i 7.) + 1 i A temp
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 If this notation is not absolutely clear, read the pseudo-code conventions outlined on pages 19-20 of the text. In particular, notice that the left arrow " " stands for the assignment operator, and that loop bodies and conditional branches are indicated solely by indentation, not by braces or other punctuation characters. Also there are no semicolons, parenthesis, or brackets, and local variables need not be declared before use. Notice that on the j th iteration of loop 2-7, the subarray )] 1 ( 1 [ - j A L is already sorted, while ] [ n j A L is unsorted. Steps 3-7 have the effect of inserting j A into its correct position in )] 1 ( 1 [ - j A L , thus expanding the sorted section by exactly 1. n j j j A A A A A 1 1 1 L L L L L L L L + - Exercise: Trace InsertionSort( A ) on ) 6 , 2 , 7 , 4 , 1 , 3 , 5 , 8 ( = A We wish to determine the run time ) ( n T of this algorithm as a function of the input size n . This analysis should be, as far as possible, independent of the computing machine that is executing the algorithm. Let k c denote the cost of step k . We remain uncommitted as to just what units or even what quantity k c measures. This could be processor time in seconds, or power consumed in watts, or even some appropriate monetary unit. As we shall see, details of this kind are not critical to the analysis. Thus for instance, 2 c and 3 c represent the costs of assignment operations, while 1 c and 4 c are the costs of performing tests of loop repetition conditions. Notice that
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/03/2009 for the course CS CS101 taught by Professor Agoreback during the Spring '09 term at American College of Gastroenterology.

Page1 / 6

Introduction - CMPS 101 Algorithms and Abstract Data Types...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online