1. Main program%%find two sets quick sort TicarrayList1= [ the, -, $, the, the, -, -, the, -, the];arraylist1= QuickSort (ArrayList1,1, Length (arrayList1)); ArrayList2= [ the, the, the, -, at,566, the];arraylist2= QuickSort (ArrayList2,1, Length (arrayList2));%%two sets of intersection; Length_arraylist1=length (arrayList1); Length_arraylist2=length (ARRAYLIST2); Union=[];i=1; J=1; while true ifI < Length_arraylist1 && J <Length_arraylist2ifArrayList1 (i) <ArrayList2 (j) I= i +1; ElseIf ArrayList1 (i)>ArrayList2 (j) J= j +1; ElseUnion=[Union,arraylist1 (i)]; I= i +1; J= j +1; EndElse Break; ENDENDTOC Quick Sort functions function arrayList=QuickSort (Arraylist,low,high)% Pivotpos =1;if(Low <High ) [Pivotpos,arraylist]=partition (Arraylist,low,high); ArrayList= QuickSort (Arraylist,low,pivotpos-1); ArrayList= QuickSort (Arraylist,pivotpos +1, high); EndEnd partition function; functions [low,new_arraylist]=partition (Arraylist,low,high)ifNargin = =1 Low=1; High=length (arrayList); Endpivot= ArrayList (low); %using the 1th record of the interval to make the benchmark; whileThe low < high% is scanned from the interval two stages to the middle until low =Hing whileLow Pivot High= High-1; EndifLow < high% means found arraylist[hihg]<pivot; Temp=arrayList (Low); ArrayList (Low)=arrayList (high); ArrayList (High)=temp; Low= Low +1; End whileLow < High && arrayList (low) <=Pivot Low= Low +1; EndifLow <High temp=arrayList (high); ArrayList (High)=arrayList (Low); ArrayList (Low)=temp; High= High-1; Endendnew_arraylist=Arraylist;end
Find out what the faster way to solve the set intersection.
Two convergence intersection with fast sorting