-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwet2dry.lyx
1154 lines (982 loc) · 26.9 KB
/
wet2dry.lyx
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
#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\begin_preamble
%Customisation
\usepackage[tableposition=top]{caption}
\usepackage{chngcntr}
\renewcommand{\arraystretch}{2}
% Set space between words to be wider:
\spaceskip=1.3\fontdimen2\font plus 1\fontdimen3\font minus 1.5\fontdimen4\font
% Convert the LyX colors into more pleasent colors
\usepackage{xcolor}
\definecolor{blue}{RGB}{14,107,217}
\definecolor{green}{RGB}{0,158,40}
\definecolor{red}{RGB}{235,16,16}
\definecolor{brown}{RGB}{164,66,0}
\definecolor{orange}{RGB}{231,135,26}
\definecolor{purple}{RGB}{94,53,177}
%fixing parentheses
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\hebrewfont[Script=Hebrew]{David}
\makeatletter
\def\maketag@@@#1{\hbox{\m@th\normalfont\LRE{#1}}}
\def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip)}}
\makeatother
\end_preamble
\use_default_options true
\begin_modules
eqs-within-sections
figs-within-sections
theorems-ams-bytype
theorems-sec-bytype
\end_modules
\maintain_unincluded_children false
\language hebrew
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts true
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_author "Daniel Belokon"
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize a4paper
\use_geometry true
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 2cm
\topmargin 3cm
\rightmargin 2cm
\bottommargin 2cm
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Title
מבני נתונים - תרגיל רטוב
\family roman
\series medium
\shape up
\size largest
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\numeric on
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
1
\end_layout
\begin_layout Section
תיאור מבנה הנתונים:
\end_layout
\begin_layout Subsection
עץ
\begin_inset Formula $\mathtt{AVL-Rank}$
\end_inset
\end_layout
\begin_layout Standard
למען פתרון התרגיל מימשנו עץ דרגות
\begin_inset Formula $AVL$
\end_inset
גנרי המחזיק מידע נוסף, המשתמש בפעולת השוואה בעזרת פונקציית
\begin_inset Formula $\text{bool customCompare(T, T)}$
\end_inset
אשר מסופקת בבנאי - או, בברירת המחדל, אופרטור השוואה
\begin_inset Formula $<$
\end_inset
המוגדר עבור אותו אובייקט גנרי.
בסיס העץ הינו העץ מתרגיל רטוב
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\numeric on
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
1
\family roman
\series medium
\shape up
\size normal
\emph off
\numeric off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
עם שיפורים לתמיכה בדרגות וסכימה של ערך נוסף.
\end_layout
\begin_layout Standard
העץ מורכב ממצביע לשורש שהוא מטיפוס
\begin_inset Formula $\text{Node}$
\end_inset
גנרי, בנוסף מכיל שדה המציין את גודל העץ.
\end_layout
\begin_layout Standard
\begin_inset Formula $Node$
\end_inset
: מחלקה המייצגת צומת בעץ, מכילה שדות -
\begin_inset Formula $\text{left\_size, right\_size, right\_value, left\_value, height}$
\end_inset
ומצביעים לצומת ימנית ושמאלית.
\end_layout
\begin_layout Standard
העץ תומך בפעולות הסטנדרטיות: הוספה, חיפוש, מחיקה ואיחוד בין עצים.
בנוסף לאלו, העץ תומך בפעולות
\begin_inset Formula $\text{getValueSumUpTo}$
\end_inset
שמחזירה את סכום השדות
\begin_inset Formula $value$
\end_inset
של כלל הצמתים שקטנים מצומת ספציפית - בנוסף מעבירה את דרגת הצומת במשתנה
עזר.
\end_layout
\begin_layout Subsection
טבלת ערבול
\end_layout
\begin_layout Standard
למען פתרון התרגיל מימשנו טבלת ערבול כפי שנלמד בהרצאה, פונקציית הערבול היא
על פי שיטת הכפל כפי שראינו בהרצאה.
הטבלה מטפלת בהתנגשויות עם
\begin_inset Formula $\text{linear probing}$
\end_inset
, ושומרת את מספר האיברים הנמצאים בתוכה.
במידת הצורך, מתבצעת הגדלה של המבנה על ידי יצירת מערך חדש וערבול מחדש של
האיברים לתוכה בעזרת הגודל החדש.
\end_layout
\begin_layout Standard
הטבלה עצמה מחזיקה מערך של
\begin_inset Formula $HashNode$
\end_inset
שהיא מחלקה גנרית המחזיקה שדה של
\begin_inset Formula $Id$
\end_inset
, שדה של מידע ושדה שמסמן את אותו התא כמחוק.
המבנה תומך בפעולות הסטנדרטיות - הכנסה, הסרה, חיפוש, ואיחוד.
\end_layout
\begin_layout Subsection
\begin_inset Formula $\text{Union-Find}$
\end_inset
\end_layout
\begin_layout Standard
למען פתרון התרגיל מימשנו
\begin_inset Formula $UF$
\end_inset
עם איחוד קבוצות וכיווץ מסלולים והאיחוד מתבצע לפי גודל ולכן בסך הכל הסיבוכיות
המשוערכת היא
\begin_inset Formula $O\left(\log^{*}(n)\right)$
\end_inset
לחיפוש ואיחוד.
המבנה מומש בעזרת חמישה מערכים בגודל מספר האיברים - שלושה מערכים כפי שראינו
בהרצאה )האיבר, גודל והורה( ושני מערכים נוספים התומכים בפעולות הנדרשות בתרגיל
- האחד,
\begin_inset Formula $value$
\end_inset
שומר ערך של קבוצה ומבצע חישובים בדומה לשיטת הארגזים שראינו בתרגול.
השני,
\begin_inset Formula $\text{set\_representative}$
\end_inset
שומר בפועל מי הוא הנציג של אותה קבוצה - כדי שנוכל לבצע איחודים בסיבוכיות
נכונה ועדיין לשמור על נכונות בחירת הנציגים.
\end_layout
\begin_layout Itemize
\begin_inset Newpage pagebreak
\end_inset
\end_layout
\begin_layout Subsection
המערכת
\end_layout
\begin_layout Standard
המערכת תנהל שני אובייקטים - עובדים וחברות.
כל חברה תכיל )אולי( עובדים, וכל עובד יהיה שייך לחברה.
כלל האובייקטים במערכת ינוהלו, יווצרו, וימחקו על ידי המערכת.
היחסים בין עובדים לחברות ישמרו בתור התייחסויות עם מצביעים בלבד.
\begin_inset Newline newline
\end_inset
\begin_inset Newline newline
\end_inset
למען עמידה בסיבוכיות הדרושה, המערכת תחזיק את החברות ב
\begin_inset Formula $\text{UnionFind}$
\end_inset
כשערך כל חברה ינוהל גם בעזרתו - ואת מספרן במשתנה נוסף.
בנוסף,
\emph on
כלל העובדים
\emph default
בערכת יוחזקו ב
\begin_inset Formula $\text{HashTable}$
\end_inset
כאשר התחום הוא תעודות הזהות של העובדים - בנוסף נחזיק עץ דרגות מאוזן שיכיל
את כלל העובדים שאינם מתמחים )שכר גבוהה מ
\numeric on
0
\numeric off
( ממוין לפי שכר, ועבור כל שאר העובדים )שכר
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\numeric on
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
0
\numeric off
( נחזיק משתנים נוספים אשר מונים את סכום הדרגותיהם ומספרם, כל זאת על מנת
לעמוד בדרישות התרגיל ובש' ההגשה.
\begin_inset Newline newline
\end_inset
\end_layout
\begin_layout Subsubsection
חברה:
\end_layout
\begin_layout Standard
כל חברה תכיל שדה מזהה, את ערכה ההתחלתי וְ-
\begin_inset Formula $\text{HashTable}$
\end_inset
של מצביעים לכלל העובדים של החברה - ובנוסף, בדומה למערכת, תכיל עץ דרגות
של העובדים בחברה עם שכר וסכום דרגות שאר העובדים ומספרם בנפרד.
\end_layout
\begin_layout Subsubsection
עובד:
\end_layout
\begin_layout Standard
העובד יכיל שדה של מזהה, שכר, דרגה ומצביע לחברה בה הוא עובד.
\end_layout
\begin_layout Standard
\begin_inset Newpage pagebreak
\end_inset
\end_layout
\begin_layout Subsection
ממשק
\end_layout
\begin_layout Subsubsection
\begin_inset CommandInset label
LatexCommand label
name "subsec:סיבוכיות-זמן:"
\end_inset
סיבוכיות זמן:
\end_layout
\begin_layout Standard
למען פשטות והקלת הקריאה עבור הקורא המסור, נציין שֶ-
\end_layout
\begin_layout Itemize
פעולות החיפוש, סיבוכיות ההסרה, החיפוש וההכנסה ב
\begin_inset Formula $\text{HashTable}$
\end_inset
העובדים היא כפי שראינו בהרצאה, תחת הנחת הפיזור האחיד הפשוט של שלושת הפעולות
היא משוערכת להיות
\begin_inset Formula $O(1)$
\end_inset
בממוצע על הקלט.
\end_layout
\begin_layout Itemize
פעולות החיפוש והאיחוד ב
\begin_inset Formula $UF$
\end_inset
החברות מתבצעות בסיבוכיות, כפי שראינו בהרצאה, של
\begin_inset Formula $O(\text{log}^{*}n)$
\end_inset
- זאת בעזרת כיווץ מסלולים ואיחוד לפי גודל.
\end_layout
\begin_layout Itemize
הסרה והוספה בעץ העובדים עם שכר היא
\begin_inset Formula $\log n$
\end_inset
– כאשר
\begin_inset Formula $n$
\end_inset
הוא מספר העובדים במערכת.
אלגוריתם החיפוש עובד לפי שמורת החיפוש בעץ ולכן כפי שנלמד בהרצאה יקח
\begin_inset Formula $\log n$
\end_inset
, אלגוריתם ההוספה עובד גם כפי הנלמד בהרצאה ולכן שומר על אותה סיבוכיות הזמן.
במקרה ההסרה, במקרה הגרוע נבצע לאורך המסלול עד לשורש תיקונים ל
\begin_inset Formula $BF$
\end_inset
ולכן הסיבוכיות היא אותה הסיבוכיות זמן.
בנוסף במהלך חלק מהפונקציות אנו מבצעים דפוס החוזר על עצמו : בדיקה האם האיבר
בעץ, הכנסה / הוצאה , נציין שאם נבצע
\begin_inset Formula $L$
\end_inset
פעמים חיפוש בעץ עדיין מתקיים שעבור
\begin_inset Formula $J,L$
\end_inset
מספר טבעי :
\begin_inset Formula $J\log k+L\log n=O(\log k+\log n)$
\end_inset
\end_layout
\begin_layout Subsubsection
סיבוכיות מקום:
\end_layout
\begin_layout Standard
במערכת כולה יוחזקו
\begin_inset Formula $n$
\end_inset
עובדים ו
\begin_inset Formula $k$
\end_inset
חברות - בנוסף לאובייקטים עצמם השמורים בזכרון, יהיו העצים והטבלאות הערבול
המוכלים במערכת, ובחברות, תלויים לינארית באותם משתנים.
סכום כל הצמתים והתאים של עצי וטבלאות העובדים בתוך החברות הינו
\begin_inset Formula $2n$
\end_inset
מכיוון שזו חלוקה של העובדים )כל עובד יכול להיות בחברה אחת וישנו עץ וטבלה
אחת בכל חברה(, בנוסף - בתוך המערכת, ה
\begin_inset Formula $UF$
\end_inset
המחזיק את החברות מחזיק מספר קבוע של מערכים בגודל כמות החברות
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
שבמערכת, העץ וטבלת הערבול של העובדים גם כן מחזיקים מספר קבוע של צמתים/תאים
כתלות לינארים במספר העובדים במערכת )נדגיש כי טבלת הערבול מבצעת צמצום אם
התפוסה קטנה מ
\begin_inset Formula $25\%$
\end_inset
, ולכן גודלה תמיד לינארי בתפוסתה(.
\end_layout
\begin_layout Enumerate
\begin_inset Formula $\text{\textbf{init}}$
\end_inset
:
\begin_inset Newline newline
\end_inset
בפעולה מאתחלת את מבנה הנתונים, יוצרת
\begin_inset Formula $k$
\end_inset
חברות ריקות ומכניסה כל אחת מהן לקבוצה משלה ב
\begin_inset Formula $UnionFind$
\end_inset
החברות.
בנוסף, יוצרת עץ ריק וטבלת ערבול ריקה של עובדים סך הכל,
\begin_inset Formula $O(k)$
\end_inset
.
\end_layout
\begin_layout Enumerate
\begin_inset Formula $\text{\textbf{AddEmployee}}$
\end_inset
:
\begin_inset Newline newline
\end_inset
נבדוק את ערכי הפרמטרים, במידה ולא עומדים בתנאים נחזיר את השגיאה המתאימה.
נבצע חיפוש למציאת החברה שעלינו להוסיף את העובד ב
\begin_inset Formula $UF$
\end_inset
החברות )כפי שפירטנו בסעיף
\begin_inset CommandInset ref
LatexCommand ref
reference "subsec:סיבוכיות-זמן:"
plural "false"
caps "false"
noprefix "false"
\end_inset
הסיבוכיות היא
\begin_inset Formula $O(\log^{*}k)$
\end_inset
( אם החברה אינה נמצאת – נחזיר את השגיאה המתאימה.
ניצור את העובד, ונבצע חיפוש בטבלת הערבול לבדוק אם העובד כבר קיים במבנה
)
\begin_inset Formula $O(1)$
\end_inset
(, אם הוא אינו קיים נבצע הכנסה אך ורק לטבלת הערבול )שכרו
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\numeric on
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
0
\numeric off
(, ונבצע הכנסה לחברה )שגם מבצעת הכנסה רק לטבלת הערבול(.
נוסף
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\numeric on
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
1
\family roman
\series medium
\shape up
\size normal
\emph off
\numeric off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
למניית הזוטרים ונוסיף את דרגתו לסכימת דרגותהים של הזוטרים.
סך הכל הסיבוכיות הינה
\begin_inset Formula $O\left(\log^{*}(k)\right)$
\end_inset
.
\end_layout
\begin_layout Enumerate
\begin_inset Formula $\text{\textbf{RemoveEmployee}}$
\end_inset
:
\begin_inset Newline newline
\end_inset
נבדוק את תקינות הפרמטרים, אם יש בעיה נחזיר את ערך ההחזרה המבוקש.
נחפש את העובד לפי המזהה, ונשיג את החברה שבה הוא עובד ממנו )
\begin_inset Formula $O(1)$
\end_inset
(.
נסיר את העובד מכלל המבנים שבהם הוא נמצא, סך הכל
\begin_inset Formula $O(\log n)$
\end_inset
.
אם העובד בעל שכר
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\numeric on
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
0
\numeric off
, נדע כי הוא זוטר ולא שווה הכנסה לעץ ולכן רק נסיר את דרגתו מסכום הדרגות
של הזוטרים.
\end_layout
\begin_layout Enumerate
\begin_inset Formula $\text{\textbf{AcquireCompany}}$
\end_inset
:
\begin_inset Newline newline
\end_inset
נמצא את החברה הרוכשת והחברה הנרכשת ב
\begin_inset Formula $UF$
\end_inset
)
\begin_inset CommandInset ref
LatexCommand ref
reference "subsec:סיבוכיות-זמן:"
plural "false"
caps "false"
noprefix "false"
\end_inset
( ונוודא שאכן שתי החברות בקבוצות זרות.
במידה והרכישה יכולה להתבצע נבצע מיזוג של החברות, כלומר מיזוג בין שני הקבוצות
ב
\begin_inset Formula $UF$
\end_inset
בתוספת ה
\begin_inset Formula $factor$
\end_inset
, שיבצע עדכון הערך של קבוצת החברה הרוכשת ב
\begin_inset Formula $UF$
\end_inset
.
בנוסף, נבצע מיזוג בין החברות שיעביר את כלל העובדים מטבלת הנרכש לרוכש ויבצע
מיזוג בין העצים.
סך הכל
\begin_inset Formula $O(\log^{*}k+n_{\text{Acquirer}}+n_{\text{Target}})$
\end_inset
בשל שימוש בפונקציית
\begin_inset Formula $\text{merge}$
\end_inset
וחיפוש החברות המתאימות.
נדגיש כי המבנים שמכילים עובדים בעץ הנרכש מתרוקנים ולכן לא משפיעים על סיבוכיות
המקום, על אף שהחברה נותרת במערכת.
\end_layout
\begin_layout Enumerate
\begin_inset Formula $\text{\textbf{employeeSalaryIncrase}}$
\end_inset
:
\begin_inset Newline newline
\end_inset
נמצא את העובד המבוקש בטבלה, נשמור את השכר הנוכחי שלו לפני העדכון.
נשיג את החברה שהוא עובד בה ב
\begin_inset Formula $O(1)$
\end_inset
מהשדה השמור בעובד.
נסיר את העובד מעץ המשכורות של המערכת ושל החברה, נעדכן את שכרו ונחזיר אותו
לשני העצים.
לאחר מכן, אם שכרו הקודם היה
\family roman
\series medium
\shape up
\size normal
\emph off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\numeric on
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
0
\family roman
\series medium
\shape up
\size normal
\emph off
\numeric off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
- כלומר הוא היה זוטר, נוריד את הדרגה שלו מסכום הדרגות ונקטין את מספר הזוטרים
ב
\numeric on
1
\family roman
\series medium
\shape up
\size normal
\emph off
\numeric off
\bar no
\strikeout off
\xout off
\uuline off
\uwave off
\noun off
\color none
\family default
\series default
\shape default
\size default
\emph default
\bar default
\strikeout default
\xout default
\uuline default
\uwave default
\noun default
\color inherit
כן בחברה וכן במערכת.
סך הכל,
\begin_inset Formula $O\left(\log n\right)$
\end_inset
בממוצע על הקלט.
\end_layout
\begin_layout Enumerate
\begin_inset Formula $\text{\textbf{PromoteEmployee}}$
\end_inset
:
\begin_inset Newline newline
\end_inset
נמצא את העובד, נגדיר את דרגתו אם הפרמטר חיובי, אחרת נצא ונחזיר הצלחה.
אם העלנו את דרגתו, נוציא ונחזיר אותו לעצים של השכר אם הוא בעל שכר גבוהה
מ
\numeric on
0
\numeric off
.
אחרת, נעלה את סכימת הדרגות של הזוטרים בפרמטר הנתון.
סך הכל, בדומה ל
\begin_inset Formula $salaryIncrease$
\end_inset
הסיבוכיות היא
\begin_inset Formula $O\left(\log n\right)$
\end_inset
.
\end_layout
\begin_layout Enumerate
\begin_inset Formula $\text{\textbf{SumOfBumpGradeBetweenTopWorkersByGroup}}$
\end_inset
:
\begin_inset Newline newline
\end_inset
לאחר בדיקת נכנות הקלט, נמצא את העץ הנכון לפי הפרמטר
\begin_inset Formula $companyID$
\end_inset
כמפורט בתרגיל.
אם אין חברה מתאימה, נחזיר שגיאה.
לאחר מכן, נשתמש בפונקציית העץ
\begin_inset Formula $getHighetMValueSum$
\end_inset
כדי לקבל את הערך הרצוי - סך הכל, זהו חיפוש בינארי בעץ דרגות מאוזן ולכן
\begin_inset Formula $O(\log^{*}k+\log n)$
\end_inset
בשל חיפוש החברה.
\end_layout
\begin_layout Enumerate
\begin_inset Formula $\text{\textbf{AverageBumpGradeBetweenSalaryByGroup}}$
\end_inset
:
\begin_inset Newline newline
\end_inset
לאחר בדיקת נכונות הקלו, נמצא את העץ הנכון לפי הפרמטר כמפורט בתרגיל.
אם אין חברה מתאימה, נחזיר שגיאה.
לאחר מכן, נשתמש בפונקציית העץ
\begin_inset Formula $findNode$
\end_inset
בכדי למצוא את ה
\begin_inset Formula $node$
\end_inset
הקרוב ביותר לתחום העליון - מימין, ולתחום התחתון - משמאל.