1 / 67

Lecture 41: Semester Review

CSC 213 – Large Scale Programming. Lecture 41: Semester Review. Final Exam. Tues., May 10 from 10:15 – 12:15 in OM 200 Plan on exam taking full 2 hours If major problem , come talk to me ASAP Exam covers material from entire semester Open-book & open-note so bring what you’ve got

Download Presentation

Lecture 41: Semester Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 213 – Large Scale Programming Lecture 41:Semester Review

  2. Final Exam • Tues., May 10 from 10:15 – 12:15 in OM 200 • Plan on exam taking full 2 hours • If major problem, come talk to me ASAP • Exam covers material from entire semester • Open-book & open-note so bring what you’ve got • My handouts, solutions, & computers are not allowed • Cannot collaborate with a neighbor on the exam • Problems will be in a similar style to 2 midterms • Lab mastery: 2:45 – 3:45 on Thurs., May 12 in OM119

  3. Lazy

  4. Contemplative

  5. Always Using Imagination

  6. Most Important Trait

  7. Critical Property of Test All goodtests FAIL

  8. Loop Testing: Simple Loops • Loop executed at most n times, try inputs that: • Skip loop entirely • Make 1 pass through the loop • Make 2 passes through the loop • Make m passes through the loop, where (m < n) • If possible, n-1,n,&(n+1)passesthrough the loop

  9. Indexed File Format • Split information into two (or more) files • Data file uses fixed-size records to store data • Index files contain search terms & location record starts • Fixed-size records usually used in data file • Each record will use exactly that much space • Extra space wasted if the value is smaller • But limits data size, cannot get more space • Makes it far easier to reuse space & rebuild index

  10. Entry ADT • Needs 2 pieces: what we have & what we want • First part is the key: data used in search • Item we want is value; the second part of an Entry • Implementations must define 2 methods • key()& value()return appropriate item • Usually includes setValue()but NOTsetKey()

  11. What is a Map? • At simplest level, Map is collection of Entrys • key-value pairs serve as the basic data in a Map • size() & isEmpty()work at level of Entry • Searchable data stored using Maps • put() adds an Entry so key is mapped to the value • get() retrieves valueassociated with key from Map • remove()deletes entire Entry • At most one value per key using a Map

  12. Dictionary ADT • Dictionary ADT very similar to Map • Hold searchable data in each of these ADTs • Both data structures are collections of Entrys • Convert key to valueusing either concept • Dictionary can have multiple values to one key • 1 value for key is still legal option

  13. Dictionary ADT • Dictionary ADT very similar to Map • Hold searchable data in each of these ADTs • Both data structures are collections of Entrys • Convert key to valueusing either concept • Dictionary can have multiple values to one key • 1 value for key is still legal option “pantsless”

  14. Dictionary ADT • Dictionary ADT very similar to Map • Hold searchable data in each of these ADTs • Both data structures are collections of Entrys • Convert key to valueusing either concept • Dictionary can have multiple values to one key • 1 value for key is still legal option “pantsless” • Also many Entryswith same key but different value “cool” “cool”

  15. Using Hash Properly • Normally, table holds one Entry per index • Need to be smarter when keys collide • Efficiency mattersimportantcritical • If we do not care, use List-based approach • Several common schemes used to provide speed • Each form of probing has strengths & weaknesses • Must consider bad hash effects before using • If this O(n) time unacceptable, use other leafy plant

  16. Using Hash Properly • Normally, table holds one Entry per index • Need to be smarter when keys collide • Efficiency mattersimportantcritical • If we do not care, use List-based approach • Several common schemes used to provide speed • Each form of probing has strengths & weaknesses • Must consider bad hash effects before using • If this O(n) time unacceptable, use other leafy plant

  17. Binary Search Trees • Implements a BinaryTree for searching • Map or Dictionary will be ADT exposed • Data organized to make usage efficient (maybe) • Strict ordering maintained in tree • Nodes to theleft are smaller • Larger keys in right child of node • Equal values not specified • No problem, just be consistent 6 2 9 10 1 4 6

  18. BST Performance • Search, insert, & remove take O(h) time • h is height of tree • Height’s best case is complete tree at O(log n) • O(n) height for linked list is BST’s worst case

  19. AVL Tree Definition • Fancy type of BST • O(logn) time provided • For this, needs more info 6 2 9 1 4 8 5

  20. AVL Tree Definition • Fancy type of BST • O(logn) time provided • For this, needs more info 4 6 3 2 2 9 1 2 1 1 4 8 1 5 Node heights are shown in blue

  21. AVL Tree Definition • Fancy type of BST • O(logn) time provided • For this, needs more info • Keep tree balanced by… • Checking heights of kids • Only let differ by 0 or 1 4 6 3 2 2 9 1 2 1 1 4 8 1 5 Node heights are shown in blue

  22. AVL Tree Definition • Fancy type of BST • O(logn) time provided • For this, needs more info • Keep tree balanced by… • Checking heights of kids • Only let differ by 0 or 1 • Fix larger differences by • Shifts nodes in the BST • For balance maintainence Trinode Restructuring 4 6 3 2 2 9 1 2 1 1 4 8 1 5 Node heights are shown in blue

  23. Building a SplayTree • Another approach which builds upon BST • Not anAVLTree, however, but a new BST subclass

  24. Concept Behind SplayTree • Splay trees do NOT maintain balance • Recently used nodes clustered near top of BST • Most recently accessed nodes take O(1) time • Other nodes may need O(n) time to access • Usually very efficient, but provides no guarantees

  25. Red-Black Tree • Root Property:Root node painted black • External Property: Leaves are painted black • Internal Property: Red nodes’ children are black • Depth Property: Leaves have identical blackdepth • Number of blackancestorsfor the node 9 4 15 21 2 6 12 7

  26. Map & Dictionary ADT

  27. Sorting is a Dance

  28. Sorting is a Dance

  29. Sorting is a Dance

  30. Merge Sort Execution Tree • Show steps used to sort all of the data 7 2 9 4 3 8 6 1 1 2 3 4 6 7 8 9 7 2 9 4 2 4 7 9 3 8 6 11 3 6 8 72 2 7 944 9 38 3 8 611 6 77 22 99 44 33 88 66 11

  31. Quick Sort • Divide: Partition by pivot • L has values <= p • G uses values >= p • Recur: Sort L and G • Conquer: Merge L, p, G p p G L p

  32. Quick Sort v. Merge Sort Quick Sort Merge Sort • Divide data around pivot • Want pivot to be near middle • All comparisons occur here • Conquer with recursion • Does not need extra space • Merge usually done already • Data already sorted! • Divide data in blindly half • Always gets even split • No comparisons performed! • Conquer with recursion • Needs* to use other arrays • Merge combines solutions • Compares from (sorted) halves

  33. Bucket & Radix Sort • Sort data written as tuple of enumerable data • Consumption of wine overall, in liters • Annual per capita consumption of liters • Sort one place in tupleusing bucket sort • Uses 1 bucket per value that could be enumerated • When there are ties, preserve relative ordering • Repeat stable sorts to perform radix sort • Must preserve relative ordering, like bucket sort • From least to most important sort each tuple place

  34. Radix-Sort In Action • List of 4-bit integers sorted using Radix-sort 1001 0010 1001 1001 0001 0010 1110 1101 0001 0010 1101 1001 0001 0010 1001 0001 1101 0010 1101 1101 0001 1110 1110 1110 1110

  35. Lower Bound on Sorting • Smallest number of comparisonsis tree’s height • Decision tree sorting n elements has n! leaves • At least log(n!) height needed for this many leaves • As we saw, this simplifies to at most O(n log n) height • O(n log n) time needed to compare data! • Practical lower bound, but cheating can do better • Need enumerable tuples- cannot always cheat • “If you believe radix hypothesis” it takes O(n) time

  36. Graph Applications • Electronic circuits • Transportation networks • Databases • Packing suitcases • Finding terrorists • Scheduling college’s exams • Assigning classes to rooms • Garbage collection • Coloring countries on a map • Playing minesweeper

  37. Edge List Structure u • Simplest Graph • Space efficient • No change to use withdirected or undirected a c b d v w z

  38. Edge List Structure u • Simplest Graph • Space efficient • No change to use withdirected or undirected • Fields • Sequenceof vertices a c b d v w z vertices z w v u

  39. Edge List Structure u • Simplest Graph • Space efficient • No change to use withdirected or undirected • Fields • Sequenceof vertices • Sequenceof edges a c b d v w z vertices z w v u edges c a b d

  40. Adjacency-List Implementation • Vertex has Sequence of Edges • Edges still refer to Vertex v b a u u w w

  41. Adjacency-List Implementation • Vertex has Sequence of Edges • Edges still refer to Vertex • Ideas in Edge-List serve as base v b a u u w w vertices w u v a b edges

  42. Adjacency-List Implementation • Vertex has Sequence of Edges • Edges still refer to Vertex • Ideas in Edge-List serve as base • Extends Vertex v b a u u w w vertices w u v a b edges

  43. Adjacency-List Implementation • Vertex has Sequence of Edges • Edges still refer to Vertex • Ideas in Edge-List serve as base • Extends Vertex • Add Position reference to speed removal v b a u u w w vertices w u v a b edges

  44. Adjacency Matrix Structure v b a • Edge-List structurestill used as base u w vertices 0 1 2 w v u a b edges

  45. Adjacency Matrix Structure v b a • Edge-List structurestill used as base • Vertex stores int • Index found in matrix u w vertices 0 1 2 w v u a b edges

  46. Adjacency Matrix Structure v b a • Edge-List structurestill used as base • Vertex stores int • Index found in matrix • Adjacency matrix in Graph class u w vertices 0 1 2 w v u a b edges

  47. Adjacency Matrix Structure v b a • Edge-List structurestill used as base • Vertex stores int • Index found in matrix • Adjacency matrix in Graph class • nullif not adjacent u w vertices 0 1 2 w v u a b edges

  48. Adjacency Matrix Structure v b a • Edge-List structurestill used as base • Vertex stores int • Index found in matrix • Adjacency matrix in Graph class • nullif not adjacent -or- • Edgeincidentto both vertices u w vertices 0 1 2 w v u a b edges

  49. Adjacency Matrix Structure v b a • Undirected edgesstored in both array locations u w vertices 0 1 2 w v u a b edges

  50. Adjacency Matrix Structure v b a • Undirected edgesstored in both array locations • Directed edgesonly in array from source to target u w vertices 0 1 2 w v u a b edges

More Related