{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

13 - Sorting and Recursion

# 13 - Sorting and Recursion - Engineering 101 Quote of the...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering 101 Quote of the Day When one door to happiness closes, another opens; but often we look so long at the closed door that we do not see the one which has been opened for us. - Helen Keller Sorting and Recursion Sorting Often we have a list of numbers and we would like to order them. What is a good way to do this using a computer? Bubble Sort Go through the list and make sure to move the highest to the end. Then go through the list again and make sure the second highest is second to the end. Rinse and Repeat... Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 5 0 3 4 1 6 5 2 1 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 5 0 3 4 1 6 5 2 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 5 0 2 4 1 6 5 3 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 5 1 2 4 1 6 5 3 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 5 1 2 3 1 6 5 4 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 5 2 2 3 1 6 5 4 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 5 3 2 3 1 6 5 4 2 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 5 3 2 3 1 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 5 4 2 3 1 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 4 0 2 3 1 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 4 1 2 3 1 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 4 2 2 3 1 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 4 3 2 3 1 4 5 6 3 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 3 0 2 3 1 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 3 1 2 3 1 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 3 2 2 3 1 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 2 0 2 3 1 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 2 0 1 3 2 4 5 6 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 2 1 1 3 2 4 5 6 4 Bubble Sort void bubblesort( vector<int> & list){ int i; // How many have we sorted? int j; // Which are we comparing? for(i=list.size( )-1; i > 0; i=i-1) )i=ifor(j=0; j< i; j=j+1) if (list.at(j) > list.at(i)) swap(list.at(i), list.at(j)); return; } i j list[0] list[1] list[2] list[3] list[4] list[5] 2 1 1 2 3 4 5 6 Recursion A program that calls itself is called recursive. recursive. Example: int factorial (int n){ if (n==0) return 1; else return n* factorial(n-1); factorial(n} Recursion factorial (4) return 4* factorial(3) factorial (4) Recursion return 4* factorial(3) factorial (3) return 3* factorial(2) Recursion factorial (4) return 4* factorial(3) factorial (3) return 3* factorial(2) factorial (2) return 2* factorial(1) factorial (4) Recursion return 4* factorial(3) factorial (3) return 3* factorial(2) factorial (2) return 2* factorial(1) factorial (1) return 1* factorial(0) 5 Recursion factorial (4) return 4* factorial(3) factorial (3) return 3* factorial(2) factorial (2) return 2* factorial(1) factorial (1) return 1* 1 factorial (4) Recursion return 4* factorial(3) factorial (3) return 3* factorial(2) factorial (2) return 2* 1 Recursion factorial (4) return 4* factorial(3) factorial (3) return 3* factorial(2) factorial (2) return 2 factorial (4) Recursion return 4* factorial(3) factorial (3) return 3* 2 Recursion factorial (4) return 4* factorial(3) factorial (3) return 6 factorial (4) return 4* 6 Recursion 6 Recursion Exercise Which function will return the nth number in the Fibonacci sequence? 1 1 2 3 5 8 13 21 ... Fn = Fn-1 + Fn-2 24 What is the screen output and what will the function return if the following vector is passed in as input? Exercise What will be output if the string "go" is passed to the function? Another Sort of Sort What if we write a procedure that will merge two sorted lists into a combined sorted list? Another Sort of Sort What if we write a procedure that will merge two sorted lists into a combined sorted list? 1 2 3 4 5 6 7 8 9 10 2 3 4 7 9 1 5 6 8 10 7 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) if(aindex==a.size()){ c[ i ] = b[bindex]; bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge a 2 3 4 7 9 b 1 5 6 8 10 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; First create a new for( int i=0; i<c.size(); i=i+1) vector that is the if(aindex==a.size()){ size of the other c[ i ] = b[bindex]; two combined bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge c a 2 3 4 7 9 b 1 5 6 8 10 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); aindex and bindex int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) will track the if(aindex==a.size()){ progress through c[ i ] = b[bindex]; the two lists bindex = bindex + 1; a and b }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge c a 2 3 4 7 9 b 1 5 6 8 10 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); loop over each int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) element in the if(aindex==a.size()){ combined list and c[ i ] = b[bindex]; figure out what the bindex = bindex + 1; element should be. }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge c a 2 3 4 7 9 b 1 5 6 8 10 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); if we have int aindex=0, bindex=0; exhausted the a for( int i=0; i<c.size(); i=i+1) list then take the if(aindex==a.size()){ next from the b list c[ i ] = b[bindex]; and increment bindex = bindex + 1; bindex }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge c a 2 3 4 7 9 b 1 5 6 8 10 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); if we have int aindex=0, bindex=0; exhausted the b for( int i=0; i<c.size(); i=i+1) list then take the if(aindex==a.size()){ next from the a list c[ i ] = b[bindex]; and increment bindex = bindex + 1; aindex }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge c a 2 3 4 7 9 b 1 5 6 8 10 8 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); otherwise take int aindex=0, bindex=0; from the list with for( int i=0; i<c.size(); i=i+1) the lowest if(aindex==a.size()){ remaining value c[ i ] = b[bindex]; and increment bindex = bindex + 1; its index }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge c 1 a 2 3 4 7 9 b 1 5 6 8 10 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) if(aindex==a.size()){ c[ i ] = b[bindex]; bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge c 1 2 a 2 3 4 7 9 b 1 5 6 8 10 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) if(aindex==a.size()){ c[ i ] = b[bindex]; bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge c 1 2 3 a 2 3 4 7 9 b 1 5 6 8 10 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) if(aindex==a.size()){ c[ i ] = b[bindex]; bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge c 1 2 3 4 a 2 3 4 7 9 b 1 5 6 8 10 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) if(aindex==a.size()){ c[ i ] = b[bindex]; bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge a 2 3 4 7 9 b 1 5 6 8 10 c 1 2 3 4 5 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) if(aindex==a.size()){ c[ i ] = b[bindex]; bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge a 2 3 4 7 9 b 1 5 6 8 10 c 1 2 3 4 5 6 9 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) if(aindex==a.size()){ c[ i ] = b[bindex]; bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge a 2 3 4 7 9 b 1 5 6 8 10 c 1 2 3 4 5 6 7 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) if(aindex==a.size()){ c[ i ] = b[bindex]; bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge a 2 3 4 7 9 b 1 5 6 8 10 c 1 2 3 4 5 6 7 8 template<class T> void merge( const T & a, const T & b, T & c){ c.resize(a.size() + b.size() ); int aindex=0, bindex=0; for( int i=0; i<c.size(); i=i+1) if(aindex==a.size()){ c[ i ] = b[bindex]; bindex = bindex + 1; }else if (bindex==b.size()){ c[ i ] = a[aindex]; aindex = aindex + 1; }else if (a[aindex] < b[bindex]){ c[ i ] = a[aindex]; aindex = aindex + 1; } else { c[ i ] = b[bindex]; bindex = bindex + 1; } } Merge a 2 3 4 7 9 b 1 5 6 8 10 c 1 2 3 4 5 6 7 8 9 10 Merge Sort We can create a sort in the following way: If there is only 1 element in the list do nothing Otherwise break the list into two nearly even parts a and b Sort each part Merge the two together How do we sort each part? Recursively! 7 9 2 4 3 8 10 1 5 6 Merge Sort We can create a sort in the following way: If there is only 1 element in the list do nothing Otherwise break the list into two nearly even parts a and b Sort each part Merge the two together Merge Sort 7 9 2 4 3 8 10 1 5 6 We can create a sort in the following way: If there is only 1 element in the list do nothing Otherwise break the list into two nearly even parts a and b Sort each part Merge the two together How do we sort each part? Recursively! How do we sort each part? Recursively! 2 3 4 7 9 1 5 6 8 10 10 Merge Sort We can create a sort in the following way: If there is only 1 element in the list do nothing Otherwise break the list into two nearly even parts a and b Sort each part Merge the two together How do we sort each part? Recursively! 1 2 3 4 5 6 7 8 9 10 template <class T> void mergeSort(T & x) { if (x.size() <= 1) return; int i; T a, b; a.resize(x.size()/2); b.resize(x.size() a.size()); Merge Sort for(i=0; i< a.size(); i++) a[ i ] = x[ i ]; for(i=0; i< b.size(); i++) b[ i ] = x[ a.size()+i ]; mergeSort(a); mergeSort(b); merge(a, b, x); return; } template <class T> void mergeSort(T & x) { if (x.size() <= 1) return; int i; T a, b; a.resize(x.size()/2); b.resize(x.size() a.size()); Merge Sort if the size of x is 1 or 0 then there is no need to sort template <class T> void mergeSort(T & x) { if (x.size() <= 1) return; int i; T a, b; a.resize(x.size()/2); b.resize(x.size() a.size()); Merge Sort Otherwise split the list into two sub-lists that are each half or nearly-half the original list for(i=0; i< a.size(); i++) a[ i ] = x[ i ]; for(i=0; i< b.size(); i++) b[ i ] = x[ a.size()+i ]; mergeSort(a); mergeSort(b); merge(a, b, x); return; } } for(i=0; i< a.size(); i++) a[ i ] = x[ i ]; for(i=0; i< b.size(); i++) b[ i ] = x[ a.size()+i ]; mergeSort(a); mergeSort(b); merge(a, b, x); return; template <class T> void mergeSort(T & x) { if (x.size() <= 1) return; int i; T a, b; a.resize(x.size()/2); b.resize(x.size() a.size()); Merge Sort Copy the original list into the two sublists template <class T> void mergeSort(T & x) { if (x.size() <= 1) return; int i; T a, b; a.resize(x.size()/2); b.resize(x.size() a.size()); Merge Sort Sort each half for(i=0; i< a.size(); i++) a[ i ] = x[ i ]; for(i=0; i< b.size(); i++) b[ i ] = x[ a.size()+i ]; mergeSort(a); mergeSort(b); merge(a, b, x); return; } } for(i=0; i< a.size(); i++) a[ i ] = x[ i ]; for(i=0; i< b.size(); i++) b[ i ] = x[ a.size()+i ]; mergeSort(a); mergeSort(b); merge(a, b, x); return; 11 template <class T> void mergeSort(T & x) { if (x.size() <= 1) return; int i; T a, b; a.resize(x.size()/2); b.resize(x.size() a.size()); Merge Sort Merge them Merge Sort 7 9 2 4 3 8 10 1 5 6 for(i=0; i< a.size(); i++) a[ i ] = x[ i ]; for(i=0; i< b.size(); i++) b[ i ] = x[ a.size()+i ]; mergeSort(a); mergeSort(b); merge(a, b, x); return; } Merge Sort 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 Merge Sort split sort Merge Sort 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 7 9 Merge Sort split sort 12 Merge Sort 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 7 9 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 Merge Sort split merge Merge Sort 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 Merge Sort 2 4 3 sort 2 4 3 split Merge Sort 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 Merge Sort 2 4 3 4 3 sort 2 4 3 4 3 split 13 Merge Sort 7 9 2 4 3 8 10 1 5 6 7 9 2 4 3 7 9 2 4 3 8 10 1 5 6 7 9 2 3 4 Merge Sort 2 3 4 merge merge Merge Sort 2 3 4 7 9 8 10 1 5 6 2 3 4 7 9 8 10 1 5 6 Merge Sort merge sort 8 10 1 5 6 Merge Sort 2 3 4 7 9 8 10 1 5 6 2 3 4 7 9 8 10 1 5 6 Merge Sort split 8 10 1 5 6 sort 8 10 1 5 6 8 10 14 Merge Sort 2 3 4 7 9 8 10 1 5 6 2 3 4 7 9 8 10 1 5 6 Merge Sort split 8 10 1 5 6 8 10 merge 8 10 1 5 6 Merge Sort 2 3 4 7 9 8 10 1 5 6 2 3 4 7 9 8 10 1 5 6 Merge Sort sort 8 10 1 5 6 1 5 6 split 8 10 1 5 6 1 5 6 Merge Sort 2 3 4 7 9 8 10 1 5 6 2 3 4 7 9 8 10 1 5 6 Merge Sort sort 8 10 1 5 6 1 5 6 split 8 10 1 5 6 1 5 6 5 6 5 6 15 Merge Sort 2 3 4 7 9 8 10 1 5 6 2 3 4 7 9 8 10 1 5 6 Merge Sort merge 8 10 1 5 6 1 5 6 merge 8 10 1 5 6 Merge Sort 2 3 4 7 9 1 5 6 8 10 1 2 3 4 5 6 7 8 9 10 Merge Sort merge merge Next Lecture Matrices and Linear Equations 16 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online