-
Notifications
You must be signed in to change notification settings - Fork 54
/
DivideAndConquer.html
1382 lines (1297 loc) · 36.9 KB
/
DivideAndConquer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<!-- THIS FILE WAS GENERATED BY A SCRIPT: DO NOT EDIT IT! -->
<head>
<link href="style.css" rel="stylesheet" type="text/css"/>
<title>
Design and Analysis of Algorithms: Divide and Conquer
</title>
</head>
<body>
<div id="header">
<div id="logo">
<img src="graphics/Julia.png">
</div>
<div id="user-tools">
<a href="index.html">Home</a>
<a href="about.html">About</a>
<a href="feedback.html">Feedback</a>
</div>
</div>
<h1>
Design and Analysis of Algorithms: Divide and Conquer
</h1>
<div style="text-align:center">
<p>
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/45/Sierpinski_triangle.svg/250px-Sierpinski_triangle.svg.png">
</p>
</div>
<details>
<summary class="sum1">
Introduction
</summary>
<p>
What is this?
</p>
<ul>
<li><b>Divide</b> the problem into a number of sub problems that are
smaller instances of the same problem.
</li>
<li><b>Conquer</b> the sub problems by solving them recursively. If
the subproblem sizes are small enough, however, just solve
the subproblems in a straightforward manner.
</li>
<li><b>Combine</b> the solutions for the sub problems into the
solution for the original problem.
</li>
</ul>
<figure>
<iframe width="560" height="315"
src="https://www.youtube.com/embed/6SUmp_Cn-SU"
frameborder="0" allowfullscreen></iframe>
<figcaption>
Introduction to divide-and-conquer
</figcaption>
</figure>
<details>
<summary class="sum2">
Recurrences
</summary>
<p>
Merge sort recurrence:
<br>
<br>
<img src="graphics/RecEq1.gif">
<br>
<br>
We "solve" these by finding a closed-form equation that
describes the recurrence but without recursion.
<br>
<b>Solution</b>: T(n) = Θ(n lg n)
<br>
<br>
<b>Methods</b>:
<br>
</p>
<ul>
<li><b>Substitution method</b>: Guess a solution and then use
induction to prove it.
</li>
<li><b>Recursive-tree method</b>: Convert the recurrence into a
tree whose nodes represent costs incurred at each level.
</li>
<li><b>Master method</b>:
<br>
Solves recurrences of the form:
<br>
T(n) = aT(n / b) + f(n)
<br>
where a ≥ 1, b > 1.
</li>
</ul>
<p>
<br>
<b>Technicalities</b>
<br>
We often omit floors, ceilings, and boundary conditions. For
instance, if n is odd, we may say n / 2 anyway.
</p>
</details>
</details>
<details>
<summary class="sum1">
4.1 The maximum-subarray problem
</summary>
<p>
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/25/Maximum_Subarray_Visualization.svg/220px-Maximum_Subarray_Visualization.svg.png">
<br>
<br>
Only makes since in an array with both negative and positive
values: otherwise the answer is either the whole array or the
maximum member.
<br>
<br>
</p>
<details>
<summary class="sum2">
Brute-force solution
</summary>
<p>
Try every combination of two elements!
<br>
A n choose 2 problem, so order of Ω(n<sup>2</sup>).
<br>
n choose 2 will be about 1/2 n<sup>2</sup>, since it equals
n(n - 1) / 2. So we can establish a lower bound by setting c =
1/3, for instance, and n choose 2 will always be bounded from
below by c*n<sup>2</sup>.
</p>
</details>
<details>
<summary class="sum2">
A transformation
</summary>
<p>
We look at the problem differently: let's find the nonempty,
contiguous subarray of our array whose values have the largest sum.
We call this the <b>maximum subarray</b>.
</p>
</details>
<details>
<summary class="sum2">
A solution using divide-and-conquer
</summary>
<p>
To solve this problem, we divide an array A into three subarrays,
and ask what is the maximum subarray in each:
</p>
<ol>
<li>From A[low] to A[midpoint - 1].</li>
<li>Crossing the mid-point.</li>
<li>From A[midpoint + 1] to A[high]</li>
</ol>
<p>
Problems 1 and 3 are simply this same problem on a smaller array!
Problem 2 can be solved by finding the maximum subarrays in
low-to-mid and in mid+1-to-high.
<br>
<br>
The recurrence is the same as for merge sort.
</p>
</details>
<details>
<summary class="sum2">
Run the Python code
</summary>
<p>
In the console below, type or paste:
<br/>
<code>
!git clone https://gist.github.com/25ffc0600a866535adef05c5d8eca34a.git
<br/>
cd 25ffc0600a866535adef05c5d8eca34a
<br/>
from find_max_subarray import *
<br/>
A = [13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7]
<br/>
</code>
</p>
<div class="python-console">
<iframe style="width: 640; height: 480;"
name="embedded_python_anywhere"
src="https://www.pythonanywhere.com/embedded3/" scrolling="yes">
</iframe>
<figcaption>
Python console
</figcaption>
</div>
<p>
To run the example from the textbook, type:
<br/>
<code>
A
<br/>
find_max_subarray(A, 0, 15)
</code>
</p>
<p>
Now you can experiment with the algorithm by typing
in your own array (my_array = [x, y, z])
and running find_max_array(my_array).
</p>
</details>
<details>
<summary class="sum2">
Video on maximum subarray problem
</summary>
<figure>
<iframe width="560" height="315"
src="https://www.youtube.com/embed/OexQs_cYgAQ"
frameborder="0" allowfullscreen></iframe>
<figcaption>
Maximum sub-array video
</figcaption>
</figure>
</details>
<details>
<summary class="sum2">
Quiz
</summary>
<ol>
<li>
The problem with the brute force max-subarray solution is
</li>
<ol type="a" class="nested">
<li>
<input type="radio" name="q1" value="a">
it is too complicated
</li>
<li>
<input type="radio" name="q1" value="b">
the force used might break the code
</li>
<li>
<input type="radio" name="q1" value="c">
it is too slow
</li>
</ol>
<li>
The three possible arrays containing the maximum sequence are
</li>
<ol type="a" class="nested">
<li>
<input type="radio" name="q2" value="a">
An array of ints, an array of doubles, and an array of strings
</li>
<li>
<input type="radio" name="q2" value="b">
The array from A[0] to the mid-point; an array that crosses the midpoint, and the array from A[midpoint + 1] to the end
</li>
<li>
<input type="radio" name="q2" value="c">
The whole array, the null array, and the middle array
</li>
</ol>
<li>
What does FIND-MAXIMUM-SUBARRAY return when all elements of A are negative?
</li>
<ol type="a" class="nested">
<li>
<input type="radio" name="q3" value="a">
Largest Positive Number in A
</li>
<li>
<input type="radio" name="q3" value="b">
Largest Negative Number in A
</li>
<li>
<input type="radio" name="q3" value="c">
First index of A
</li>
<li>
<input type="radio" name="q3" value="d">
Lase index of A
</li>
</ol>
</ol>
<details>
<summary class="sum3">
Answers
</summary>
<p>
1. c; 2. b; 3. b;
</p>
</details>
</details>
</details>
<details>
<summary class="sum1">
4.2 Strassen's algorithm for matrix multiplication
</summary>
<details>
<summary class="sum2">
Recursive Square-Matrix Multiply
</summary>
<p>
We divide each of our initial matrices into four
sub-matrices, and multiply them. Which we do by dividing
each of them into four...
<br>
<br>
In the base case when each matrix has only one member, we
just multiply them and return the result.
<br>
<br>
So what is our recurrence? Each step except the base case
multiplies eight matrices of size n / 2. So they
contribute 8T(n / 2) to running time. There are also four
matrix additions of matrices containing n<sup>2</sup> / 4
entries -- squared because n specifies an n x n matrix. So
this contributes Θ(n<sup>2</sup>) time.
<br>
<br>
So our recurrence is:
<br>
<br>
<img src="graphics/RecEq6.gif">
<br>
<br>
The master method will show us that the solution to this
recurrence is:
<br>
T(n) = Θ(n<sup>3</sup>)
</p>
</details>
<details>
<summary class="sum2">
Run the Python code
</summary>
<p>
In the console below, type or paste:
<br/>
<code>
!git clone https://gist.github.com/87e1f86c634c1538062041ca153bc466.git
<br/>
cd 87e1f86c634c1538062041ca153bc466
<br/>
from divide_conquer_matrix import *
<br/>
A = [[1, 3], [7, 5]]
<br/>
B = [[6, 8], [4, 2]]
<br/>
</code>
</p>
<div class="python-console">
<iframe style="width: 640; height: 480;"
name="embedded_python_anywhere"
src="https://www.pythonanywhere.com/embedded3/" scrolling="yes">
</iframe>
<figcaption>
Python console
</figcaption>
</div>
<p>
To run the example from the textbook, type:
<br/>
<code>
A,B
<br/>
square_matrix_multiply(A, B)
<br/>
square_matrix_multiply_recursive(A, B)
</code>
</p>
<p>
Now you can experiment with the algorithm by typing
in your own Matrix (my_matrix = [x, y, z])
and running square_matrix_multiply(a_matrix, b_matrix) or
square_matrix_multiply_recursive(a_matrix, b_matrix).
</p>
</details>
<details>
<summary class="sum2">
Strassen's Algorithm
</summary>
<p>
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Strassen_algorithm.svg/800px-Strassen_algorithm.svg.png">
<br>
<br>
By adding ten additions, we can cut the divide portion of
our algorithm down to seven multiplications instead of
eight.
<br>
<br>
Let's try one!
<br>
<br>
Here is the method:
<br>
<br>
For two matrices:
<br>
<br>
<img src="graphics/RecEq8.gif">
<br>
<br>
Define:
<br>
<br>
P<sub>1</sub> = A(F - H)
<br>
P<sub>2</sub> = H(A + B)
<br>
P<sub>3</sub> = E(C + D)
<br>
P<sub>4</sub> = D(G - E)
<br>
P<sub>5</sub> = (A + D) * (E + H)
<br>
P<sub>6</sub> = (B - D) * (G + H)
<br>
P<sub>7</sub> = (A - C) * (E + F)
<br>
<br>
Then:
<br>
<br>
<img src="graphics/RecEq9.gif">
<br>
<br>
So let's try this example:
<br>
<br>
<img src="graphics/RecEq7.gif">
<br>
<br>
<b>Important Lesson</b>
<br>
<br>
There are often serious trade-offs between set-up time and
aymptotic run-time. One must carefully consider how large
one's inputs are likely to be before opting for a complex
algorithm like Strassen's. On modern hardware optimized for
matrix multiplication, matrix sizes often need to be in the
thousands before Strassen's algorithm yields significant
gains.
</p>
</details>
</details>
<details>
<summary class="sum1">
4.3 The substitution method for solving recurrences
</summary>
<p>
<b>Note:</b> I am presenting these three methods in my
notes in textbook order. But in lectures, I present the
substitution method last, because we can best make sense of
our "guess" for a solution if we understand the other two
methods first. I suggest students tackle recursion-tree,
then master method, and <i>then</i> substitution.
</p>
<details>
<summary class="sum2">
Towers of Hanoi
</summary>
<p>
Shared web material <a
href="https://gcallah.github.io/DiscreteMathematics/advcounting.html#Hanoi">located here</a>.
</p>
</details>
<details>
<summary class="sum2">
Another substitution-method problem
</summary>
<p>
Let's look at the recurrence:
<br>
T(n) = T(n/3) + T(2n/3) + <i>n</i>
<br>
T(0) = 1
<br>
T(1) = 1
<br>
<br>
This does not have the form the master method
requires. And if we sketch a recursion tree, not every
node is the same on a level, so it is different from
what we usually deal with there. But if we <i>do</i>
diagram a recursion tree, we will see that the work
looks constant at each level, like a master theorem
case 2. And since the function part of the equation is
f(n) = n, let's "guess":
<br>
T(n) ≤ cn log <i>n</i>
<br>
<br>
But that is just our hunch: we have to prove it!
<br>
<br>
Let's look at base cases for our inductive proof.
Use floors for divisions! Is:
</p>
<ul>
<li>T(0) ≤ c(0 * log 0) --> nonsense! (There is no log 0.)
<br>
</li>
<li>T(1) ≤ c(1 * log 1) --> false! (There is no such c.)
<br>
</li>
<li>T(2) ≤ c(2 * log 2) --> true!
<br>
T(2) = T(floor(2/3)) + T(floor(4/3)) + 2 = 1 + 1 + 2 ≤
c(2 * log 2) = c(2 * 1)
<br>
So if we set c = 2 (or greater) the inequality holds.
</li>
</ul>
<p>
How many base cases do we need to examine? We will see!
<br>
But we can prove it for any given "small" n > 2 by
setting:
<br>
c ≥ T(n) / n log <i>n</i>
</p>
<p>
<b>Recursion step:</b>
<br>
We assume that for k where:
<br>
2 ≤ k < <i>n</i>
<br>
the claim is true.
<br>
Now, we need to show that if for sub-problems smaller
than n the claim is true, then it is true for n.
</p>
</details>
</details>
<details>
<summary class="sum1">
4.4 The recursion-tree method for solving recurrences
</summary>
<p>
There are two ways to use this method:
</p>
<ol>
<li>As a way to generate a guess for the substitution
method.
</li>
<li>As a way to generate a rigorous answer by itself.
</li>
</ol>
<p>
Analyze the tree:
<br>
<br>
<img
src="graphics/NSquaredTree1.png">
<br>
<br>
Calculate the work at each level:
<br>
<br>
<img
src="graphics/NSquaredTree2.png">
<br>
<br>
This produces the geometric series:
<br>
<br>
<img src="graphics/RecEq4.gif">
<br>
<br>
If we set <i>a</i> = <i>n</i><sup>2</sup>
and <i>r</i> = 1/2, then we have the
general sum of a converging geometric series:
<br>
<br>
<img src="graphics/RecEq5.gif">
<br>
<br>
So the solution here is O(<i>n</i><sup>2</sup>). The amount of work at
each level is reduced by a power of two, and so is
just a constant factor times the root.
<br>
<br>
<b>Consider these three examples</b>:
</p>
<ol>
<li>
<i>T</i>(<i>n</i>) = 4<i>T</i>(<i>n</i>/2) + <i>cn</i>
</li>
<li>
<i>T</i>(<i>n</i>) = 2<i>T</i>(<i>n</i>/2) + <i>cn</i>
</li>
<li>
<i>T</i>(<i>n</i>) = 2<i>T</i>(<i>n</i>/2) + <i>cn</i><sup>2</sup>
<br>
(This is the recurrence in the diagram above.)
</li>
</ol>
<p>
(We assume <i>c</i> > 0.)
<br>
Let's break down these cases:
</p>
<table>
<tr>
<th colspan="4">
<b><i>T</i>(<i>n</i>) = 4<i>T</i>(<i>n</i>/2)
+ <i>cn</i><sup>1</sup></b>
</th>
</tr>
<tr>
<th>
Level
</th>
<th>
# Nodes
</th>
<th>
Work at
<br>
Node
</th>
<th>
Work at
<br>
Level
</th>
</tr>
<tr>
<td>
0
</td>
<td>
1
</td>
<td>
<i>n</i>
</td>
<td>
<i>n</i>
</td>
</tr>
<tr>
<td>
1
</td>
<td>
4
</td>
<td>
<i>n</i>/2
</td>
<td>
2<i>n</i>
</td>
</tr>
<tr>
<td>
2
</td>
<td>
16
</td>
<td>
<i>n</i>/4
</td>
<td>
4<i>n</i>
</td>
</tr>
<tr>
<td>
3
</td>
<td>
64
</td>
<td>
<i>n</i>/8
</td>
<td>
8<i>n</i>
</td>
</tr>
<tr>
<td>
<i>i</i>
</td>
<td>
4<sup><i>i</i></sup>
</td>
<td>
<i>n</i>/2<sup><i>i</i></sup>
</td>
<td>
2<sup><i>i</i></sup><i>n</i>
</td>
</tr>
<tr>
<td>
<i>h</i> =
<br>
log<sub>2</sub><i>n</i>
</td>
<td>
4<sup><i>h</i></sup>
</td>
<td>
<i>T</i>(1)
</td>
<td>
4<sup><i>h</i></sup><i>T</i>(1)
</td>
</tr>
</table>
<p>
The runtime then is:
<br>
<img src="graphics/4TRec.gif">
<br>
<i>h</i> = log<sub>2</sub><i>n</i>
<br>
so the first part equals:
<br>
4<sup>log<sub>2</sub><i>n</i></sup>
= <i>n</i><sup>log<sub>2</sub>4</sup>
<br>
We pull out the n from the sum and it is
an increasing geometric series
that evaluates to <i>n</i> − 1.
So the closed form for the recurrence is:
<br>
<i>n</i><sup>2</sup><i>T</i>(1) + <i>n</i>(<i>n</i> - 1)
<br>
<br>
The very last level dominates, as it already has
O(<i>n</i><sup>2</sup>) complexity.
</p>
<hr>
<table>
<tr>
<th colspan="4">
<b><i>T</i>(<i>n</i>) = 2<i>T</i>(<i>n</i>/2)
+ <i>cn</i><sup>1</sup></b>
</th>
</tr>
<tr>
<th>
Level
</th>
<th>
# Nodes
</th>
<th>
Equ. for
<br>
Node
</th>
<th>
Work
</th>
</tr>
<tr>
<td>
0
</td>
<td>
1
</td>
<td>
<i>n</i>
</td>
<td>
<i>cn</i>
</td>
</tr>
<tr>
<td>
1
</td>
<td>
2
</td>
<td>
<i>n</i>/2
</td>
<td>
<i>cn</i>
</td>
</tr>
<tr>
<td>
2
</td>
<td>
4
</td>
<td>
<i>n</i>/4
</td>
<td>
<i>cn</i>
</td>
</tr>
<tr>
<td>
3
</td>
<td>
8
</td>
<td>
<i>n</i>/8
</td>
<td>
<i>cn</i>
</td>
</tr>
<tr>
<td>
<i>i</i>
</td>
<td>
2<sup><i>i</i></sup>
</td>
<td>
<i>n</i>/2<sup><i>i</i></sup>
</td>
<td>
<i>cn</i>
</td>
</tr>
<tr>
<td>
<i>h</i> =
<br>
log<sub>2</sub> <i>n</i>
</td>
<td>
2<sup><i>h</i></sup>
</td>
<td>
<i>T</i>(1)
</td>
<td>
2<sup><i>h</i></sup><i>T</i>(1)
</td>
</tr>
</table>
<p>
And so we get:
<br>
<img src="graphics/EqCaseRec.gif">
<br>
2<sup><i>h</i></sup> = <i>n</i>.
<br>
The sum happens log <i>n</i> times, so we have <i>cn</i> * log <i>n</i>.
<br>
<br>
All levels contribute equally.
</p>
<hr>
<table>
<tr>
<th colspan="4">
<b><i>T</i>(<i>n</i>) = 2<i>T</i>(<i>n</i>/2)
+ <i>cn</i><sup>2</sup></b>
</th>
</tr>
<tr>
<th>
Level
</th>
<th>
# Nodes
</th>
<th>
Equ. for
<br>
Node
</th>
<th>
Work
</th>
</tr>
<tr>
<td>
0
</td>
<td>
1
</td>
<td>
n<sup>2</sup>
</td>
<td>
n<sup>2</sup>
</td>
</tr>
<tr>
<td>
1
</td>
<td>
2
</td>
<td>
(<i>n</i>/2)<sup>2</sup>
</td>
<td>
<i>n</i><sup>2</sup>/2
</td>
</tr>
<tr>
<td>
2
</td>
<td>
4
</td>
<td>
(<i>n</i>/4)<sup>2</sup>
</td>
<td>
<i>n</i><sup>2</sup>/4
</td>
</tr>
<tr>
<td>
3
</td>
<td>
8
</td>
<td>
(<i>n</i>/8)<sup>2</sup>
</td>