Register now to access 7 million high quality study materials (What's Course Hero?) Course Hero is the premier provider of high quality online educational resources. With millions of study documents, online tutors, digital flashcards and free courseware, Course Hero is helping students learn more efficiently and effectively. Whether you're interested in exploring new subjects or mastering key topics for your next exam, Course Hero has the tools you need to achieve your goals.

1 Page

2c03-review - 00030

Course: CAS 2c03, Spring 2003
School: McMaster
Rating:

Word Count: 213

Document Preview

P2(n:integer); b.[5] procedure var i,j,k : integer; begin for i:=1 to 100000000 do for j:=i-1 to 20*n do for k:=1 to j do {some statement requiring O(1) time} end T(n) = 100000000i=1T = 100000000i=1(20nj=i-1T) = 100000000i=1(20nj=i-1(jk=1O(1))) = 100000000i=1(20nj=i-1O(j)) = 100000000i=1O((20n-i+2)*(20n+i-1)) = 100000000i=1O((20n-i)*(20n+i)) = 100000000i=1O(400n2-i2) = O(400n2 - 100000000i=1i2) = O(n2) Now we...

Register Now

Unformatted Document Excerpt

Coursehero >> Canada >> McMaster >> CAS 2c03

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
P2(n:integer); b.[5] procedure var i,j,k : integer; begin for i:=1 to 100000000 do for j:=i-1 to 20*n do for k:=1 to j do {some statement requiring O(1) time} end T(n) = 100000000i=1T = 100000000i=1(20nj=i-1T) = 100000000i=1(20nj=i-1(jk=1O(1))) = 100000000i=1(20nj=i-1O(j)) = 100000000i=1O((20n-i+2)*(20n+i-1)) = 100000000i=1O((20n-i)*(20n+i)) = 100000000i=1O(400n2-i2) = O(400n2 - 100000000i=1i2) = O(n2) Now we have only two nested loops since for i:=1 to 100000000 is a constant. c.[5] procedure var P3(n:integer); i,j,x,y : integer; begin for i:=1 to n do if i mod 3 = 1 then begin for j:=i to n do x:=x+1; for j:=20000 downto n do x:=x+y; for j:=1 to i do y:=y+1 end end T(n) = ni=1T = ni=1(nj=iO(1) + 20000j=nO(1) +ij=1O(1))/3 = ni=1(O(n-i+1) +O(i)) = O(n(n+1)/2) + O(n(n+1)/2) = O(n2) Only two level of nesting, each with O(n). d.[15] function F(n:integer):integer; begin if n<=1 then return(1) else return(F(n-1)+F(n div 2)) end We have to solve the following recurrence equation. 4
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

McMaster - CAS - 2c03
T(n) = if n1 then C1 else C + T(n-1) +T(n div 2) Let T1(n) and T2(n) be the following functions: T1(n) = if n1 then C1 else C + 2T1 (n-1), T2(n) = if n1 then C1 else C + 2*T2 (n div 2). Clearly T2(n) &lt; T(n) &lt; T1 (n) if n&gt;1. Note that, for n &gt; 1: T1 (n) =
McMaster - CAS - 2c03
7.[55] Sort the following numbers using [5] bubble, [5] insertion, [5] bin, [5] Shell, [10] quick, [15] heap, and both [5] the recursive and [5] non-recursive versions of the 2-way merge sort: 5, 11, 20, 8, 13, 10, 25, 7, 30, 12, 10, 40, 0, 3, 10, 21, 16,
McMaster - CAS - 2c03
Pass16: 0, 3, 5, 7, 8, 10, 10, 10, 11, 12, 13, 16, 20, 21, 25, 30, 40, 74 Pass17: 0, 3, 5, 7, 8, 10, 10, 10, 11, 12, 13, 16, 20, 21, 25, 30, 40, 74 Bin: First pass: Bin:0 20 10 30 10 40 0 101 11 212 123 13 34 745 5 256 167 78 89The concatenated
McMaster - CAS - 2c03
5 incr=411 10 80310716 1220 40 1310 25 2130 740 incr=2310 7510 10813 1120 21 16 1225 4030 740 incr=1 0 quick:3 357 5710 88 10 10 1010 1013 11 11 1216 12 20 21 13 16 20 2125 40 25 3030 74 40 745 11 20 8 13 10 25 7 30 12 10 40
McMaster - CAS - 2c03
11 12 11 12result: 0, 3, 5, 7, 8, 10, 10, 10, 11, 12, 13, 16, 20, 21, 25, 30, 40, 74 heap: 5 insert(5) 5 insert(11) 11 insert(20) 11 20 11 5 insert(13) 8 11 13 20 11 insert(10) 8 10 11 13 20 5 insert(25) 8 5 insert(25) 10 7 13 20 25 5 10 5 insert(8) 8 20
McMaster - CAS - 2c03
0 insert(10) 7 8 10 10 3 511 30 13 12 40 20 25 10 0 insert(21) 7 8 10 10 3 5 11 21 8 30 16 13 insert(16) 7 10 10 25 3 5 10 011 30 13 12 40 20 25 10 2112 40 200 insert(74) 7 8 10 10 3 511 30 13 12 40 20 25 10 21 16 74 3 delete(0) 7 8 10 10 5 1011 30
McMaster - CAS - 2c03
5 delete(3) 7 8 10 16 10 10 11 21 10 30 13 delete(5) 8 167 10 10 12 40 20 25 7411 30 13 12 40 20 25 74 21 8 delete(7) 10 11 12 16 10 1010 delete(8) 11 21 25 30 13 12 16 10 1021 30 13 74 40 20 2574 40 2010 delete(10) 11 21 12 16 delete(10) 10 20 25 2
McMaster - CAS - 2c03
20 delete(16) 21 25 74 25 delete(21) 40 74 40 delete(30) 74 delete(40) 74 delete(25) 30 40 40 delete(20) 30 40 25 7421 3030 74delete(74)result: 0, 3, 5, 7, 8, 10, 10, 10, 11, 12, 13, 16, 20, 21, 25, 30, 40, 74 non-recursive 2-way merge: 5 5 5 5 0 0 11
McMaster - CAS - 2c03
8.[20]Write a program (in pseudo-code) to find the mode (the most frequently occurring element) of a list of elements. What is a complexity of your program?[10] 1. MODE(A) 2. 3. / A: array of elements 4. / F: frequency 5. SORT(A) 6. m 0 7. l 0 8. F(1) 1
McMaster - CAS - 2c03
void maxHeapify(int A[],int i,int heapSize)cfw_ int r=right(i); int l=left(i); int largest; if(l&lt;heapSize &amp; A[l]&gt;A[i]) largest=l; else largest=i; if(r&lt;heapSize &amp; A[r]&gt;A[largest]) largest=r; if(largest!=i)cfw_ int t=A[i]; A[i]=A[largest]; A[largest]=t; ma
McMaster - CAS - 2c03
for(int i=0;i!=size;i+)cfw_ cout&lt;endl&lt;&quot;(&quot;&lt;i+1&lt;&quot;):&quot;; cin&gt;A[i]; heapSort(A,size);int *F=new int[size];/frequency F[0]=1; for(int i=1;i!=size;i+) if(A[i]=A[i-1]) F[i]=F[i-1]+1; else F[i]=1;int m=0; int l=0; for(int i=1;i!=size;i+) if(F[i]&gt;=m)cfw_ m=F[i];
McMaster - CAS - 2c03
a.[5]n T (n) = 4T ( ) + n 3 4 n n 4T ( ) = 42 T ( 2 ) + n 3 3 3 4 n n 4 2 T ( 2 ) = 43 T ( 3 ) + ( ) 2 n 3 3 3 MM 4 n n 4i T ( i ) = 4i +1T ( i +1 ) + ( )i n 3 3 3 MM 4log3 T ( T (n) = 4log3 + nn n log 3 1 nn 3n log3) = 4log3n (3)i =04i= n log3
McMaster - CAS - 2c03
10.[10] Give tight big-oh and big-omega bounds on T(n) defined by the following recurrences. Assume T(1)=1 a.[5] T(n)=2T(n/2)+log n b.[5] T(n)=2T(n/2)+n2a.[5]n T (n) = 2T ( ) + lg n 2 n n n 2T ( ) = 2T ( 2 ) + 2 lg 2 2 2 n n n 22 T ( 2 ) = 23 T ( 3 ) +
McMaster - CAS - 2c03
b.[5]n T ( n) = 2T ( ) + n 2 2 n n n2 2T ( ) = 2T ( 2 ) + 2 2 2 2 2 n n n2 2 2 T ( 2 ) = 23 T ( 3 ) + 2 2 4 2 2 2 MM n n n2 2i T ( i ) = 2i +1T ( i +1 ) + 2i 2i 2 2 2 MM 2lg n T ( T ( n) = n +lg n 1n ) = 2lg n 2lg ni =0n2 1 = n + n 2 (1 ( )lg n ) = n
McMaster - CAS - 2c03
SE2C03. Sample solutions to the assignment 2. Total of this assignment is 151 pts. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, and resubmit
McMaster - CAS - 2c03
if (p .next &lt;&gt; nil) p := p .next ; while (p .next &lt;&gt; nil) do begin p .next := p .next .next; if (p .next &lt;&gt; nil) p := p .next ; end p := L1; while (p .next &lt;&gt; nil) do p := p .next ; p .next := L2 .next; return(L1); end The time complexity is O(m+n). c.[6]
McMaster - CAS - 2c03
The time complexity is O(n). d.[6] Assume that the list are doubly linked and redo (b). Discuss the difference if any. function C1H2H(L1, L2: celltype;): celltype; var p : celltype; var n : integer; begin cfw_delete odd elements in List 1 p := L1; while (
McMaster - CAS - 2c03
var n : integer; begin p := L; q := p .previous; while (p&lt;&gt;q) and (p .next &lt;&gt; q) do begin L := p .next ; p .next .previous := p .previous; p := p .next; L .previous := q .previous; q .previous .next := nil; q := q .previous; end return(L); end For doubly
McMaster - CAS - 2c03
end The time complexity is O(n). [6] function C1H2H(L1, L2: List;): List; var n : integer; begin L1.last := (L1.last div 2); for (n:=1 to L1.last) do L1.element[n] := L1.element[2*n] L2.last := L2.last (L2.last div 2); for (n:=1 to L2.last) do L2.element[
McMaster - CAS - 2c03
next: celltype; procedure EXCHANGE1-6(var L: celltype;): var p,q : celltype; var tmp : elementtype; var i: integer; begin p := L; q := L; for i := 1 to 5 do if (q .next &lt;&gt; nil) then q := q .next; while (q .next &lt;&gt; nil) do begin for i := 1 to 5 do if (q .n
McMaster - CAS - 2c03
while (p&lt;&gt;END(L1) do begin Delete(p, L1); if p&lt;&gt;END(L1)p := NEXT(p, L1); end cfw_delete even elements in List two p := FIRST(L2); if p&lt;&gt; END(L2) then p := NEXT(p, L2); while (p&lt;&gt;END(L2) do begin Delete(p, L2); if p&lt;&gt;END(L2) then p := NEXT(p, L2); end cfw_
McMaster - CAS - 2c03
end return(L); end 5.[15] The level-order listing of the nodes of a tree first lists the root, then all nodes of depth a, then all nodes of depth 2, and so on. Nodes at the same depth are listed in left-to-right order. Write a program to list the nodes of
McMaster - CAS - 2c03
Question 6[5] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 133 20 383 22 156 784 9999 82 144787 674 176 845 11 31 1230 122622 35 416 94Question 7[5] h(k ) = 506 k ( 51 2)mod 1h(51) = 262, h(52) = 69, h(53) = 382, h(54) = 189, h(55) = 501. Questio
McMaster - CAS - 2c03
9.[15] a.[5] Show the heap (partially ordered tree) that results if the integers 8, 7, 5, 6, 10, 2, 1, 3, 11, 9, 4 are inserted into an empty tree.b[10]. What is the result of 5 successive DELETEMIN operations on the tree from (a)?1
McMaster - CAS - 2c03
Question 10[10] 8 7 5 (a) 2 1 3 4 6 6 9 11 9 10 8 11 (b) 7 102
McMaster - CAS - 2c03
11.[10]Give an example of a binary search tree which is a complete tree. Can it be done for an arbitrary number of nodes? Prove your answer.Yes. First, construct complete tree with n nodes. Get the inorder list of the complete tree, say, a1,a2,an. Let a
McMaster - CAS - 2c03
insertion:n(n + 1) = O(n 2 ) 2 i =1 inorder walk takes O(n) therefore total time: O(n 2 )i =nBest case: O(n lg n) : when tree growth is balanced, each insertion takes O(lg n) ,we have n insertion therefore total insertion takes O(n lg n) inorder walk
McMaster - CAS - 2c03
SE2C03. Sample solutions to the assignment 3. Total of this assignment is 274pts. 100%=254. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, and
McMaster - CAS - 2c03
2.[30] AVL trees are a good implementation of binary search trees. Show (step by step) the AVL trees formed by inserting the numbers 10, 9, 8, 7, 6, 5, 4, 3, 2, 1. 10 10 insert(10) insert(9) 9 8 9 insert(6) 8 7 6 10 6 9 repair 7 8 5 insert(5) 10 6 7 8 10
McMaster - CAS - 2c03
7 repair 5 3 2 4 1 6 8 9 10 2 3 4 inset(1) 57 repair 9 6 8 10 1 2 4 37 9 5 8 6 103.[20] a[10], b[10], Solutions at the end. 4.[10] Consider ADT Sets with the following operations: MEMBER, DELETE, INSERT. Show that a heap is not an efficient way to impl
McMaster - CAS - 2c03
5.[15] Consider ADT Sets with the following operations: MEMBER, DELETE, INSERT, UNION, MERGE. Show that a binary search trees are not an efficient way to implement this ADT. What about 2-3 trees or red-black? Which operation is the most problematic? Provi
McMaster - CAS - 2c03
6.[25] Consider ADT Sets (of numbers) with the following operations: MEMBER(x), DELETEMIN, INSERT(x), DELETEMAX, and MEDIAN, which is a function integer greater than or equal to x, i.e. 3.1 = 4, 4 = 4. What model(s) would you recommend and why? Provide bi
McMaster - CAS - 2c03
8.[10] a[5] If team 1 needs i games to win, then it has won n-i games already. Thus, we obtain the following recurrence: P(i, j) = 1 0 pn-i(P(i-1,j)+(1- pn-i(P(i,j-1) if i=0 and j&gt;0 if i&gt;0 and j=0 if i&gt;0 and j&gt;0b[5] (i,j) 0 1 2 3 4 0 0 1 1 1 1 1 0 0.5 0.
McMaster - CAS - 2c03
b. Assume T(k,k)=T(j,0)=c for all j,k, and for making reasoning easier T(i,j)=0 if j&lt;0. T(n,m)=T(n-1,m)+T(n-1,m-1)+1 (n,m) / (n-1,m) / \ (n-2,m) (n-2,m-1) . \ (n-1,m-1) / \ (n-1,m-1) (n-2,m-2)One solution, by using recursion tree in pure form: In the wor
McMaster - CAS - 2c03
Hence: T(n,m) (C(0,k)+C(1,k)+.+C(i,k)+.+C(k,k) c + (2k+1-1)c = 2k c + (2k+1-1)c = (32k 1)c = (32n/2 1)c = O(2n/2). One also may suspect O(2n/2) solution, and prove it by induction. c. we use the recursive formulation, to fill entries of the table like the
McMaster - CAS - 2c03
int Factorial(int n)cfw_ int f=1; for(int i=1;i&lt;=n;i+) f*=i; return f; /DnC implements solution to 10(a). it uses divide and conquer method int DnC(int n,int m)cfw_ if(m=0 | n=m) return 1; else return DnC(n-1,m)+DnC(n-1,m-1); /DP implements solution to
McMaster - CAS - 2c03
12.[10] Suppose characters a, b, c, d, e, f, g, h, i, j have probabilities 0.02, 0.02, 0.03, , 0.04, 0.05, 0.10, 0.10, 0.13, 0.20, 0.31, respectively. Construct an optimal Huffman code and draw the Huffman tree. Use the following rules: a. Left: 0, right:
McMaster - CAS - 2c03
13.[20] Suppose T is a Huffman tree, and that the leaf for symbol a has greater depth than the leaf for symbol b. Prove that the probability of symbol b is no less than that of a. It can be proven in many ways by induction. The simplest seems to be the fo
McMaster - CAS - 2c03
Another possible solution, in the similar style is the following. For any Huffman tree, if we combine two leaves, and use another symbol to represent it. Assigning the sum of probability of two leaves to the new symbol, we get a new Huffman tree for a new
McMaster - CAS - 2c03
Now, we suppose prob(a) &gt; prob(b), which means a is not used before b is used in construction of Huffman tree. These imply that prob(a) &gt; prob(T), because prob(b) and prob(T) must be the smallest two ones. With the same reason, prob(c) &gt; prob(b), pro(T),
McMaster - CAS - 2c03
16.[20] Suppose we use the 2-3 trees to implement the WMERGE (i.e. a MERGE(A,B), but the set is totally ordered and all the elements of A are smaller than the elements of B) and SPLIT. a.[10] Show the result of splitting the tree of Question (1a) at 7. 25
McMaster - CAS - 2c03
Question 3 5 1 0 2 3 4 6 7 8 10 9 11 12 13 After deletions: 5 1 0 2 4 6 7 8 10 9 11 12Question 9 8 2 5 10 j f1 [j ] f2 [j ] l1 [j ] l2 [j ] 1 10 15 2 20 19 1 1 3 22 26 1 3 2 6 4 27 27 1 1 5 36 33 1 2 6 39 41 2 2 10 2 1 7 7 49 47 1 2 8 52 52 2 2 1 3 4 5 4
McMaster - CAS - 2c03
Question 14 (a) 519110 After deletions:234678101213519110 (b)2467810122690 After deletions:134578101112132690 (c)14578101112590 After deletions:1234678101112135901246781011122
McMaster - CAS - 2c03
SE2C03. Sample solutions to the assignment 4. Total of this assignment is 231 pts. 100%= 205. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, a
McMaster - CAS - 2c03
Using KMPabaAbabaababbababaaababaababb pass1 a b b pass2 aB pass3 Abb pass4 abb pass5 ab pass6 abb pass7 abbababaaabab # of comparisons 3 2 3 3 2 3 13 Total 293.[16] Abstract Data Type DIGRAPH involves the following 3 operations on directed graphs : FIR
McMaster - CAS - 2c03
b.[8] Linked adjacency lists Assume the ADT LIST is defined with proper functions implemented. function FIRST(v:integer): position begin return(FIRST_LIST(A[v]) end function NEXT(v:integer, i:position): position begin return(NEXT_LIST(A[v],i) end function
McMaster - CAS - 2c03
a.[5] a a b c d e f g h i b[5] a [b,5,nil] b [c,1] [d,3,nil] c [a,3] [d,2] [e,3] [h,2,nil] d [a,4] [b,4,nil] e [b,2] [d,3] [f,2] [i,4,nil] f [b,1] [d,2,nil] g [b,1] [c,3,nil] h [d,2] [g,3,nil] i [a,1,nil] 3 4 b c 1 4 2 1 1 d 3 2 3 2 3 2 1 3 e 3 2 f 5 g h
McMaster - CAS - 2c03
7.[20] A root of a directed acyclic graph (dag) is a vertex r such that every vertex of the dag can be reached by a directed path from r. Write a program to determine whether a dag is rooted. Assume that the dag is represented using adjacency lists. Make
McMaster - CAS - 2c03
10.[10]Use a depth-first search algorithm to identify all the articulation vertices and biconnected components in the graph from Question 9. Draw an appropriate depth-first graph and indicate all the low and dfnumber values.A solution at the end11.[15]
McMaster - CAS - 2c03
A possible solution M cfw_(A,I) cfw_(A,I),(B,G) cfw_(A,I),(B,G),(C,J) cfw_(A,I),(B,G),(C,J),(E,K) cfw_(A,I),(B,G),(C,J),(E,K),(M,N) cfw_(A,I),(B,H),(C,J),(D,G),(E,K),(M,N) cfw_(A,I),(B,H),(C,J),(D,G),(E,K),(F,J),(M,K) augmenting path relative to M A-I B-G
McMaster - CAS - 2c03
Question 5(a)a 1/18/1b 3/16/3g 12/13/9f 2/17/2c 4/15/4i 8/9/7e 7/10/6d 5/6/5h 11/14/8Tree edges are black, back edges are red, forward edges are green and cross edges are blue. The numbers in each vertex are (d[v ]/f [v ]/dfnumber[v ]). Question
McMaster - CAS - 2c03
Question 8 Assuming alphabetical ordering, the solution is:A 1/12 B 2/3 C 4/5O 28/29H 14/17I 15/16G 13/18 D 7/8 F 6/11 E 9/10 N 25/26J 19/30K 20/21L 22/27M 23/24Ordering by decreasing nishing times gives the topological sorting:JOLNMKGH
McMaster - CAS - 2c03
(c) Depth-rst spanning tree (costs ignored):a f51b2g c3 8i6e4d7h(d) Breadth-rst spanning tree (costs ignored):1a1 1 11b2g c2f i e2dhQuestion 10 We use the depth-rst spanning tree from question 9(c), and redraw it to highlight t
McMaster - CAS - 2c03
SE2C03. Sample solutions to the assignment 5. Total of this assignment is 75pts. 100% equals 65. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right
McMaster - CAS - 2c03
Question 1 Dijkstras algorithms works as follows if alphabetical ordering (as in the last assignment) is assumed. Edges are numbered in the order that they are added.3 a 0 1 f 5 2 e 10 d 7 7 c 7 6 i 14 9 h 9 8 b 6 4 g 12The array is as follows. [a] [b]
McMaster - CAS - 2c03
A3 =0 3 3 64 6 65 44 4 72 0 4 2 1 1 1 0 5 3 2 2 3 2 0 3 2 4 2 4 3 8 0 5 5 5 8 8 9 2 0 9 12 0 3 3 2 7 5 4 4 0 7 7 47 5 03 A4 =20 3 3 64 6 65 44 4 6 7 0 6 4 2 1 1 6 1 0 5 3 2 2 7 3 2 0 3 2 4 2 4 3 8 0 5 5 10 5 8 8 9 2 0 9 11 12 0 3 3 2
McMaster - CAS - 2c03
9v14 6 15 104v3817 4v54 8 96s5t152v212v43v69v14 6 12 104v3817 4v54 8 9 126s35 9 3t32v2v43v69v14 6 4 104v38 217 4v54 8 46s115 1 111 8 3t11v2v4v6No more augmenting paths exist, so we are done. Quest
McMaster - CAS - 2c03
CS2MD3. Sample solutions to the assignment 1. Total of this assignment is 132pts. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, and resubmit
McMaster - CAS - 2c03
2.[11] Using only definition of O(f(n) proof that the following statements are true: 1.[2] 7000n2n/(n2 + 3) = O(2n) Let c=1, n0=7000. For all n 7000, 7000n2n/(n2 + 3) 7000n2n/(7000n + 3) 2n. 2.[3] 100n32n + 6n23n = O(4n) Let c=106, n0=16=24. First n3 = 23
McMaster - CAS - 2c03
For all n n0, n*log (3/2) log c, then (3/2)n c. Hence, 3n = (3/2)n * 2n c*2n. d.[2] log n + n1/2 = O(log n) For all c 0, take n0 = c4. For all n n0, log n + n1/2 log c + n1/4*n1/4 log c + c*n1/4 c*log n hold.4.[12] Consider lists of integers. The lexicog
McMaster - CAS - 2c03
p1 := FIRST(L1); p2 := FIRST(L2); while (p1 &lt;&gt; END(L1) and p2 &lt;&gt; END(L2) do begin x1 := RETRIEVE(p1, L1); x2 := RETRIEVE(p2, L2); if (x1 &lt; x2) then return(true) else if (x1 &gt; x2) then return(false) else begin p1 := NEXT(p1, L1); p1 := NEXT(p1, L1) end end