-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht.html
1018 lines (761 loc) · 68.3 KB
/
t.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
<!DOCTYPE html>
<!-- saved from url=(0041)https://cs50.harvard.edu/ai/2024/notes/0/ -->
<html lang="en-us" class="wf-ptsans-n4-active wf-ptsans-n7-active wf-active"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1, width=device-width"><meta property="og:description" content="This course explores the concepts and algorithms at the foundation of modern artificial intelligence, diving into the ideas that give rise to technologies like game-playing engines, handwriting recognition, and machine translation. Through hands-on projects, students gain exposure to the theory behind graph search algorithms, classification, optimization, machine learning, large language models, and other topics in artificial intelligence as they incorporate them into their own Python programs. By course's end, students emerge with experience in libraries for machine learning as well as knowledge of artificial intelligence principles that enable them to design intelligent systems of their own.">
<meta property="og:image" content="https://img.youtube.com/vi/qK46ET1xk2A/maxresdefault.jpg"><meta property="og:title" content="Lecture 0 - CS50's Introduction to Artificial Intelligence with Python">
<link href="https://cs50.harvard.edu/ai/2024/favicon.ico?1710440346" rel="icon">
<!-- https://fonts.google.com/specimen/PT+Sans?query=PT+Sans&selection.family=PT+Sans:ital,wght@0,400;0,700;1,400;1,700 -->
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>
<!-- https://getbootstrap.com/docs/ -->
<script src="./t_files/jquery.min.js"></script>
<script src="./t_files/bootstrap.bundle.min.js"></script>
<!-- https://bootstrap-table.com/docs/getting-started/introduction/ -->
<link href="./t_files/bootstrap-table.min.css" rel="stylesheet">
<script src="./t_files/bootstrap-table.min.js"></script>
<script src="./t_files/bootstrap-table-mobile.min.js"></script>
<!-- https://fontawesome.com/how-to-use/on-the-web/referencing-icons/basic-use -->
<link crossorigin="anonymous" href="https://kit.fontawesome.com/a6e66aa089.css" rel="stylesheet">
<!-- https://moment.github.io/luxon/ -->
<script src="./t_files/luxon.min.js"></script>
<!-- http://docs.mathjax.org/ -->
<!-- http://docs.mathjax.org/en/latest/options/output/chtml.html?highlight=displayAlign#the-configuration-block -->
<script>
MathJax = {
chtml: {
displayAlign: "left"
}
};
</script>
<script src="./t_files/tex-chtml.js"></script><style type="text/css">.CtxtMenu_InfoClose { top:.2em; right:.2em;}
.CtxtMenu_InfoContent { overflow:auto; text-align:left; font-size:80%; padding:.4em .6em; border:1px inset; margin:1em 0px; max-height:20em; max-width:30em; background-color:#EEEEEE; white-space:normal;}
.CtxtMenu_Info.CtxtMenu_MousePost {outline:none;}
.CtxtMenu_Info { position:fixed; left:50%; width:auto; text-align:center; border:3px outset; padding:1em 2em; background-color:#DDDDDD; color:black; cursor:default; font-family:message-box; font-size:120%; font-style:normal; text-indent:0; text-transform:none; line-height:normal; letter-spacing:normal; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; z-index:201; border-radius: 15px; /* Opera 10.5 and IE9 */ -webkit-border-radius:15px; /* Safari and Chrome */ -moz-border-radius:15px; /* Firefox */ -khtml-border-radius:15px; /* Konqueror */ box-shadow:0px 10px 20px #808080; /* Opera 10.5 and IE9 */ -webkit-box-shadow:0px 10px 20px #808080; /* Safari 3 & Chrome */ -moz-box-shadow:0px 10px 20px #808080; /* Forefox 3.5 */ -khtml-box-shadow:0px 10px 20px #808080; /* Konqueror */ filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color="gray", Positive="true"); /* IE */}
</style><style type="text/css">.CtxtMenu_MenuClose { position:absolute; cursor:pointer; display:inline-block; border:2px solid #AAA; border-radius:18px; -webkit-border-radius: 18px; /* Safari and Chrome */ -moz-border-radius: 18px; /* Firefox */ -khtml-border-radius: 18px; /* Konqueror */ font-family: "Courier New", Courier; font-size:24px; color:#F0F0F0}
.CtxtMenu_MenuClose span { display:block; background-color:#AAA; border:1.5px solid; border-radius:18px; -webkit-border-radius: 18px; /* Safari and Chrome */ -moz-border-radius: 18px; /* Firefox */ -khtml-border-radius: 18px; /* Konqueror */ line-height:0; padding:8px 0 6px /* may need to be browser-specific */}
.CtxtMenu_MenuClose:hover { color:white!important; border:2px solid #CCC!important}
.CtxtMenu_MenuClose:hover span { background-color:#CCC!important}
.CtxtMenu_MenuClose:hover:focus { outline:none}
</style><style type="text/css">.CtxtMenu_Menu { position:absolute; background-color:white; color:black; width:auto; padding:5px 0px; border:1px solid #CCCCCC; margin:0; cursor:default; font: menu; text-align:left; text-indent:0; text-transform:none; line-height:normal; letter-spacing:normal; word-spacing:normal; word-wrap:normal; white-space:nowrap; float:none; z-index:201; border-radius: 5px; /* Opera 10.5 and IE9 */ -webkit-border-radius: 5px; /* Safari and Chrome */ -moz-border-radius: 5px; /* Firefox */ -khtml-border-radius: 5px; /* Konqueror */ box-shadow:0px 10px 20px #808080; /* Opera 10.5 and IE9 */ -webkit-box-shadow:0px 10px 20px #808080; /* Safari 3 & Chrome */ -moz-box-shadow:0px 10px 20px #808080; /* Forefox 3.5 */ -khtml-box-shadow:0px 10px 20px #808080; /* Konqueror */}
.CtxtMenu_MenuItem { padding: 1px 2em; background:transparent;}
.CtxtMenu_MenuArrow { position:absolute; right:.5em; padding-top:.25em; color:#666666; font-family: null; font-size: .75em}
.CtxtMenu_MenuActive .CtxtMenu_MenuArrow {color:white}
.CtxtMenu_MenuArrow.CtxtMenu_RTL {left:.5em; right:auto}
.CtxtMenu_MenuCheck { position:absolute; left:.7em; font-family: null}
.CtxtMenu_MenuCheck.CtxtMenu_RTL { right:.7em; left:auto }
.CtxtMenu_MenuRadioCheck { position:absolute; left: .7em;}
.CtxtMenu_MenuRadioCheck.CtxtMenu_RTL { right: .7em; left:auto}
.CtxtMenu_MenuInputBox { padding-left: 1em; right:.5em; color:#666666; font-family: null;}
.CtxtMenu_MenuInputBox.CtxtMenu_RTL { left: .1em;}
.CtxtMenu_MenuComboBox { left:.1em; padding-bottom:.5em;}
.CtxtMenu_MenuSlider { left: .1em;}
.CtxtMenu_SliderValue { position:absolute; right:.1em; padding-top:.25em; color:#333333; font-size: .75em}
.CtxtMenu_SliderBar { outline: none; background: #d3d3d3}
.CtxtMenu_MenuLabel { padding: 1px 2em 3px 1.33em; font-style:italic}
.CtxtMenu_MenuRule { border-top: 1px solid #DDDDDD; margin: 4px 3px;}
.CtxtMenu_MenuDisabled { color:GrayText}
.CtxtMenu_MenuActive { background-color: #606872; color: white;}
.CtxtMenu_MenuDisabled:focus { background-color: #E8E8E8}
.CtxtMenu_MenuLabel:focus { background-color: #E8E8E8}
.CtxtMenu_ContextMenu:focus { outline:none}
.CtxtMenu_ContextMenu .CtxtMenu_MenuItem:focus { outline:none}
.CtxtMenu_SelectionMenu { position:relative; float:left; border-bottom: none; -webkit-box-shadow:none; -webkit-border-radius:0px; }
.CtxtMenu_SelectionItem { padding-right: 1em;}
.CtxtMenu_Selection { right: 40%; width:50%; }
.CtxtMenu_SelectionBox { padding: 0em; max-height:20em; max-width: none; background-color:#FFFFFF;}
.CtxtMenu_SelectionDivider { clear: both; border-top: 2px solid #000000;}
.CtxtMenu_Menu .CtxtMenu_MenuClose { top:-10px; left:-10px}
</style>
<!-- https://github.com/verlok/vanilla-lazyload -->
<script src="./t_files/intersection-observer.js"></script>
<script src="./t_files/lazyload.min.js"></script>
<!-- https://github.com/davidjbradshaw/iframe-resizer -->
<script src="./t_files/iframeResizer.min.js"></script>
<!-- https://github.com/scratchblocks/scratchblocks/releases -->
<script src="./t_files/scratchblocks.min.js"></script><style><![CDATA[.sb-label{font-family:Lucida Grande,Verdana,Arial,DejaVu Sans,sans-serif;font-weight:700;fill:#fff;font-size:10px;word-spacing:1px}.sb-obsolete{fill:#d42828}.sb-motion{fill:#4a6cd4}.sb-looks{fill:#8a55d7}.sb-sound{fill:#bb42c3}.sb-pen{fill:#0e9a6c}.sb-events{fill:#c88330}.sb-control{fill:#e1a91a}.sb-sensing{fill:#2ca5e2}.sb-operators{fill:#5cb712}.sb-variables{fill:#ee7d16}.sb-list{fill:#cc5b22}.sb-custom{fill:#632d99}.sb-custom-arg{fill:#5947b1}.sb-extension{fill:#4b4a60}.sb-grey{fill:#969696}.sb-bevel{filter:url(#bevelFilter)}.sb-input{filter:url(#inputBevelFilter)}.sb-input-number,.sb-input-number-dropdown,.sb-input-string{fill:#fff}.sb-literal-dropdown,.sb-literal-number,.sb-literal-number-dropdown,.sb-literal-string{font-weight:400;font-size:9px;word-spacing:0}.sb-literal-number,.sb-literal-number-dropdown,.sb-literal-string{fill:#000}.sb-darker{filter:url(#inputDarkFilter)}.sb-outline{stroke:#fff;stroke-opacity:.2;stroke-width:2;fill:none}.sb-comment,.sb-define-hat-cap{stroke:#632d99;stroke-width:1;fill:#8e2ec2}.sb-comment{fill:#ffffa5;stroke:#d0d1d2}.sb-comment-line{fill:#ffff80}.sb-comment-label{font-family:Helvetica,Arial,DejaVu Sans,sans-serif;font-weight:700;fill:#5c5d5f;word-spacing:0;font-size:12px}.sb-diff{fill:none;stroke:#000}.sb-diff-ins{stroke-width:2px}.sb-diff-del{stroke-width:3px}]]></style><style><![CDATA[.sb3-label{font:500 12pt Helvetica Neue,Helvetica,sans-serif;word-spacing:1pt}.sb3-literal-dropdown,.sb3-literal-number,.sb3-literal-number-dropdown,.sb3-literal-string{word-spacing:0}.sb3-diff{fill:none;stroke:#000}.sb3-diff-ins{stroke-width:2px}.sb3-diff-del{stroke-width:3px}svg .sb3-motion{fill:#4c97ff;stroke:#3373cc}svg .sb3-motion-alt{fill:#4280d7}svg .sb3-motion-dark{fill:#3373cc}svg .sb3-looks{fill:#96f;stroke:#774dcb}svg .sb3-looks-alt{fill:#855cd6}svg .sb3-looks-dark{fill:#774dcb}svg .sb3-sound{fill:#cf63cf;stroke:#bd42bd}svg .sb3-sound-alt{fill:#c94fc9}svg .sb3-sound-dark{fill:#bd42bd}svg .sb3-control{fill:#ffab19;stroke:#cf8b17}svg .sb3-control-alt{fill:#ec9c13}svg .sb3-control-dark{fill:#cf8b17}svg .sb3-events{fill:#ffbf00;stroke:#c90}svg .sb3-events-alt{fill:#e6ac00}svg .sb3-events-dark{fill:#c90}svg .sb3-sensing{fill:#5cb1d6;stroke:#2e8eb8}svg .sb3-sensing-alt{fill:#47a8d1}svg .sb3-sensing-dark{fill:#2e8eb8}svg .sb3-operators{fill:#59c059;stroke:#389438}svg .sb3-operators-alt{fill:#46b946}svg .sb3-operators-dark{fill:#389438}svg .sb3-variables{fill:#ff8c1a;stroke:#db6e00}svg .sb3-variables-alt{fill:#ff8000}svg .sb3-variables-dark{fill:#db6e00}svg .sb3-list{fill:#ff661a;stroke:#e64d00}svg .sb3-list-alt{fill:#f50}svg .sb3-list-dark{fill:#e64d00}svg .sb3-custom{fill:#ff6680;stroke:#f35}svg .sb3-custom-alt{fill:#ff4d6a}svg .sb3-custom-dark{fill:#f35}svg .sb3-extension{fill:#0fbd8c;stroke:#0b8e69}svg .sb3-extension-alt{fill:#0da57a}svg .sb3-extension-dark{fill:#0b8e69}svg .sb3-obsolete{fill:#ed4242;stroke:#ca2b2b}svg .sb3-obsolete-alt{fill:#db3333}svg .sb3-obsolete-dark{fill:#ca2b2b}svg .sb3-grey{fill:#bfbfbf;stroke:#909090}svg .sb3-grey-alt{fill:#b2b2b2}svg .sb3-grey-dark{fill:#909090}svg .sb3-label{fill:#fff}svg .sb3-input-color{stroke:#fff}svg .sb3-input-number,svg .sb3-input-string{fill:#fff}svg .sb3-literal-number,svg .sb3-literal-string{fill:#575e75}svg .sb3-custom-arg{fill:#ff6680;stroke:#f35}svg.scratchblocks-style-scratch3-high-contrast .sb3-motion{fill:#80b5ff;stroke:#3373cc}svg.scratchblocks-style-scratch3-high-contrast .sb3-motion-alt{fill:#b3d2ff}svg.scratchblocks-style-scratch3-high-contrast .sb3-motion-dark{fill:#3373cc}svg.scratchblocks-style-scratch3-high-contrast .sb3-looks{fill:#ccb3ff;stroke:#774dcb}svg.scratchblocks-style-scratch3-high-contrast .sb3-looks-alt{fill:#dcf}svg.scratchblocks-style-scratch3-high-contrast .sb3-looks-dark{fill:#774dcb}svg.scratchblocks-style-scratch3-high-contrast .sb3-sound{fill:#e19de1;stroke:#bd42bd}svg.scratchblocks-style-scratch3-high-contrast .sb3-sound-alt{fill:#ffb3ff}svg.scratchblocks-style-scratch3-high-contrast .sb3-sound-dark{fill:#bd42bd}svg.scratchblocks-style-scratch3-high-contrast .sb3-control{fill:#ffbe4c;stroke:#cf8b17}svg.scratchblocks-style-scratch3-high-contrast .sb3-control-alt{fill:#ffda99}svg.scratchblocks-style-scratch3-high-contrast .sb3-control-dark{fill:#cf8b17}svg.scratchblocks-style-scratch3-high-contrast .sb3-events{fill:#ffd966;stroke:#c90}svg.scratchblocks-style-scratch3-high-contrast .sb3-events-alt{fill:#ffecb3}svg.scratchblocks-style-scratch3-high-contrast .sb3-events-dark{fill:#c90}svg.scratchblocks-style-scratch3-high-contrast .sb3-sensing{fill:#85c4e0;stroke:#2e8eb8}svg.scratchblocks-style-scratch3-high-contrast .sb3-sensing-alt{fill:#aed8ea}svg.scratchblocks-style-scratch3-high-contrast .sb3-sensing-dark{fill:#2e8eb8}svg.scratchblocks-style-scratch3-high-contrast .sb3-operators{fill:#7ece7e;stroke:#389438}svg.scratchblocks-style-scratch3-high-contrast .sb3-operators-alt{fill:#b5e3b5}svg.scratchblocks-style-scratch3-high-contrast .sb3-operators-dark{fill:#389438}svg.scratchblocks-style-scratch3-high-contrast .sb3-variables{fill:#ffa54c;stroke:#db6e00}svg.scratchblocks-style-scratch3-high-contrast .sb3-variables-alt{fill:#fc9}svg.scratchblocks-style-scratch3-high-contrast .sb3-variables-dark{fill:#db6e00}svg.scratchblocks-style-scratch3-high-contrast .sb3-list{fill:#f96;stroke:#e64d00}svg.scratchblocks-style-scratch3-high-contrast .sb3-list-alt{fill:#ffcab0}svg.scratchblocks-style-scratch3-high-contrast .sb3-list-dark{fill:#e64d00}svg.scratchblocks-style-scratch3-high-contrast .sb3-custom{fill:#f9a;stroke:#e64d00}svg.scratchblocks-style-scratch3-high-contrast .sb3-custom-alt{fill:#ffccd5}svg.scratchblocks-style-scratch3-high-contrast .sb3-custom-dark{fill:#e64d00}svg.scratchblocks-style-scratch3-high-contrast .sb3-extension{fill:#13ecaf;stroke:#0b8e69}svg.scratchblocks-style-scratch3-high-contrast .sb3-extension-alt{fill:#75f0cd}svg.scratchblocks-style-scratch3-high-contrast .sb3-extension-dark{fill:#0b8e69}svg.scratchblocks-style-scratch3-high-contrast .sb3-obsolete{fill:#fc6666;stroke:#d32121}svg.scratchblocks-style-scratch3-high-contrast .sb3-obsolete-alt{fill:#fcb0b0}svg.scratchblocks-style-scratch3-high-contrast .sb3-obsolete-dark{fill:#d32121}svg.scratchblocks-style-scratch3-high-contrast .sb3-grey{fill:#bfbfbf;stroke:#959595}svg.scratchblocks-style-scratch3-high-contrast .sb3-grey-alt{fill:#b2b2b2}svg.scratchblocks-style-scratch3-high-contrast .sb3-grey-dark{fill:#959595}svg.scratchblocks-style-scratch3-high-contrast .sb3-label{fill:#000}svg.scratchblocks-style-scratch3-high-contrast .sb3-input-color{stroke:#fff}svg.scratchblocks-style-scratch3-high-contrast .sb3-input-number,svg.scratchblocks-style-scratch3-high-contrast .sb3-input-string{fill:#fff}svg.scratchblocks-style-scratch3-high-contrast .sb3-literal-number,svg.scratchblocks-style-scratch3-high-contrast .sb3-literal-string{fill:#000}svg.scratchblocks-style-scratch3-high-contrast .sb3-custom-arg{fill:#f9a;stroke:#e64d00}.sb3-comment{fill:#ffffa5;stroke:#d0d1d2;stroke-width:1}.sb3-comment-line{fill:#ffff80}.sb3-comment-label,.sb3-label.sb3-comment-label{font:400 12pt Helvetica Neue,Helvetica,sans-serif;fill:#000;word-spacing:0}]]></style>
<!-- https://mermaid-js.github.io/ -->
<script src="./t_files/mermaid.min.js"></script>
<!-- https://github.com/twitter/twemoji -->
<script src="./t_files/twemoji.min.js"></script>
<link href="./t_files/page.css" rel="stylesheet">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Sans%7CPT+Sans:bold%7CPT+Sans:ital" media="all"><script src="./t_files/jekyll-theme-cs50.js"></script>
<script>
window.CS50 = {
local: {"day":"numeric","hour":"numeric","minute":"numeric","month":"long","timeZoneName":"short","weekday":"long","year":"numeric"},
locale: "en",
tz: "America/New_York"
};
</script>
<title>Lecture 0 - CS50's Introduction to Artificial Intelligence with Python</title>
<style id="MJX-CHTML-styles">
mjx-container[jax="CHTML"] {
line-height: 0;
}
mjx-container [space="1"] {
margin-left: .111em;
}
mjx-container [space="2"] {
margin-left: .167em;
}
mjx-container [space="3"] {
margin-left: .222em;
}
mjx-container [space="4"] {
margin-left: .278em;
}
mjx-container [space="5"] {
margin-left: .333em;
}
mjx-container [rspace="1"] {
margin-right: .111em;
}
mjx-container [rspace="2"] {
margin-right: .167em;
}
mjx-container [rspace="3"] {
margin-right: .222em;
}
mjx-container [rspace="4"] {
margin-right: .278em;
}
mjx-container [rspace="5"] {
margin-right: .333em;
}
mjx-container [size="s"] {
font-size: 70.7%;
}
mjx-container [size="ss"] {
font-size: 50%;
}
mjx-container [size="Tn"] {
font-size: 60%;
}
mjx-container [size="sm"] {
font-size: 85%;
}
mjx-container [size="lg"] {
font-size: 120%;
}
mjx-container [size="Lg"] {
font-size: 144%;
}
mjx-container [size="LG"] {
font-size: 173%;
}
mjx-container [size="hg"] {
font-size: 207%;
}
mjx-container [size="HG"] {
font-size: 249%;
}
mjx-container [width="full"] {
width: 100%;
}
mjx-box {
display: inline-block;
}
mjx-block {
display: block;
}
mjx-itable {
display: inline-table;
}
mjx-row {
display: table-row;
}
mjx-row > * {
display: table-cell;
}
mjx-mtext {
display: inline-block;
}
mjx-mstyle {
display: inline-block;
}
mjx-merror {
display: inline-block;
color: red;
background-color: yellow;
}
mjx-mphantom {
visibility: hidden;
}
_::-webkit-full-page-media, _:future, :root mjx-container {
will-change: opacity;
}
mjx-assistive-mml {
position: absolute !important;
top: 0px;
left: 0px;
clip: rect(1px, 1px, 1px, 1px);
padding: 1px 0px 0px 0px !important;
border: 0px !important;
display: block !important;
width: auto !important;
overflow: hidden !important;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
mjx-assistive-mml[display="block"] {
width: 100% !important;
}
mjx-c::before {
display: block;
width: 0;
}
.MJX-TEX {
font-family: MJXZERO, MJXTEX;
}
.TEX-B {
font-family: MJXZERO, MJXTEX-B;
}
.TEX-I {
font-family: MJXZERO, MJXTEX-I;
}
.TEX-MI {
font-family: MJXZERO, MJXTEX-MI;
}
.TEX-BI {
font-family: MJXZERO, MJXTEX-BI;
}
.TEX-S1 {
font-family: MJXZERO, MJXTEX-S1;
}
.TEX-S2 {
font-family: MJXZERO, MJXTEX-S2;
}
.TEX-S3 {
font-family: MJXZERO, MJXTEX-S3;
}
.TEX-S4 {
font-family: MJXZERO, MJXTEX-S4;
}
.TEX-A {
font-family: MJXZERO, MJXTEX-A;
}
.TEX-C {
font-family: MJXZERO, MJXTEX-C;
}
.TEX-CB {
font-family: MJXZERO, MJXTEX-CB;
}
.TEX-FR {
font-family: MJXZERO, MJXTEX-FR;
}
.TEX-FRB {
font-family: MJXZERO, MJXTEX-FRB;
}
.TEX-SS {
font-family: MJXZERO, MJXTEX-SS;
}
.TEX-SSB {
font-family: MJXZERO, MJXTEX-SSB;
}
.TEX-SSI {
font-family: MJXZERO, MJXTEX-SSI;
}
.TEX-SC {
font-family: MJXZERO, MJXTEX-SC;
}
.TEX-T {
font-family: MJXZERO, MJXTEX-T;
}
.TEX-V {
font-family: MJXZERO, MJXTEX-V;
}
.TEX-VB {
font-family: MJXZERO, MJXTEX-VB;
}
mjx-stretchy-v mjx-c, mjx-stretchy-h mjx-c {
font-family: MJXZERO, MJXTEX-S1, MJXTEX-S4, MJXTEX, MJXTEX-A ! important;
}
@font-face /* 0 */ {
font-family: MJXZERO;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Zero.woff") format("woff");
}
@font-face /* 1 */ {
font-family: MJXTEX;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Main-Regular.woff") format("woff");
}
@font-face /* 2 */ {
font-family: MJXTEX-B;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Main-Bold.woff") format("woff");
}
@font-face /* 3 */ {
font-family: MJXTEX-I;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Math-Italic.woff") format("woff");
}
@font-face /* 4 */ {
font-family: MJXTEX-MI;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Main-Italic.woff") format("woff");
}
@font-face /* 5 */ {
font-family: MJXTEX-BI;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Math-BoldItalic.woff") format("woff");
}
@font-face /* 6 */ {
font-family: MJXTEX-S1;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Size1-Regular.woff") format("woff");
}
@font-face /* 7 */ {
font-family: MJXTEX-S2;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Size2-Regular.woff") format("woff");
}
@font-face /* 8 */ {
font-family: MJXTEX-S3;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Size3-Regular.woff") format("woff");
}
@font-face /* 9 */ {
font-family: MJXTEX-S4;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Size4-Regular.woff") format("woff");
}
@font-face /* 10 */ {
font-family: MJXTEX-A;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_AMS-Regular.woff") format("woff");
}
@font-face /* 11 */ {
font-family: MJXTEX-C;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Calligraphic-Regular.woff") format("woff");
}
@font-face /* 12 */ {
font-family: MJXTEX-CB;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Calligraphic-Bold.woff") format("woff");
}
@font-face /* 13 */ {
font-family: MJXTEX-FR;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Fraktur-Regular.woff") format("woff");
}
@font-face /* 14 */ {
font-family: MJXTEX-FRB;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Fraktur-Bold.woff") format("woff");
}
@font-face /* 15 */ {
font-family: MJXTEX-SS;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_SansSerif-Regular.woff") format("woff");
}
@font-face /* 16 */ {
font-family: MJXTEX-SSB;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_SansSerif-Bold.woff") format("woff");
}
@font-face /* 17 */ {
font-family: MJXTEX-SSI;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_SansSerif-Italic.woff") format("woff");
}
@font-face /* 18 */ {
font-family: MJXTEX-SC;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Script-Regular.woff") format("woff");
}
@font-face /* 19 */ {
font-family: MJXTEX-T;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Typewriter-Regular.woff") format("woff");
}
@font-face /* 20 */ {
font-family: MJXTEX-V;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Vector-Regular.woff") format("woff");
}
@font-face /* 21 */ {
font-family: MJXTEX-VB;
src: url("https://cs50.harvard.edu/ai/2024/assets/mathjax/es5/output/chtml/fonts/woff-v2/MathJax_Vector-Bold.woff") format("woff");
}
</style></head>
<body class="">
<div class="container-fluid">
<div class="row">
<aside class="col-lg" style="height: 711px; top: 0px;">
<header><h1 data-id="cs50s-introduction-to-artificial-intelligence-with-python"><a href="https://cs50.harvard.edu/ai/2024/">CS50’s Introduction to Artificial Intelligence with Python</a></h1>
<p>OpenCourseWare</p>
<p><a class="pr-1 small" href="https://cs50.harvard.edu/donate">Donate<i aria-hidden="true" class="fas fa-external-link-alt ps-2"></i></a></p>
<p><a href="https://brianyu.me/">Brian Yu</a><br>
<a href="mailto:[email protected]">[email protected]</a></p>
<p><a href="https://cs.harvard.edu/malan/">David J. Malan</a>
<br>
<a href="mailto:[email protected]">[email protected]</a>
<br>
<a class="mr-1" href="https://www.facebook.com/dmalan"><i aria-hidden="true" class="fa-brands fa-facebook-f" title="Facebook"></i><span class="sr-only">Facebook</span></a>
<a class="mr-1" href="https://github.com/dmalan"><i aria-hidden="true" class="fa-brands fa-github" title="GitHub"></i><span class="sr-only">GitHub</span></a>
<a class="mr-1" href="https://www.instagram.com/davidjmalan/"><i aria-hidden="true" class="fa-brands fa-instagram" title="Instagram"></i><span class="sr-only">Instagram</span></a>
<a class="mr-1" href="https://www.linkedin.com/in/malan/"><i aria-hidden="true" class="fa-brands fa-linkedin" title="LinkedIn"></i><span class="sr-only">LinkedIn</span></a>
<a class="mr-1" href="https://www.reddit.com/user/davidjmalan"><i aria-hidden="true" class="fa-brands fa-reddit-alien" title="Reddit"></i><span class="sr-only">Reddit</span></a>
<a class="mr-1" href="https://www.threads.net/@davidjmalan"><i aria-hidden="true" class="fa-brands fa-threads" title="Threads"></i><span class="sr-only">Threads</span></a>
<a class="mr-1" href="https://twitter.com/davidjmalan"><i aria-hidden="true" class="fa-brands fa-twitter" title="Twitter"></i><span class="sr-only">Twitter</span></a></p></header>
<button aria-controls="nav" aria-expanded="false" class="btn btn-sm collapsed d-lg-none" data-bs-target="aside > nav" data-bs-toggle="collapse">
Menu
</button>
<nav class="collapse d-lg-block" id="nav"><hr>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/x/2023/ready/"><i class="fa-solid fa-duck me-2"></i>Ready Player 50</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/ai/2024/zoom/"><i class="fa-solid fa-video me-2"></i>Zoom Meetings</a></li>
</ul>
<!-- Tools -->
<hr class="small">
<ul class="small fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.ai/"><i class="fa-solid fa-duck pe-2 text-decoration-none"></i>CS50.ai</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.edx.org/ed"><i class="fa-solid fa-comment-question pe-2 text-decoration-none"></i>Ed Discussion</a> for Q&A</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.dev/"><i class="fa-solid fa-laptop pe-2 text-decoration-none"></i>Visual Studio Code</a></li>
</ul>
<!-- Course Nav -->
<hr>
<ol start="0">
<li><a href="https://cs50.harvard.edu/ai/2024/weeks/0/">Search</a></li>
<li><a href="https://cs50.harvard.edu/ai/2024/weeks/1/">Knowledge</a></li>
<li><a href="https://cs50.harvard.edu/ai/2024/weeks/2/">Uncertainty</a></li>
<li><a href="https://cs50.harvard.edu/ai/2024/weeks/3/">Optimization</a></li>
<li><a href="https://cs50.harvard.edu/ai/2024/weeks/4/">Learning</a></li>
<li><a href="https://cs50.harvard.edu/ai/2024/weeks/5/">Neural Networks</a></li>
<li><a href="https://cs50.harvard.edu/ai/2024/weeks/6/">Language</a></li>
</ol>
<!-- Items that might usually appear in an academic syllabus -->
<hr>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/ai/2024/honesty/">Academic Honesty</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/ai/2024/certificate/">CS50 Certificate</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/ai/2024/faqs/">FAQs</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.me/cs50ai">Gradebook</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/ai/2024/staff/">Staff</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span></li>
</ul>
<!-- Where to watch or take the class course -->
<hr>
<ul class="small fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://apps.apple.com/us/app/cs50/id1631064453">Apple TV</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.edx.org/ai">edX</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://play.google.com/store/apps/details?id=edu.harvard.cs50.googletv">Google TV</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://web.dce.harvard.edu/extension/csci/e/80">Harvard Extension School</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://web.dce.harvard.edu/summer/csci/s/80">Harvard Summer School</a></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.youtube.com/playlist?list=PLhQjrBD2T381PopUTYtMSstgk-hsTGkVm">YouTube</a></li>
</ul>
<!-- Manual page, style guide, other docs -->
<!-- Status Page -->
<hr>
<ul class="small fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.statuspage.io/">Status Page</a></li>
</ul>
<!-- Communities -->
<hr>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/ai/2024/communities/"><strong>Communities</strong></a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.bsky.social/">Bluesky</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.clubhouse.com/club/cs50">Clubhouse</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://discord.gg/cs50">Discord</a> <span class="badge bg-light ms-1 py-1 rounded-pill text-dark">Q&A</span></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.edx.org/ed">Ed</a> <span class="badge bg-light ms-1 py-1 rounded-pill text-dark">Q&A</span></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.facebook.com/groups/cs50/">Facebook Group</a> <span class="badge bg-light ms-1 py-1 rounded-pill text-dark">Q&A</span></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.facebook.com/cs50/">Facebook Page</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://github.com/cs50">GitHub</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://gitter.im/cs50/x">Gitter</a> <span class="badge bg-light ms-1 py-1 rounded-pill text-dark">Q&A</span></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://instagram.com/cs50">Instagram</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.linkedin.com/groups/7437240/">LinkedIn Group</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.linkedin.com/school/CS50/">LinkedIn Page</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.medium.com/">Medium</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.quora.com/topic/CS50">Quora</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.reddit.com/r/cs50/">Reddit</a> <span class="badge bg-light ms-1 py-1 rounded-pill text-dark">Q&A</span></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.edx.org/slack">Slack</a> <span class="badge bg-light ms-1 py-1 rounded-pill text-dark">Q&A</span></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.snapchat.com/add/cs50">Snapchat</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://soundcloud.com/cs50">SoundCloud</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.stackexchange.com/">Stack Exchange</a> <span class="badge bg-light ms-1 py-1 rounded-pill text-dark">Q&A</span></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://t.me/cs50x">Telegram</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.tiktok.com/@cs50">TikTok</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://www.threads.net/@cs50">Threads</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://twitter.com/cs50">Twitter Account</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://twitter.com/i/communities/1722308663522594923">Twitter Community</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="http://www.youtube.com/subscription_center?add_user=cs50tv">YouTube</a></li>
</ul>
<!-- Courses -->
<hr>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/ai/2024/courses/"><strong>Courses</strong></a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/x">CS50x</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/ai">CS50 AI</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/business">CS50 Business</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="https://cs50.harvard.edu/cybersecurity">CS50 Cybersecurity</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="http://cs50.harvard.edu/law">CS50 for Lawyers</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="http://cs50.harvard.edu/games">CS50 Games</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="http://cs50.harvard.edu/python">CS50 Python</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="http://cs50.harvard.edu/r">CS50 R</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="http://cs50.harvard.edu/scratch">CS50 Scratch</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="http://cs50.harvard.edu/sql">CS50 SQL</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="http://cs50.harvard.edu/technology">CS50 Technology</a></li>
<li data-marker="*" class="small"><span class="fa-li"><i class="fas fa-square"></i></span><a href="http://cs50.harvard.edu/web">CS50 Web</a></li>
</ul>
<!-- Harvard Shop -->
<hr>
<p><a href="https://cs50.harvardshop.com/"><img src="https://cs50.harvard.edu/x/2023/assets/shop.png" alt="Harvard Shop"></a></p>
<!-- Legal -->
<hr>
<p><a href="https://cs50.harvard.edu/ai/2024/license/" class="small"><i class="fab fa-creative-commons me-1"></i>License</a></p>
<p class="small">2024-03-14 14:19:11</p></nav>
<footer></footer>
</aside>
<main class="col-lg" style="margin-bottom: 393px; margin-top: 0px;">
<a data-id="" id="lecture-0" style="top: 0px;"></a><h1><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#lecture-0">Lecture 0</a></h1>
<a data-id="" id="artificial-intelligence" style="top: 0px;"></a><h2><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#artificial-intelligence">Artificial Intelligence</a></h2>
<p>Artificial Intelligence (AI) covers a range of techniques that appear as sentient behavior by the computer. For example, AI is used to recognize faces in photographs on your social media, beat the World’s Champion in chess, and process your speech when you speak to Siri or Alexa on your phone.</p>
<p>In this course, we will explore some of the ideas that make AI possible:</p>
<ol start="0">
<li><strong>Search</strong></li>
</ol>
<p>Finding a solution to a problem, like a navigator app that finds the best route from your origin to the destination, or like playing a game and figuring out the next move.</p>
<ol start="1">
<li><strong>Knowledge</strong></li>
</ol>
<p>Representing information and drawing inferences from it.</p>
<ol start="2">
<li><strong>Uncertainty</strong></li>
</ol>
<p>Dealing with uncertain events using probability.</p>
<ol start="3">
<li><strong>Optimization</strong></li>
</ol>
<p>Finding not only a correct way to solve a problem, but a better—or the best—way to solve it.</p>
<ol start="4">
<li><strong>Learning</strong></li>
</ol>
<p>Improving performance based on access to data and experience. For example, your email is able to distinguish spam from non-spam mail based on past experience.</p>
<ol start="5">
<li><strong>Neural Networks</strong></li>
</ol>
<p>A program structure inspired by the human brain that is able to perform tasks effectively.</p>
<ol start="6">
<li><strong>Language</strong></li>
</ol>
<p>Processing natural language, which is produced and understood by humans.</p>
<a data-id="" id="search" style="top: 0px;"></a><h2><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#search">Search</a></h2>
<p>Search problems involve an agent that is given an initial state and a goal state, and it returns a solution of how to get from the former to the latter. A navigator app uses a typical search process, where the agent (the thinking part of the program) receives as input your current location and your desired destination, and, based on a search algorithm, returns a suggested path. However, there are many other forms of search problems, like puzzles or mazes.</p>
<p><img src="https://cs50.harvard.edu/ai/2024/notes/0/15puzzle.png" alt="15 puzzle"></p>
<p>Finding a solution to a 15 puzzle would require the use of a search algorithm.</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>Agent</strong></p>
<p>An entity that perceives its environment and acts upon that environment. In a navigator app, for example, the agent would be a representation of a car that needs to decide on which actions to take to arrive at the destination.</p>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>State</strong></p>
<p>A configuration of an agent in its environment. For example, in a <a href="https://en.wikipedia.org/wiki/15_puzzle">15 puzzle</a>, a state is any one way that all the numbers are arranged on the board.</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>Initial State</strong></p>
<p>The state from which the search algorithm starts. In a navigator app, that would be the current location.</p>
</li>
</ul>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>Actions</strong></p>
<p>Choices that can be made in a state. More precisely, actions can be defined as a function. Upon receiving state <code class="language-plaintext highlighter-rouge">s</code> as input, <code class="language-plaintext highlighter-rouge">Actions(s)</code> returns as output the set of actions that can be executed in state <code class="language-plaintext highlighter-rouge">s</code>. For example, in a <em>15 puzzle</em>, the actions of a given state are the ways you can slide squares in the current configuration (4 if the empty square is in the middle, 3 if next to a side, 2 if in the corner).</p>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>Transition Model</strong></p>
<p>A description of what state results from performing any applicable action in any state. More precisely, the transition model can be defined as a function. Upon receiving state <code class="language-plaintext highlighter-rouge">s</code> and action <code class="language-plaintext highlighter-rouge">a</code> as input, <code class="language-plaintext highlighter-rouge">Results(s, a)</code> returns the state resulting from performing action <code class="language-plaintext highlighter-rouge">a</code> in state <code class="language-plaintext highlighter-rouge">s</code>. For example, given a certain configuration of a <em>15 puzzle</em> (state <code class="language-plaintext highlighter-rouge">s</code>), moving a square in any direction (action <code class="language-plaintext highlighter-rouge">a</code>) will bring to a new configuration of the puzzle (the new state).</p>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>State Space</strong></p>
<p>The set of all states reachable from the initial state by any sequence of actions. For example, in a 15 puzzle, the state space consists of all the 16!/2 configurations on the board that can be reached from any initial state. The state space can be visualized as a directed graph with states, represented as nodes, and actions, represented as arrows between nodes.</p>
</li>
</ul>
<p><img src="https://cs50.harvard.edu/ai/2024/notes/0/statespace.png" alt="State Space"></p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>Goal Test</strong></p>
<p>The condition that determines whether a given state is a goal state. For example, in a navigator app, the goal test would be whether the current location of the agent (the representation of the car) is at the destination. If it is — problem solved. If it’s not — we continue searching.</p>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>Path Cost</strong></p>
<p>A numerical cost associated with a given path. For example, a navigator app does not simply bring you to your goal; it does so while minimizing the path cost, finding the fastest way possible for you to get to your goal state.</p>
</li>
</ul>
<a data-id="" id="solving-search-problems" style="top: 0px;"></a><h2><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#solving-search-problems">Solving Search Problems</a></h2>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>Solution</strong></p>
<p>A sequence of actions that leads from the initial state to the goal state.</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><strong>Optimal Solution</strong></p>
<p>A solution that has the lowest path cost among all solutions.</p>
</li>
</ul>
</li>
</ul>
<p>In a search process, data is often stored in a <strong><em>node</em></strong>, a data structure that contains the following data:</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>A <em>state</em></li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>Its <em>parent node</em>, through which the current node was generated</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>The <em>action</em> that was applied to the state of the parent to get to the current node</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>The <em>path cost</em> from the initial state to this node</li>
</ul>
<p><em>Nodes</em> contain information that makes them very useful for the purposes of search algorithms. They contain a <em>state</em>, which can be checked using the <em>goal test</em> to see if it is the final state. If it is, the node’s <em>path cost</em> can be compared to other nodes’ <em>path costs</em>, which allows choosing the <em>optimal solution</em>. Once the node is chosen, by virtue of storing the <em>parent node</em> and the <em>action</em> that led from the <em>parent</em> to the current node, it is possible to trace back every step of the way from the <em>initial state</em> to this node, and this sequence of actions is the <em>solution</em>.</p>
<p>However, <em>nodes</em> are simply a data structure — they don’t search, they hold information. To actually search, we use the <strong>frontier</strong>, the mechanism that “manages” the <em>nodes</em>. The <em>frontier</em> starts by containing an initial state and an empty set of explored items, and then repeats the following actions until a solution is reached:</p>
<p>Repeat:</p>
<ol>
<li>
<p>If the frontier is empty,</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><em>Stop.</em> There is no solution to the problem.</li>
</ul>
</li>
<li>
<p>Remove a node from the frontier. This is the node that will be considered.</p>
</li>
<li>
<p>If the node contains the goal state,</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>Return the solution. <em>Stop</em>.</li>
</ul>
<p>Else,</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>* Expand the node (find all the new nodes that could be reached from this node), and add resulting nodes to the frontier.
* Add the current node to the explored set.
</code></pre></div> </div>
</li>
</ol>
<a data-id="" id="depth-first-search" style="top: 0px;"></a><h4><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#depth-first-search">Depth-First Search</a></h4>
<p>In the previous description of the <em>frontier</em>, one thing went unmentioned. At stage 1 in the pseudocode above, which node should be removed? This choice has implications on the quality of the solution and how fast it is achieved. There are multiple ways to go about the question of which nodes should be considered first, two of which can be represented by the data structures of <strong>stack</strong> (in <em>depth-first</em> search) and <strong>queue</strong> (in <em>breadth-first search</em>; and <a href="https://www.youtube.com/watch?v=2wM6_PuBIxY">here is a cute cartoon demonstration</a> of the difference between the two).</p>
<p>We start with the <em>depth-first</em> search (<em>DFS</em>) approach.</p>
<p>A <em>depth-first</em> search algorithm exhausts each one direction before trying another direction. In these cases, the frontier is managed as a <em>stack</em> data structure. The catchphrase you need to remember here is “<em>last-in first-out</em>.” After nodes are being added to the frontier, the first node to remove and consider is the last one to be added. This results in a search algorithm that goes as deep as possible in the first direction that gets in its way while leaving all other directions for later.</p>
<p>(An example from outside lecture: Take a situation where you are looking for your keys. In a <em>depth-first</em> search approach, if you choose to start with searching in your pants, you’d first go through every single pocket, emptying each pocket and going through the contents carefully. You will stop searching in your pants and start searching elsewhere only once you will have completely exhausted the search in every single pocket of your pants.)</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>Pros:
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>At best, this algorithm is the fastest. If it “lucks out” and always chooses the right path to the solution (by chance), then <em>depth-first</em> search takes the least possible time to get to a solution.</li>
</ul>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>Cons:
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>It is possible that the found solution is not optimal.</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>At worst, this algorithm will explore every possible path before finding the solution, thus taking the longest possible time before reaching the solution.</li>
</ul>
</li>
</ul>
<p>Code example:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="c1"># Define the function that removes a node from the frontier and returns it.
</span> <span class="k">def</span> <span class="nf">remove</span><span class="p">(</span><span class="n">self</span><span class="p">):</span>
<span class="c1"># Terminate the search if the frontier is empty, because this means that there is no solution.
</span> <span class="k">if</span> <span class="n">self</span><span class="p">.</span><span class="nf">empty</span><span class="p">():</span>
<span class="k">raise</span> <span class="nc">Exception</span><span class="p">(</span><span class="sh">"</span><span class="s">empty frontier</span><span class="sh">"</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Save the last item in the list (which is the newest node added)
</span> <span class="n">node</span> <span class="o">=</span> <span class="n">self</span><span class="p">.</span><span class="n">frontier</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="c1"># Save all the items on the list besides the last node (i.e. removing the last node)
</span> <span class="n">self</span><span class="p">.</span><span class="n">frontier</span> <span class="o">=</span> <span class="n">self</span><span class="p">.</span><span class="n">frontier</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">return</span> <span class="n">node</span>
</code></pre></div></div>
<a data-id="" id="breadth-first-search" style="top: 0px;"></a><h4><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#breadth-first-search">Breadth-First Search</a></h4>
<p>The opposite of <em>depth-first</em> search would be <em>breadth-first</em> search (<em>BFS</em>).</p>
<p>A <em>breadth-first</em> search algorithm will follow multiple directions at the same time, taking one step in each possible direction before taking the second step in each direction. In this case, the frontier is managed as a <em>queue</em> data structure. The catchphrase you need to remember here is “<em>first-in first-out</em>.” In this case, all the new nodes add up in line, and nodes are being considered based on which one was added first (first come first served!). This results in a search algorithm that takes one step in each possible direction before taking a second step in any one direction.</p>
<p>(An example from outside lecture: suppose you are in a situation where you are looking for your keys. In this case, if you start with your pants, you will look in your right pocket. After this, instead of looking at your left pocket, you will take a look in one drawer. Then on the table. And so on, in every location you can think of. Only after you will have exhausted all the locations will you go back to your pants and search in the next pocket.)</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>Pros:
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>This algorithm is guaranteed to find the optimal solution.</li>
</ul>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>Cons:
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>This algorithm is almost guaranteed to take longer than the minimal time to run.</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>At worst, this algorithm takes the longest possible time to run.</li>
</ul>
</li>
</ul>
<p>Code example:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="c1"># Define the function that removes a node from the frontier and returns it.
</span> <span class="k">def</span> <span class="nf">remove</span><span class="p">(</span><span class="n">self</span><span class="p">):</span>
<span class="c1"># Terminate the search if the frontier is empty, because this means that there is no solution.
</span> <span class="k">if</span> <span class="n">self</span><span class="p">.</span><span class="nf">empty</span><span class="p">():</span>
<span class="k">raise</span> <span class="nc">Exception</span><span class="p">(</span><span class="sh">"</span><span class="s">empty frontier</span><span class="sh">"</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Save the oldest item on the list (which was the first one to be added)
</span> <span class="n">node</span> <span class="o">=</span> <span class="n">self</span><span class="p">.</span><span class="n">frontier</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="c1"># Save all the items on the list besides the first one (i.e. removing the first node)
</span> <span class="n">self</span><span class="p">.</span><span class="n">frontier</span> <span class="o">=</span> <span class="n">self</span><span class="p">.</span><span class="n">frontier</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
<span class="k">return</span> <span class="n">node</span>
</code></pre></div></div>
<a data-id="" id="greedy-best-first-search" style="top: 0px;"></a><h4><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#greedy-best-first-search">Greedy Best-First Search</a></h4>
<p>Breadth-first and depth-first are both <strong>uninformed</strong> search algorithms. That is, these algorithms do not utilize any knowledge about the problem that they did not acquire through their own exploration. However, most often is the case that some knowledge about the problem is, in fact, available. For example, when a human maze-solver enters a junction, the human can see which way goes in the general direction of the solution and which way does not. AI can do the same. A type of algorithm that considers additional knowledge to try to improve its performance is called an <strong>informed</strong> search algorithm.</p>
<p><strong>Greedy best-first</strong> search expands the node that is the closest to the goal, as determined by a <strong>heuristic function</strong> <em>h(n)</em>. As its name suggests, the function estimates how close to the goal the next node is, but it can be mistaken. The efficiency of the <em>greedy best-first</em> algorithm depends on how good the heuristic function is. For example, in a maze, an algorithm can use a heuristic function that relies on the <strong>Manhattan distance</strong> between the possible nodes and the end of the maze. The <em>Manhattan distance</em> ignores walls and counts how many steps up, down, or to the sides it would take to get from one location to the goal location. This is an easy estimation that can be derived based on the (x, y) coordinates of the current location and the goal location.</p>
<p><img src="https://cs50.harvard.edu/ai/2024/notes/0/manhattandistance.png" alt="Manhattan Distance"></p>
<p>Manhattan Distance</p>
<p>However, it is important to emphasize that, as with any heuristic, it can go wrong and lead the algorithm down a slower path than it would have gone otherwise. It is possible that an <em>uninformed</em> search algorithm will provide a better solution faster, but it is less likely to do so than an <em>informed</em> algorithm.</p>
<a data-id="" id="a-search" style="top: 0px;"></a><h4><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#a-search">A* Search</a></h4>
<p>A development of the <em>greedy best-first</em> algorithm, <em>A* search</em> considers not only <em>h(n)</em>, the estimated cost from the current location to the goal, but also <em>g(n)</em>, the cost that was accrued until the current location. By combining both these values, the algorithm has a more accurate way of determining the cost of the solution and optimizing its choices on the go. The algorithm keeps track of (<em>cost of path until now</em> + <em>estimated cost to the goal</em>), and once it exceeds the estimated cost of some previous option, the algorithm will ditch the current path and go back to the previous option, thus preventing itself from going down a long, inefficient path that <em>h(n)</em> erroneously marked as best.</p>
<p>Yet again, since this algorithm, too, relies on a heuristic, it is as good as the heuristic that it employs. It is possible that in some situations it will be less efficient than <em>greedy best-first</em> search or even the <em>uninformed</em> algorithms. For <em>A* search</em> to be optimal, the heuristic function, <em>h(n)</em>, should be:</p>
<ol>
<li><em>Admissible</em>, or never <em>overestimating</em> the true cost, and</li>
<li><em>Consistent</em>, which means that the estimated path cost to the goal of a new node in addition to the cost of transitioning to it from the previous node is greater or equal to the estimated path cost to the goal of the previous node. To put it in an equation form, <em>h(n)</em> is consistent if for every node <em>n</em> and successor node <em>n’</em> with step cost <em>c</em>, <em>h(n) ≤ h(n’) + c</em>.</li>
</ol>
<a data-id="" id="adversarial-search" style="top: 0px;"></a><h3><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#adversarial-search">Adversarial Search</a></h3>
<p>Whereas, previously, we have discussed algorithms that need to find an answer to a question, in <strong>adversarial search</strong> the algorithm faces an opponent that tries to achieve the opposite goal. Often, AI that uses adversarial search is encountered in games, such as tic tac toe.</p>
<a data-id="" id="minimax" style="top: 0px;"></a><h4><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#minimax">Minimax</a></h4>
<p>A type of algorithm in adversarial search, <strong>Minimax</strong> represents winning conditions as (-1) for one side and (+1) for the other side. Further actions will be driven by these conditions, with the minimizing side trying to get the lowest score, and the maximizer trying to get the highest score.</p>
<p><strong>Representing a Tic-Tac-Toe AI</strong>:</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><em>S₀</em>: Initial state (in our case, an empty 3X3 board)</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><em>Players(s)</em>: a function that, given a state <em>s</em>, returns which player’s turn it is (X or O).</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><em>Actions(s)</em>: a function that, given a state <em>s</em>, return all the legal moves in this state (what spots are free on the board).</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><em>Result(s, a)</em>: a function that, given a state <em>s</em> and action <em>a</em>, returns a new state. This is the board that resulted from performing the action <em>a</em> on state <em>s</em> (making a move in the game).</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><em>Terminal(s)</em>: a function that, given a state <em>s</em>, checks whether this is the last step in the game, i.e. if someone won or there is a tie. Returns <em>True</em> if the game has ended, <em>False</em> otherwise.</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span><em>Utility(s)</em>: a function that, given a terminal state <em>s</em>, returns the utility value of the state: -1, 0, or 1.</li>
</ul>
<p><strong>How the algorithm works</strong>:</p>
<p>Recursively, the algorithm simulates all possible games that can take place beginning at the current state and until a terminal state is reached. Each terminal state is valued as either (-1), 0, or (+1).</p>
<p><img src="https://cs50.harvard.edu/ai/2024/notes/0/minimax_tictactoe.png" alt="Minimax in Tic Tac Toe"></p>
<p>Minimax Algorithm in Tic Tac Toe</p>
<p>Knowing based on the state whose turn it is, the algorithm can know whether the current player, when playing optimally, will pick the action that leads to a state with a lower or a higher value. This way, alternating between minimizing and maximizing, the algorithm creates values for the state that would result from each possible action. To give a more concrete example, we can imagine that the maximizing player asks at every turn: “if I take this action, a new state will result. If the minimizing player plays optimally, what action can that player take to bring to the lowest value?” However, to answer this question, the maximizing player has to ask: “To know what the minimizing player will do, I need to simulate the same process in the minimizer’s mind: the minimizing player will try to ask: ‘if I take this action, what action can the maximizing player take to bring to the highest value?’” This is a recursive process, and it could be hard to wrap your head around it; looking at the pseudo code below can help. Eventually, through this recursive reasoning process, the maximizing player generates values for each state that could result from all the possible actions at the current state. After having these values, the maximizing player chooses the highest one.</p>
<p><img src="https://cs50.harvard.edu/ai/2024/notes/0/minimax_theoretical.png" alt="Minimax Algorithm"></p>
<p>The Maximizer Considers the Possible Values of Future States.</p>
<p>To put it in pseudocode, the Minimax algorithm works the following way:</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p>Given a state <em>s</em></p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>The maximizing player picks action <em>a</em> in <em>Actions(s)</em> that produces the highest value of <em>Min-Value(Result(s, a))</em>.</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>The minimizing player picks action <em>a</em> in <em>Actions(s)</em> that produces the lowest value of <em>Max-Value(Result(s, a))</em>.</li>
</ul>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p>Function <em>Max-Value(state)</em></p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><em>v = -∞</em></p>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p>if <em>Terminal(state)</em>:</p>
<p> return <em>Utility(state)</em></p>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p>for <em>action</em> in <em>Actions(state)</em>:</p>
<p> <em>v = Max(v, Min-Value(Result(state, action)))</em></p>
<p>return <em>v</em></p>
</li>
</ul>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p>Function <em>Min-Value(state)</em>:</p>
<ul class="fa-ul">
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p><em>v = ∞</em></p>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p>if <em>Terminal(state)</em>:</p>
<p> return <em>Utility(state)</em></p>
</li>
<li data-marker="*"><span class="fa-li"><i class="fas fa-square"></i></span>
<p>for <em>action</em> in <em>Actions(state)</em>:</p>
<p> <em>v = Min(v, Max-Value(Result(state, action)))</em></p>
<p>return <em>v</em></p>
</li>
</ul>
</li>
</ul>
<a data-id="" id="alpha-beta-pruning" style="top: 0px;"></a><h4><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#alpha-beta-pruning">Alpha-Beta Pruning</a></h4>
<p>A way to optimize <em>Minimax</em>, <strong>Alpha-Beta Pruning</strong> skips some of the recursive computations that are decidedly unfavorable. After establishing the value of one action, if there is initial evidence that the following action can bring the opponent to get to a better score than the already established action, there is no need to further investigate this action because it will decidedly be less favorable than the previously established one.</p>
<p>This is most easily shown with an example: a maximizing player knows that, at the next step, the minimizing player will try to achieve the lowest score. Suppose the maximizing player has three possible actions, and the first one is valued at 4. Then the player starts generating the value for the next action. To do this, the player generates the values of the minimizer’s actions if the current player makes this action, knowing that the minimizer will choose the lowest one. However, before finishing the computation for all the possible actions of the minimizer, the player sees that one of the options has a value of three. This means that there is no reason to keep on exploring the other possible actions for the minimizing player. The value of the not-yet-valued action doesn’t matter, be it 10 or (-10). If the value is 10, the minimizer will choose the lowest option, 3, which is already worse than the preestablished 4. If the not-yet-valued action would turn out to be (-10), the minimizer will this option, (-10), which is even more unfavorable to the maximizer. Therefore, computing additional possible actions for the minimizer at this point is irrelevant to the maximizer, because the maximizing player already has an unequivocally better choice whose value is 4.</p>
<p><img src="https://cs50.harvard.edu/ai/2024/notes/0/alphabeta.png" alt="Alpha Beta Pruning"></p>
<a data-id="" id="depth-limited-minimax" style="top: 0px;"></a><h4><a data-id="" href="https://cs50.harvard.edu/ai/2024/notes/0/#depth-limited-minimax">Depth-Limited Minimax</a></h4>
<p>There is a total of 255,168 possible Tic Tac Toe games, and 10²⁹⁰⁰⁰ possible games in Chess. The minimax algorithm, as presented so far, requires generating all hypothetical games from a certain point to the terminal condition. While computing all the Tic-Tac-Toe games doesn’t pose a challenge for a modern computer, doing so with chess is currently impossible.</p>