-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.ps
1136 lines (1074 loc) · 36.5 KB
/
readme.ps
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
%!PS-Adobe-3.0
%%BoundingBox: 25 25 587 767
%%Title: Enscript Output
%%For: Jonathan R. Shewchuk
%%Creator: GNU enscript 1.6.4
%%CreationDate: Mon Apr 15 23:06:07 2013
%%Orientation: Landscape
%%Pages: (atend)
%%DocumentMedia: Letter 612 792 0 () ()
%%DocumentNeededResources: (atend)
%%EndComments
%%BeginProlog
%%BeginResource: procset Enscript-Prolog 1.6 4
%
% Procedures.
%
/_S { % save current state
/_s save def
} def
/_R { % restore from saved state
_s restore
} def
/S { % showpage protecting gstate
gsave
showpage
grestore
} bind def
/MF { % fontname newfontname -> - make a new encoded font
/newfontname exch def
/fontname exch def
/fontdict fontname findfont def
/newfont fontdict maxlength dict def
fontdict {
exch
dup /FID eq {
% skip FID pair
pop pop
} {
% copy to the new font dictionary
exch newfont 3 1 roll put
} ifelse
} forall
newfont /FontName newfontname put
% insert only valid encoding vectors
encoding_vector length 256 eq {
newfont /Encoding encoding_vector put
} if
newfontname newfont definefont pop
} def
/MF_PS { % fontname newfontname -> - make a new font preserving its enc
/newfontname exch def
/fontname exch def
/fontdict fontname findfont def
/newfont fontdict maxlength dict def
fontdict {
exch
dup /FID eq {
% skip FID pair
pop pop
} {
% copy to the new font dictionary
exch newfont 3 1 roll put
} ifelse
} forall
newfont /FontName newfontname put
newfontname newfont definefont pop
} def
/SF { % fontname width height -> - set a new font
/height exch def
/width exch def
findfont
[width 0 0 height 0 0] makefont setfont
} def
/SUF { % fontname width height -> - set a new user font
/height exch def
/width exch def
/F-gs-user-font MF
/F-gs-user-font width height SF
} def
/SUF_PS { % fontname width height -> - set a new user font preserving its enc
/height exch def
/width exch def
/F-gs-user-font MF_PS
/F-gs-user-font width height SF
} def
/M {moveto} bind def
/s {show} bind def
/Box { % x y w h -> - define box path
/d_h exch def /d_w exch def /d_y exch def /d_x exch def
d_x d_y moveto
d_w 0 rlineto
0 d_h rlineto
d_w neg 0 rlineto
closepath
} def
/bgs { % x y height blskip gray str -> - show string with bg color
/str exch def
/gray exch def
/blskip exch def
/height exch def
/y exch def
/x exch def
gsave
x y blskip sub str stringwidth pop height Box
gray setgray
fill
grestore
x y M str s
} def
/bgcs { % x y height blskip red green blue str -> - show string with bg color
/str exch def
/blue exch def
/green exch def
/red exch def
/blskip exch def
/height exch def
/y exch def
/x exch def
gsave
x y blskip sub str stringwidth pop height Box
red green blue setrgbcolor
fill
grestore
x y M str s
} def
% Highlight bars.
/highlight_bars { % nlines lineheight output_y_margin gray -> -
gsave
setgray
/ymarg exch def
/lineheight exch def
/nlines exch def
% This 2 is just a magic number to sync highlight lines to text.
0 d_header_y ymarg sub 2 sub translate
/cw d_output_w cols div def
/nrows d_output_h ymarg 2 mul sub lineheight div cvi def
% for each column
0 1 cols 1 sub {
cw mul /xp exch def
% for each rows
0 1 nrows 1 sub {
/rn exch def
rn lineheight mul neg /yp exch def
rn nlines idiv 2 mod 0 eq {
% Draw highlight bar. 4 is just a magic indentation.
xp 4 add yp cw 8 sub lineheight neg Box fill
} if
} for
} for
grestore
} def
% Line highlight bar.
/line_highlight { % x y width height gray -> -
gsave
/gray exch def
Box gray setgray fill
grestore
} def
% Column separator lines.
/column_lines {
gsave
.1 setlinewidth
0 d_footer_h translate
/cw d_output_w cols div def
1 1 cols 1 sub {
cw mul 0 moveto
0 d_output_h rlineto stroke
} for
grestore
} def
% Column borders.
/column_borders {
gsave
.1 setlinewidth
0 d_footer_h moveto
0 d_output_h rlineto
d_output_w 0 rlineto
0 d_output_h neg rlineto
closepath stroke
grestore
} def
% Do the actual underlay drawing
/draw_underlay {
ul_style 0 eq {
ul_str true charpath stroke
} {
ul_str show
} ifelse
} def
% Underlay
/underlay { % - -> -
gsave
0 d_page_h translate
d_page_h neg d_page_w atan rotate
ul_gray setgray
ul_font setfont
/dw d_page_h dup mul d_page_w dup mul add sqrt def
ul_str stringwidth pop dw exch sub 2 div ul_h_ptsize -2 div moveto
draw_underlay
grestore
} def
/user_underlay { % - -> -
gsave
ul_x ul_y translate
ul_angle rotate
ul_gray setgray
ul_font setfont
0 0 ul_h_ptsize 2 div sub moveto
draw_underlay
grestore
} def
% Page prefeed
/page_prefeed { % bool -> -
statusdict /prefeed known {
statusdict exch /prefeed exch put
} {
pop
} ifelse
} def
% Wrapped line markers
/wrapped_line_mark { % x y charwith charheight type -> -
/type exch def
/h exch def
/w exch def
/y exch def
/x exch def
type 2 eq {
% Black boxes (like TeX does)
gsave
0 setlinewidth
x w 4 div add y M
0 h rlineto w 2 div 0 rlineto 0 h neg rlineto
closepath fill
grestore
} {
type 3 eq {
% Small arrows
gsave
.2 setlinewidth
x w 2 div add y h 2 div add M
w 4 div 0 rlineto
x w 4 div add y lineto stroke
x w 4 div add w 8 div add y h 4 div add M
x w 4 div add y lineto
w 4 div h 8 div rlineto stroke
grestore
} {
% do nothing
} ifelse
} ifelse
} def
% EPSF import.
/BeginEPSF {
/b4_Inc_state save def % Save state for cleanup
/dict_count countdictstack def % Count objects on dict stack
/op_count count 1 sub def % Count objects on operand stack
userdict begin
/showpage { } def
0 setgray 0 setlinecap
1 setlinewidth 0 setlinejoin
10 setmiterlimit [ ] 0 setdash newpath
/languagelevel where {
pop languagelevel
1 ne {
false setstrokeadjust false setoverprint
} if
} if
} bind def
/EndEPSF {
count op_count sub { pos } repeat % Clean up stacks
countdictstack dict_count sub { end } repeat
b4_Inc_state restore
} bind def
% Check PostScript language level.
/languagelevel where {
pop /gs_languagelevel languagelevel def
} {
/gs_languagelevel 1 def
} ifelse
%%EndResource
%%BeginResource: procset Enscript-Encoding-88591 1.6 4
/encoding_vector [
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/space /exclam /quotedbl /numbersign
/dollar /percent /ampersand /quoteright
/parenleft /parenright /asterisk /plus
/comma /hyphen /period /slash
/zero /one /two /three
/four /five /six /seven
/eight /nine /colon /semicolon
/less /equal /greater /question
/at /A /B /C
/D /E /F /G
/H /I /J /K
/L /M /N /O
/P /Q /R /S
/T /U /V /W
/X /Y /Z /bracketleft
/backslash /bracketright /asciicircum /underscore
/quoteleft /a /b /c
/d /e /f /g
/h /i /j /k
/l /m /n /o
/p /q /r /s
/t /u /v /w
/x /y /z /braceleft
/bar /braceright /tilde /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef
/space /exclamdown /cent /sterling
/currency /yen /brokenbar /section
/dieresis /copyright /ordfeminine /guillemotleft
/logicalnot /hyphen /registered /macron
/degree /plusminus /twosuperior /threesuperior
/acute /mu /paragraph /bullet
/cedilla /onesuperior /ordmasculine /guillemotright
/onequarter /onehalf /threequarters /questiondown
/Agrave /Aacute /Acircumflex /Atilde
/Adieresis /Aring /AE /Ccedilla
/Egrave /Eacute /Ecircumflex /Edieresis
/Igrave /Iacute /Icircumflex /Idieresis
/Eth /Ntilde /Ograve /Oacute
/Ocircumflex /Otilde /Odieresis /multiply
/Oslash /Ugrave /Uacute /Ucircumflex
/Udieresis /Yacute /Thorn /germandbls
/agrave /aacute /acircumflex /atilde
/adieresis /aring /ae /ccedilla
/egrave /eacute /ecircumflex /edieresis
/igrave /iacute /icircumflex /idieresis
/eth /ntilde /ograve /oacute
/ocircumflex /otilde /odieresis /divide
/oslash /ugrave /uacute /ucircumflex
/udieresis /yacute /thorn /ydieresis
] def
%%EndResource
%%EndProlog
%%BeginSetup
%%IncludeResource: font Courier-Bold
%%IncludeResource: font Courier
/HFpt_w 10 def
/HFpt_h 10 def
/Courier-Bold /HF-gs-font MF
/HF /HF-gs-font findfont [HFpt_w 0 0 HFpt_h 0 0] makefont def
/Courier /F-gs-font MF
/F-gs-font 7 7 SF
/#copies 1 def
% Pagedevice definitions:
gs_languagelevel 1 gt {
<<
/PageSize [612 792]
>> setpagedevice
} if
%%BeginResource: procset Enscript-Header-enscript 1.6 4
%%IncludeResource: font Times-Bold
%%IncludeResource: font Times-Roman
% Fonts.
/Times-Bold /HeaderFont-Bold MF
/HeaderDateF /HeaderFont-Bold findfont 12 scalefont def
/Times-Roman /HeaderFont-Times MF
/HeaderHDRF /HeaderFont-Times findfont 14 scalefont def
/HeaderPageNumF /Helvetica-Bold findfont 28.8 scalefont def
/do_header { % print enscript header
gsave
d_header_x d_header_y translate
% light bar
0 0 d_header_w d_header_h 2 div Box
.95 setgray fill
% dark gray boxes
/dbw d_header_h 2 mul def % dark box width
/dbc .7 def % dark box color
% left dark box.
0 0 dbw d_header_h Box
dbc setgray fill
0 setgray
HeaderDateF setfont
moddatestr dup stringwidth pop dbw exch sub 2 div
d_header_h 2 div 2 add moveto show
modtimestr dup stringwidth pop dbw exch sub 2 div
d_header_h 5 div moveto show
% right dark box
d_header_w dbw sub 0 dbw d_header_h Box
dbc setgray fill
HeaderPageNumF setfont
1 setgray
pagenumstr dup
stringwidth pop dbw exch sub 2 div d_header_w dbw sub add
d_header_h .2 mul moveto show
% filename
0 setgray
HeaderHDRF setfont
d_header_w fname stringwidth pop sub 2 div d_header_h 8 div moveto
fname show
% user supplied header string.
user_header_p {
/h d_header_h 8 div 5 mul def
% Implement strict enscript compatibility.
user_header_center_str () eq user_header_right_str () eq and {
d_header_w user_header_left_str stringwidth pop sub 2 div
h moveto user_header_left_str show
} {
dbw 5 add h moveto user_header_left_str show
d_header_w user_header_center_str stringwidth pop sub 2 div
h moveto user_header_center_str show
d_header_w dbw sub 5 sub user_header_right_str stringwidth pop
sub h moveto user_header_right_str show
} ifelse
} if
grestore
} def
%%EndResource
/d_page_w 742 def
/d_page_h 562 def
/d_header_x 0 def
/d_header_y 526 def
/d_header_w 742 def
/d_header_h 36 def
/d_footer_x 0 def
/d_footer_y 0 def
/d_footer_w 742 def
/d_footer_h 0 def
/d_output_w 742 def
/d_output_h 526 def
/cols 2 def
%%EndSetup
%%Page: (1) 1
%%BeginPageSetup
_S
90 rotate
25 -587 translate
/pagenum 1 def
/fname (readme) def
/fdir () def
/ftail (readme) def
% User defined strings:
/pagenumstr (1) def
/moddatestr (04/15/13) def
/modtimestr (23:05:56) def
/user_header_p false def
/user_footer_p false def
%%EndPageSetup
column_lines
do_header
5 516 M
( CS 61B Project 3) s
5 508 M
( Weighted Undirected Graphs and Minimum Spanning Trees) s
5 500 M
( Due 5:30 pm Friday, May 3, 2013) s
5 484 M
(This is a team project. Form a team of 2 or 3 people. No teams of 1 or teams) s
5 476 M
(of 4 or more are allowed.) s
5 460 M
(Copy the Project 3 directory by doing the following, starting from your home) s
5 452 M
(directory.) s
5 436 M
( cp -r ~cs61b/hw/pj3 .) s
5 420 M
(A figure accompanies this "readme" as the files pj3graph.ps \(PostScript\) or) s
5 412 M
(pj3graph.pdf \(PDF\). Both files are the same figure.) s
5 396 M
(The purpose of this project is to become comfortable with applications that) s
5 388 M
(combine a variety of data structures and algorithms in a big ol' mess of) s
5 380 M
(references pointing just every which way. I'm not even kidding.) s
5 364 M
(Part I: Implement a Weighted Undirected Graph) s
5 356 M
(==============================================) s
5 348 M
(Implement a well-encapsulated ADT called WUGraph in a package called graph.) s
5 340 M
(A WUGraph represents a weighted, undirected graph in which self-edges are) s
5 332 M
(allowed. Any object whatsoever can serve as a vertex of a WUGraph.) s
5 316 M
(For maximum speed, you must store edges in two data structures: unordered) s
5 308 M
(doubly-linked adjacency lists and a hash table. You are expected to support) s
5 300 M
(the following public methods in the running times specified. \(You may ignore) s
5 292 M
(hash table resizing time when trying to achieve a specified running time--but) s
5 284 M
(your hash table should resize itself when necessary to keep the load factor) s
5 276 M
(constant.\) Below, |V| is the number of vertices in the graph, and d is the) s
5 268 M
(degree of the vertex in question.) s
5 244 M
(O\(1\) WUGraph\(\); construct a graph having no vertices or edges.) s
5 236 M
(O\(1\) int vertexCount\(\); return the number of vertices in the graph.) s
5 228 M
(O\(1\) int edgeCount\(\); return the number of edges in the graph.) s
5 220 M
(O\(|V|\) Object[] getVertices\(\); return an array of all the vertices.) s
5 212 M
(O\(1\) void addVertex\(Object\); add a vertex to the graph.) s
5 204 M
(O\(d\) void removeVertex\(Object\); remove a vertex from the graph.) s
5 196 M
(O\(1\) boolean isVertex\(Object\); is this object a vertex of the graph?) s
5 188 M
(O\(1\) int degree\(Object\); return the degree of a vertex.) s
5 180 M
(O\(d\) Neighbors getNeighbors\(Object\); return the neighbors of a vertex.) s
5 172 M
(O\(1\) void addEdge\(Object, Object, int\); add an edge of specified weight.) s
5 164 M
(O\(1\) void removeEdge\(Object, Object\); remove an edge from the graph.) s
5 156 M
(O\(1\) boolean isEdge\(Object, Object\); is this edge in the graph?) s
5 148 M
(O\(1\) int weight\(Object, Object\); return the weight of this edge.) s
5 124 M
(A "neighbor" of a vertex is any vertex connected to it by an edge. See the) s
5 116 M
(file graph/WUGraph.java for details of exactly how each of these methods should) s
5 108 M
(behave.) s
5 92 M
(Here are some of the design elements that will help achieve these goals.) s
5 76 M
([1] A calling application can use any object whatsoever to be a "vertex" from) s
5 68 M
( its point of view. You will also need to have an internal object that) s
5 60 M
( represents a vertex in a WUGraph and maintains its adjacency list; this) s
5 52 M
( object is HIDDEN from the application. Therefore, you will need a fast) s
5 44 M
( way to map the application's vertex objects to your internal vertex) s
5 36 M
( objects. The best way to do this is to use the hash table you implemented) s
5 28 M
( for Homework 6--modified so it resizes itself to keep the load factor) s
5 20 M
( constant as |V| changes. \(You may NOT use Java's built-in hash tables.\)) s
5 12 M
( The hash table also makes it possible to support isVertex\(\) in O\(1\) time.) s
376 516 M
( In Java, every object has a hashCode\(\) method. The default hashCode\(\)) s
376 508 M
( is defined in the Object class, and hashes the _reference_ to the Object.) s
376 500 M
( \(This is not something you could do yourself, because Java does not give) s
376 492 M
( you direct access to memory addresses.\) This means that for some classes,) s
376 484 M
( two distinct objects can act as different keys, even if their fields are) s
376 476 M
( identical. However, many object classes such as Integer and String) s
376 468 M
( override hashCode\(\) so that items with the same fields are equals\(\).) s
376 460 M
( Recall that Java has a convention that if two objects are equals\(\), they) s
376 452 M
( have the same hash code; defying this convention tends to break hash) s
376 444 M
( tables badly. For the purposes of this project, two objects provided by) s
376 436 M
( the calling application represent the same vertex if they are equals\(\).) s
376 420 M
([2] To support getVertices\(\) in O\(|V|\) time, you will need to maintain a list) s
376 412 M
( of vertices. To support removeVertex\(\) in O\(d\) time, the list of vertices) s
376 404 M
( should be doubly-linked. getVertices\(\) returns the objects that were) s
376 396 M
( provided by the calling application in calls to addVertex\(\), NOT the) s
376 388 M
( WUGraph's internal vertex data structure\(s\), which should always be) s
376 380 M
( hidden. Hence, each internal vertex representation must include) s
376 372 M
( a reference to the corresponding object that the calling application is) s
376 364 M
( using as a vertex.) s
376 348 M
( Alternatively, you could implement getVertices\(\) by traversing your hash) s
376 340 M
( table. However, this runs in O\(|V|\) time ONLY if your hash table resizes) s
376 332 M
( in both directions--specifically, it must shrink when the load factor) s
376 324 M
( drops below a constant. Otherwise, it will run too slowly if we add many) s
376 316 M
( vertices to a graph \(causing your table to grow very large\) then remove) s
376 308 M
( most of them.) s
376 292 M
([3] To support getNeighbors\(\) in O\(d\) time, you will need to maintain an) s
376 284 M
( adjacency list of edges for each vertex. To support removeEdge\(\) in O\(1\)) s
376 276 M
( time, each list of edges must be doubly-linked.) s
376 260 M
([4] Because a WUGraph is undirected, each edge \(u, v\) must appear in two) s
376 252 M
( adjacency lists \(unless u == v\): u's and v's. If we remove u from the) s
376 244 M
( graph, we must remove every edge incident on u from the adjacency lists) s
376 236 M
( of u's neighbors. To support removeVertex\(\) in O\(d\) time, we cannot walk) s
376 228 M
( through all these adjacency lists. There are several ways you could) s
376 220 M
( obtain O\(d\) time, and you may use any of these options:) s
376 204 M
( [i] Since \(u, v\) appears in two lists, we could use two nodes to) s
376 196 M
( represent \(u, v\); one in u's list, and one in v's list.) s
376 188 M
( Each of these nodes might be called a "half-edge," and each is) s
376 180 M
( the other's "partner." Each half-edge has forward and backward) s
376 172 M
( references to link it into an adjacency list. Each half-edge) s
376 164 M
( also maintains a reference to its partner. That way, when we) s
376 156 M
( remove u from the graph, we can traverse u's adjacency list and) s
376 148 M
( use the partner references to find and remove each half-edge's) s
376 140 M
( partner from the adjacency lists of u's neighbors in O\(1\) time) s
376 132 M
( per edge. This option is illustrated in the accompanying) s
376 124 M
( figure, pj3graph.ps or pj3graph.pdf \(both figures are the same\).) s
376 116 M
( [ii] You could use just one object to represent \(u, v\), but equip it) s
376 108 M
( with two forward and two backward references. However, you must) s
376 100 M
( be careful to follow the right references as you traverse) s
376 92 M
( a node's adjacency list.) s
376 84 M
( [iii] If you want to use an encapsulated DList class, you could use) s
376 76 M
( just a single object to represent an edge, and put this object) s
376 68 M
( into both adjacency lists. The edge object contains two) s
376 60 M
( DListNode references \(signifying its position in each DList\), so) s
376 52 M
( it can extract itself from both adjacency lists in O\(1\) time.) s
376 36 M
([5] To support removeEdge\(\), isEdge\(\), and weight\(\) in O\(1\) time, you will) s
376 28 M
( need a _second_ hash table for edges. The second hash table maps an) s
376 20 M
( unordered pair of objects \(both representing application-supplied vertices) s
376 12 M
( in the graph\) to your internal edge data structure. \(If you are using) s
376 4 M
( half-edges, following suggestion [4i] above, you could use the reference) s
_R
S
%%Page: (2) 2
%%BeginPageSetup
_S
90 rotate
25 -587 translate
/pagenum 2 def
/fname (readme) def
/fdir () def
/ftail (readme) def
% User defined strings:
/pagenumstr (2) def
/moddatestr (04/15/13) def
/modtimestr (23:05:56) def
/user_header_p false def
/user_footer_p false def
%%EndPageSetup
column_lines
do_header
5 516 M
( from one half-edge to find the other.\) To help you hash an edge in a) s
5 508 M
( manner that does not depend on the order of the two vertices, I have) s
5 500 M
( provided a class VertexPair.java designed for use as a key in hash tables.) s
5 492 M
( The methods VertexPair.hashCode and VertexPair.equals are written so that) s
5 484 M
( \(u, v\) and \(v, u\) are considered to be equal keys with the same hash code.) s
5 476 M
( Read them, but don't change them unless you know what you're doing.) s
5 468 M
( We recommend you use the VertexPair class as the key for your edge hash) s
5 460 M
( table. However, you are not required to do so, and you may change) s
5 452 M
( VertexPair.java freely to suit your needs.) s
5 436 M
( \(Technically, you don't need a second hash table; you could store vertices) s
5 428 M
( and edges in the same table. However, you risk confusing yourself; having) s
5 420 M
( two separate hash tables eases debugging and reduces the likelihood of) s
5 412 M
( human error. But it's your decision.\)) s
5 396 M
( To support removeVertex\(\) in O\(d\) time, you will need to remove the edges) s
5 388 M
( incident on a vertex from the hash table as well as the adjacency lists.) s
5 380 M
( You will also need to adjust the vertex degrees. Hence, each edge or) s
5 372 M
( half-edge should have references to the vertices it is incident on.) s
5 356 M
([6] To support vertexCount\(\), edgeCount\(\), and degree\(\) in O\(1\) time, you will) s
5 348 M
( need to maintain counts of the vertices, the edges, and the degree of each) s
5 340 M
( vertex, and keep these counts updated with every operation.) s
5 324 M
(For those of you who are keeping score, my own Part I solution is 350 lines) s
5 316 M
(long, not counting the hash table code.) s
5 300 M
(Interfaces) s
5 292 M
(----------) s
5 284 M
(You may NOT change Neighbors.java or the signatures and behavior of) s
5 276 M
(WUGraph.java. We will test that your WUGraph class correctly implements the) s
5 268 M
(interface we have specified.) s
5 252 M
(Neighbors.java is a class provided so the method WUGraph.getNeighbors\(\) can) s
5 244 M
(return two arrays at once. That is its only purpose. It is not appropriate to) s
5 236 M
(use the Neighbors class for any other purpose. You CANNOT change it, because) s
5 228 M
(it is part of the interface of getNeighbors\(\), and calling programs \(including) s
5 220 M
(the autograder\) are relying on you to return Neighbors objects according to) s
5 212 M
(spec. It appears as follows:) s
5 196 M
( public class Neighbors {) s
5 188 M
( public Object[] neighborList;) s
5 180 M
( public int[] weightList;) s
5 172 M
( }) s
5 156 M
(Given an input vertex, getNeighbors\(\) returns a Neighbors object. neighborList) s
5 148 M
(is a list of all the vertices \(application-provided objects, not internal) s
5 140 M
(vertex representations\) connected by an edge to the input vertex \(including the) s
5 132 M
(input vertex itself if it has a self-edge\). weightList lists the weight of) s
5 124 M
(each edge. The length of both lists is the degree of the input vertex.) s
5 116 M
(getNeighbors\(\) should construct and return a _new_ Neighbors object each time) s
5 108 M
(it is called.) s
5 92 M
(Your WUGraph should be well-encapsulated: no internal field or class used to) s
5 84 M
(represent your graph should be public. The Neighbors class is public because) s
5 76 M
(it's part of the interface of the WUGraph ADT, and it's not part of the) s
5 68 M
(internal representation of your graph.) s
376 508 M
(Part II: Kruskal's Algorithm for Minimum Spanning Trees) s
376 500 M
(========================================================) s
376 492 M
(Implement Kruskal's algorithm for finding the minimum spanning tree of a graph.) s
376 484 M
(Minimum spanning trees, and Kruskal's algorithm for constructing them, are) s
376 476 M
(discussed by Goodrich and Tamassia, Sections 13.6-13.6.1. Your algorithm) s
376 468 M
(should be embodied in a static method called minSpanTree\(\) in a class called) s
376 460 M
(Kruskal, which is NOT in the graph package. Your minSpanTree\(\) method should) s
376 452 M
(not violate the encapsulation of the WUGraph ADT, and should only access a) s
376 444 M
(WUGraph by calling the methods listed in Part I. You may NOT add any public) s
376 436 M
(methods to the WUGraph class to make Part II easier \(e.g., a method that) s
376 428 M
(returns all the edges in a WUGraph\). Remember the encapsulation rule: your) s
376 420 M
(Kruskal code should work correctly with the WUGraph code of any other group) s
376 412 M
(taking CS 61B, and your WUGraph code should work with their Kruskal code.) s
376 396 M
(The signature of minSpanTree\(\) is:) s
376 380 M
( public static WUGraph minSpanTree\(WUGraph g\);) s
376 364 M
(This method takes a WUGraph g and returns another WUGraph that represents the) s
376 356 M
(minimum spanning tree of g. The original WUGraph g is NOT changed! Let G be) s
376 348 M
(the graph represented by the WUGraph g. Your implementation should run in) s
376 340 M
(O\(|V| + |E| log |E|\) time, where |V| is the number of vertices in G, and |E| is) s
376 332 M
(the number of edges in G.) s
376 316 M
(Kruskal's algorithm works as follows.) s
376 300 M
([1] Create a new graph T having the same vertices as G, but no edges \(yet\).) s
376 292 M
( Upon completion, T will be the minimum spanning tree of G.) s
376 276 M
([2] Make a list \(not necessarily linked\) of all the edges in G. You cannot) s
376 268 M
( build this list by calling isEdge\(\) on every pair of vertices, because) s
376 260 M
( that would take O\(|V|^2\) time. You will need to use multiple calls to) s
376 252 M
( getNeighbors\(\) to obtain the complete list of edges.) s
376 236 M
( Note that your edge data structure should be defined separately from any) s
376 228 M
( edge data structure you use in WUGraph.java \(Part I\). Encapsulation) s
376 220 M
( requires that the internal data structures of the WUGraph class not be) s
376 212 M
( exposed to applications \(including Kruskal\).) s
376 196 M
([3] Sort the edges by weight in O\(|E| log |E|\) time. You may write the) s
376 188 M
( sorting algorithm yourself or use one from lab, but do not use a Java) s
376 180 M
( library sorting method. \(You can instead use a priority queue, as) s
376 172 M
( Goodrich and Tamassia suggest, but sorting in advance is more) s
376 164 M
( straightforward and is probably faster.\)) s
376 148 M
([4] Finally, find the edges of T using disjoint sets, as described in Lecture) s
376 140 M
( 33 and Goodrich & Tamassia Section 11.4. The disjoint sets code from) s
376 132 M
( Lecture 33 is included in DisjointSets.java in the "set" package/) s
376 124 M
( directory. To use the disjoint sets code, you will need a way to map the) s
376 116 M
( objects that serve as vertices to unique integers. Again, hash tables) s
376 108 M
( are a good way to accomplish this. \(You cannot use the same hash table as) s
376 100 M
( the WUGraph; that should be encapsulated so Kruskal can't see it.\)) s
376 84 M
( Be forewarned that the DisjointSets class has no error checking, and will) s
376 76 M
( fail catastrophically if you union\(\) two vertices that are not roots of) s
376 68 M
( their respective sets, or if you union\(\) a vertex with itself. If you) s
376 60 M
( add simple error checking, it might save you a lot of debugging time \(here) s
376 52 M
( and in Homework 9\).) s
376 36 M
(My own Part II solution is 100 lines long, not counting the sorting method or) s
376 28 M
(hash table code.) s
376 12 M
(Since Parts I and II are on opposite sides of the WUGraph interface, a partner) s
376 4 M
(can easily begin Part II before Part I is working.) s
_R
S
%%Page: (3) 3
%%BeginPageSetup
_S
90 rotate
25 -587 translate
/pagenum 3 def
/fname (readme) def
/fdir () def
/ftail (readme) def
% User defined strings:
/pagenumstr (3) def
/moddatestr (04/15/13) def
/modtimestr (23:05:56) def
/user_header_p false def
/user_footer_p false def
%%EndPageSetup
column_lines
do_header
5 508 M
(Style Rules) s
5 500 M
(===========) s
5 492 M
(You will be graded on style, documentation, efficiency, and the use of) s
5 484 M
(encapsulation.) s
5 468 M
( 1\) Each method must be preceded by a comment describing its behavior) s
5 460 M
( unambiguously. These comments must include descriptions of what each) s
5 452 M
( parameter is for, and what the method returns \(if anything\).) s
5 444 M
( They must also include a description of what the method does \(though) s
5 436 M
( not how it does it\) detailed enough that somebody else could implement) s
5 428 M
( a method that does the same thing from scratch.) s
5 420 M
( 2\) All classes, fields, and methods must have the proper public/private/) s
5 412 M