{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture-13

# lecture-13 - CPSC 223 Algorithms Data Abstract Structures...

This preview shows pages 1–5. Sign up to view the full content.

10/14/10 1 CPSC 223 Algorithms & Data Abstract Structures Lecture 13: Mergesort exercise Binary Search Trees (intro) Today … Homework Homework 5 due today Homework 6 Sorting Exercises (Mergesort) Start Binary Search Trees Ch 10: pp. 499-516, 519-546 CPSC 223 -­૒-­૒ Fall 2010 2

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

View Full Document
10/14/10 2 Mergesort (based on textbook) void Mergesort (Entry theArray[], int n, int first, int last) { if(first < last) { int mid = (first + last) / 2; Mergesort (theArray, n, first, mid); Mergesort (theArray, n, mid + 1, last); Merge (theArray, n, first, mid, last); } } CPSC 223 -­૒-­૒ Fall 2010 3 Mergesort (based on textbook) void Merge (Entry theArray[], int n, int first, int mid, int last) { Entry tmpArray[n]; int first1 = first, first2 = mid + 1, i = first1; for(; first1 <= mid && first2 <= last; i++) { if(theArray[first1] < theArray[first2]) tmpArray[i] = theArray[first1++]; else tmpArray[i] = theArray[first2++]; } for(; first1 <= mid; i++, first1++) // copy remaining from first half tmpArray[i] = theArray[first1]; for(; first2 <= last; i++, first2++) // copy remaining from sec. half tmpArray[i] = theArray[first2]; for(int j = first; j <= last; j++) // copy tmpArray to the array theArray[j] = tmpArray[j]; } CPSC 223 -­૒-­૒ Fall 2010 4
10/14/10 3 Binary Search Trees We’ll start with some basic terminology Next week we’ll dive into more details CPSC 223 -­૒-­૒ Fall 2010 5 Tree Structures A tree is a “ non linear ” data structure … CPSC 223 -­૒-­૒ Fall 2010 6 A B C D E F G a list is a “linear” structure A B C D E F G tree with the same nodes

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

View Full Document
10/14/10 4 Tree Structures Trees are used to represent different kinds of relationships CPSC 223 -­૒-­૒ Fall 2010 7 B R V S C For example, inheritance hierarchies (taxonomies, ontologies, …) M Vehicle Bicycle Mountain Bike Road Bike Car Sports Car ÷ 2 + 5 Algebraic expressions (evaluaVon order) × 4 3 Tree Structures CPSC 223 -­૒-­૒ Fall 2010 8 E Y C G N NesVng (including “has a” relaVonships) N Company Employee Name #Years Name Gonzaga J John 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}