compsci 201 201 exam 2 2 re review c compar arat ator ors
play

Compsci 201 201 Exam 2 2 Re Review, C , Compar arat ator ors, - PowerPoint PPT Presentation

Compsci 201 201 Exam 2 2 Re Review, C , Compar arat ator ors, A , APTs Par art 1 1 of of 4 Susan Rodger April 8, 2020 4/8/2020 Compsci 201, Spring 2020 1 U is for Unix Basis for Linux and Android and GNU and


  1. Compsci 201 201 Exam 2 2 Re Review, C , Compar arat ator ors, A , APTs Par art 1 1 of of 4 Susan Rodger April 8, 2020 4/8/2020 Compsci 201, Spring 2020 1

  2. U is for … • Unix • Basis for Linux and Android and GNU and … • User Interface/UI, User Experience/UX • User is the heart and soul 4/8/2020 Compsci 201, Spring 2020 2

  3. Google interface • Maris issa M Mayer • Google –employee number 20 • Yahoo CEO • Lumi Labs 4/8/2020 Compsci 201, Spring 2020 3

  4. Announcements • APT PT-6 du due T Tuesda day, A April il 7 • APT PT-7 o out ut t thi his week and nd d due ue A April 1 16 (no note Thu hursday) • Assig ignme ment P t P5 Percolatio tion • Code due Thursday, April 9, grace thru April 13 • Assig ignme ment P t P6 Huffma man o out e end o d of week, k, du due April il 22 • Discussi ssion on 12 12 Monda day, A April il 13 13 • Pre-discussion out at end of week • Exam 2 m 2 is A April il 10 10 – Your ur o own w n work! • APT PT Q Quiz 2 2 is A April 11 11-15 15 – Your ur o own w work! 4/8/2020 Compsci 201, Spring 2020 4

  5. PfSWoA • Exa Exam 2 Review and and L Logis istics • O-Notation, Big-Oh, Recurrences • Linked Lists • Binary Trees • Comparator R Review • API for sorting, solving problem review • Helpful on next APTs out 4/8/2020 Compsci 201, Spring 2020 5

  6. Exam 2 • Take any t y time me on F Frida iday A April il 1 10. M Maybe be earlie lier. • Ta Take on on Gradesc scop ope, DO DO NOT OT GO GO TO TO GRADE ADESCOPE UNTI UNTIL YO YOU ARE READY • ONCE YOU CLICK ON IT, YOUR TIMER STARTS • If If you canno annot take ke it it on on Frida iday, April il 10 10 • Fill out form to tell us why, and the soonest day you can take it • Fill ou out a ref eflect ect fo form afte ter taking the he e exam • Get 2 extra points • Give us feedback 4/8/2020 Compsci 201, Spring 2020 6

  7. More Exam 2 Details - GradeScope • MC, C, sho hort ans answer, and and s sho hort co code e seg egments. • You u will t ill type in, o in, or clic lick o on n ans answers • Sug uggest: w writ ite c code o on n pap aper and and t then hen type it e it in. in. • Submi mit eac each ques uestion as as yo you go. o. • Lose internet, just connect back in • Exam am is is ab about 1 1 ho hour ur, 15 15 min in • Yo You get an an ex extra 1 ho hour ur, 15 15 min f in for lo logistics • Total t al time i e is 2 2 hr hr, 30 , 30 min in • Tho Those w wit ith h acc accommodations, K Kate w will em ill email 4/8/2020 Compsci 201, Spring 2020 7

  8. Exam 2 – Honor Code • The e exam is s you our w wor ork on only • Use se book books, op open notes es, c code e you h u have w written en • Write c e code e on paper er o only, t then t en type e into Gradesc scop ope • DO DO NOT OT write te code de and nd run un it it in in I IntelliJ, Jshel hell or o other her comput uter er m means ans • DO N NOT Search on t n the he w web for a ans nswers to problems • DO NOT Talk to lk to any ny human ans a about ut the e e exam am d dur uring the e exam p m perio iod • DO DO NOT OT Ta Talk to to any ny hum humans abou out th the exam am until t til the exam i is ha handed back 4/8/2020 Compsci 201, Spring 2020 8

  9. Now let’s review for the exam 4/8/2020 Compsci 201, Spring 2020 9

  10. Runtime and Other Analysis • Asymptotic ic c comple lexit ity of runtim ime o e or memory • Return value: bleem(10)=88, bleem(20)=360 • 1+2+…+n=O(n 2 ) • Run untim ime and and v val alue • sum += 1 4/8/2020 Compsci 201, Spring 2020 10

  11. Intuition and Reality • "f "fun un" x 4 = 4 = " "funf nfunf unfunf unfun un" • https://www.youtube.com/watch?v=VbrEsOLu75c • Analyze only in terms of n, say with "fun" • It's all about line 34, how much does it matter? • 3, 6, 9, 3, 6, 9, 12, 12, …, 3n = , 3n = 3( 3(1 1 + 2 2 + … + n) n) s so b big ig-Oh Oh? • What if length of base is m, then big-Oh 4/8/2020 Compsci 201, Spring 2020 12

  12. Buffering … and faster • "f "fun un" x 4 = 4 = " "funf nfunf unfunf unfun un" • It's all about line 41, how much does is matter? • 3, 3, 3, 3, 3, 3, … ,3 = ,3 = so 3n and 3n and O(n) n) • What if length of base is m, then big-Oh? 4/8/2020 Compsci 201, Spring 2020 13

  13. WOTO-O Review http:// //bi bit.ly/2 /201spr pring20-04 0408 08-1 4/8/2020 Compsci 201, Spring 2020 14

  14. Compsci 201 201 Exam 2 2 Re Review, C , Compar arat ator ors, A , APTs Pa Part 2 2 of 4 f 4 Susan Rodger April 8, 2020 4/8/2020 Compsci 201, Spring 2020 15

  15. Recursive Insert and Recurrences • Recur currence nce rela elation f for .ad .add b belo elow? ? (TreeD reeDem emo.j .java) • https://coursework.cs.duke.edu/201spring20/classcode/ • T(N) is time to add one value to tree of N values, what is complexity of adding N values one-at-a-time? 4/8/2020 Compsci 201, Spring 2020 16

  16. Understand and Analyze • If tree h has as N values ues • One recursive call: T(n) = T(n/2) + O(1) • worst: T(n) = T(n-1) + O(1) , solutions? • We e do thi his n n tim imes. U Upper er b bound und n n lo log n, n, but ut … … • log(1) + log(2) + … + log(n) = log(1 ✕ 2 ✕ .. ✕ n) • log(n!) • n log n • Stirling's Formula 4/8/2020 Compsci 201, Spring 2020 19

  17. Recurrence Relations No need to derive, remember or look up Recurrence Algorithm Solution T(n) = T(n/2) + O(1) binary search O(log n) T(n) = T(n-1) + O(1) sequential search O(n) T(n) = 2T(n/2) + O(1) tree traversal O(n) T(n) = T(n/2) + O(n) quicksort partition O(n) T(n) = 2T(n/2) + O(n) mergesort, quicksort O(n log n) O(n 2 ) T(n) = T(n-1) + O(n) selection or bubble sort 4/8/2020 Compsci 201, Spring 2020 20

  18. WOTO Midterm Tree Review http:// //bi bit.ly/2 /201spr pring20-04 0408 08-2 4/8/2020 Compsci 201, Spring 2020 21

  19. Compsci 201 201 Exam 2 2 Re Review, C , Compar arat ator ors, A , APTs Pa Part 3 3 of 4 f 4 Susan Rodger April 8, 2020 4/8/2020 Compsci 201, Spring 2020 22

  20. Dina Katabi • Born i in Syria ia, , Professor at at MIT • ACM Hopper Award, ACM Fellow • MacArthur Genius Award • AI that sees through walls? • http://bit.ly/katabi-ted When I was a kid, I was, …, very much fascinated by Star Wars, and what fascinated me the most is this notion of the Force, this energy that connects all people and all objects and allows you to feel people that you can't even see. And I remember many nights, I would be sitting at home, just, like, concentrating and focusing, trying to feel the Force, and I didn't feel anything, don't worry. https://www.nytimes.com/2013/10/20/opinion/sunday/dina-katabi.html 4/8/2020 Compsci 201, Spring 2020 23

  21. Linked List - LowLevelLinkDemo.java • Conv nvert ar array t to link linked-lis list, v , value ues i in same o order https://course sework.cs. s.duke.edu/201sp sprin ing20/cla lassc sscode/ • • Cho hoices: ad add t to front o or bac ack o of lis list b bein eing b built uilt • If we add to front? loop over array values … • If we add to back? Need pointer to front too • Invar ariant iant? • last … 4/8/2020 Compsci 201, Spring 2020 24

  22. Add to Back Invariant • Cho hoices: ad add t to front o or bac ack o of lis list b bein eing b built uilt • If we add to back? Need pointer to front too • Invar ariant iant • last is last node of list with values in range [0,k) • True before loop guard first tested? [0,1) • Updated in loop? 4/8/2020 Compsci 201, Spring 2020 25

  23. Linked List Concepts Reviewed • Loop wit ith s h statement lis list = = list.nex .next • Recurse se wit ith c h cal all do doit(lis list.nex next) • Mus ust a assign t to .ne .next f fiel ield t to create a a link linked lis list • Can be via node constructor • Veri rify fy c code works: s: em empty lis list and and la last no node o e of lis list • void null-pointer dereference 4/8/2020 Compsci 201, Spring 2020 26

  24. WOTO Link Review http:// //bi bit.ly/2 /201spr pring20-04 0408 08-3 4/8/2020 Compsci 201, Spring 2020 27

  25. Compsci 201 201 Exam 2 2 Re Review, C , Compar arat ator ors, A , APTs Pa Part 4 4 of 4 f 4 Susan Rodger April 8, 2020 4/8/2020 Compsci 201, Spring 2020 28

  26. Sorting APTs • Creating ing i inne ner/nes /nested c classes es t to help • https://www2.cs.duke.edu/csed/newapt/clientlist.html • https://www2.cs.duke.edu/csed/newapt/medaltable.html • Sorting ing Map.E .Ent ntry<Key,Value ue> pa pairs • https://www2.cs.duke.edu/csed/newapt/sortbyfreqs.html • Sim imple U Use o e of API • https://www2.cs.duke.edu/csed/newapt/lengthsort.html 4/8/2020 Compsci 201, Spring 2020 29

  27. ClientsList APT • Nes ested c cla lass t tha hat c can an b be e compared: P Per erson • Two approaches • Implement Comparable and a newer approach • Solve? Translate, Process, Translate 4/8/2020 Compsci 201, Spring 2020 30

  28. How to sort: old and new • This This is is t the he OLD LD way to to sort i t in Java • Her ere is is ne newer way, no , no need need f for C Comparable 4/8/2020 Compsci 201, Spring 2020 31

  29. 4/8/2020 Compsci 201, Spring 2020 32

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend