big o and limits abstract data types data structure grand
play

Big O and Limits Abstract Data Types Data Structure Grand Tour - PowerPoint PPT Presentation

Big O and Limits Abstract Data Types Data Structure Grand Tour http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png Consider the limit ( ) f n lim g ( n ) n What does it say


  1. Big O and Limits Abstract Data Types Data Structure “Grand Tour” http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png

  2.  Consider the limit ( ) f n lim g ( n ) → ∞ n  What does it say about asymptotic relationship between f and g if this limit is… ◦ 0? ◦ finite and non-zero? ◦ infinite? Q5 Q5

  3. Q6 Q6 1. n and n 2 2. log n and n (on these questions and solutions ONLY, let log n mean natural log) 3. n log n and n 2 4. log a n and log b n (a < b) 5. n a and a n (a > =1) Recall l’Hôpital’s rule: under 6. a n and b n (a < b) appropriate conditions, and:

  4. What is data? What do we mean by structure?

  5. ◦ A set of operations ◦ May be provided by the hardware ( int and double ) ◦ By software ( java.math.BigInteger ) ◦ By software + hardware ( int[] )

  6.  A mathematical model of a data type  Specifies: ◦ The type of data stored ◦ The operations supported ◦ Argument types and return types of these operations ◦ What each operation does, but not how

  7.  One special value: zero  Three basic operations: ◦ succ ◦ pred ◦ isZero  Derived operations include plus  Sample rules: ◦ isZero(succ(n))  false ◦ pred(succ(n))  n ◦ plus(n, zero)  n ◦ plus(n, succ(m))  succ(plus(n, m m)) Q7 Q7

  8. Application: Specification Implementation: “how can you use that?” “what is it?” “How do you do that?” CSSE220 Q8 Q8 CSSE230

  9. Some review Some new All will appear again

  10.  Array  Map  List ◦ Tree Map ◦ Hash Map ◦ Array List  Priority Queue ◦ Linked List  Stack  Tree  Queue  Graph  Set  Network ◦ Tree Set ◦ Hash Set Implementations for almost all of these are provided by the Java Collections Framework in the java.util package.

  11. a L a[0] a[1]  Size must be declared when the a[2] array is constructed  Can look up or store items by index Example: a[i] nums[i+1] = nums[i] + 2;  How is this done? a[N-2] a[N-1] Q9 Q9

  12.  A list is an ordered collection where elements may be added anywhere, and any elements may be deleted or replaced.  Arr rray L Lis ist: t: Like an array, but growable and shrinkable.  Lin inked L Lis ist:

  13. Oper erat ations s Array rray L Lis ist Linke ked L d List t Provided ed Ef Effic icie iency Ef Effic icie iency Random access O(1) O(n) Add/remove item O(n) O(1) Q10 Q10

  14.  A last-in, first-out (LIFO) data structure  Real-world stacks ◦ Plate dispensers in the cafeteria ◦ Pancakes!  Some uses: ◦ Tracking paths through a maze ◦ Providing “unlimited undo” in an application Oper erat ations s Ef Effic icie iency Implemented by Provided ed Stack , LinkedList kedList , Stac and ArrayDeque ayDeque in Push item O(1) Java Pop item O(1)

  15.  first-in, first-out (FIFO) data structure  Real-world queues ◦ Waiting line at the BMV ◦ Character on Star Trek TNG  Some uses: ◦ Scheduling access to shared resource (e.g., printer) Oper erat ations s Ef Effic icie iency Implemented by Provided ed LinkedList and Enqueue item O(1) ArrayDeque in Java Dequeue item O(1)

  16. Q10-14 Q10 14  A collection of items with withou out du t duplic plicates (in general, order does not matter) ◦ If a and b are both in set, then !a.equals(b)  Real-world sets: ◦ Students ◦ Collectibles  One possible use: Example from 220 ◦ Quickly checking if an item is in a collection Operation tions Has ashSet TreeSet TreeS et Add/remove item O(1) O(log n) Contains? O(1) O(log n) Can hog space Sorts items!

  17. How ow is is a a Tree TreeMap like a like a TreeS TreeSet et? How ow is is it dif it differe erent?  Associate keys ys with va valu lues  Real-world “maps” ◦ Dictionary ◦ Phone book  Some uses: ◦ Associating student ID with transcript ◦ Associating name with high scores Operation tions Has ashMap TreeMap Tree Insert key-value pair O(1) O(log n) Look up the value associated O(1) O(log n) with a given key Can hog space Sorts items by key!

  18. Q15 Q15 Not like regular queues!  Each ite item stored has an associated prior priorit ity ◦ Only item with “minimum” priority is accessible ◦ Operations: insert , findMin , deleteMin  Real-world “priority queue”: ◦ Airport ticketing counter  Some uses ◦ Simulations ◦ Scheduling in an OS ◦ Huffman coding Oper erat ations s Ef Effic icie iency Provided ed Insert O(log n) The version in Warm Up Find Min O(log n) and Stretching isn’t this efficient. Delete Min O(log n)

  19.  Collection of nodes ◦ One specialized node is the root. ◦ A node has one parent (unless it is the root) ◦ A node has zero or more children.  Real-world “trees”: ◦ Organizational hierarchies Only if tree is ◦ Some family trees “balanced”  Some uses: ◦ Directory structure Oper erat ations s Ef Effic icie iency on a hard drive Provided ed ◦ Sorted collections Find O(log n) Add/remove O(log n)

  20.  A collection of nodes and edges ◦ Each edge joins two nodes ◦ Edges can be directed or undirected  Real-world “graph”: ◦ Road map  Some uses: ◦ Tracking links between web pages ◦ Facebook Depends on implementation Oper erat ations s Ef Effic icie iency (time/space trade off) Provided ed Find O(n) Add/remove O(1) or O(n) or O(n 2 )

  21.  Graph whose edges have numeric labels  Examples (labels): ◦ Road map (mileage) ◦ Airline's flight map (flying time) ◦ Plumbing system (gallons per minute) ◦ Computer network (bits/second)  Famous problems: ◦ Shortest path ◦ Maximum flow ◦ Minimal spanning tree ◦ Traveling salesman ◦ Four-coloring problem for planar graphs

  22.  Array  Map  List ◦ Tree Map ◦ Hash Map ◦ Array List  Priority Queue ◦ Linked List  Stack  Tree  Queue  Graph  Set  Network ◦ Tree Set ◦ Hash Set We’ll implement and use nearly all of these, some multiple ways. And a few other data structures.

  23. Struc uctu ture fi find nd inser sert/rem emove Commen omments Constant-time access by position Array O(n) can't do it Easy to implement as an array. Stack top only top only O(1) O(1) insert rear, remove front. Queue front only O(1) O(1) Constant-time access by position ArrayList O(log N) O(N) O(N) to find insertion position. Linked List O(n) O(1) If table not very full HashSet/Map O(1) O(1) Kept in sorted order TreeSet/Map O(log N) O(log N) Can only find/remove smallest PriorityQueue O(log N) O(log N) If tree is balanced Tree O(log N) O(log N) N nodes, M edges Graph O(N*M) ? O(M)? shortest path, maxFlow Network Q16 Q16-17 17

  24. If we have time left Make progress on Warm U Up p and nd Str tretc etching problems Get help as needed, especially with Eclipse and SVN issues Work on WA2 if you have finished WarmUpAndStretching

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