1 / 25

COM212 Data Structures

COM212 Data Structures. Intro to Abstract Data Structures 4 Weeks ~7 Homework Problems Implementation of Abstract Data Structures 7 Weeks ~7 Programming Assignments Test Advanced Java Programming 3 Weeks Project. Today. Complexity Abstract Data Structures Lists Recursion.

ssweat
Download Presentation

COM212 Data Structures

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. COM212 Data Structures • Intro to Abstract Data Structures • 4 Weeks • ~7 Homework Problems • Implementation of Abstract Data Structures • 7 Weeks • ~7 Programming Assignments • Test • Advanced Java Programming • 3 Weeks • Project

  2. Today • Complexity • Abstract Data Structures • Lists • Recursion

  3. Complexity • How long functions take to run • Can be counted in number of instructions executed • Growth rate of functions • How much longer they take to run as size of the input increases

  4. Example Function One example(n) print x print y x = y2 What is the run time?

  5. Example Function One example(n) print x print y x = y2 The run time is 3.

  6. Example Function Two example(n) loop n times y = x + 1 x = y2 print x What is the run time?

  7. Example Function Two example(n) loop n times y = x + 1 x = y2 print x The run time is 4n

  8. Example Function Three example(n) print x print y loop n times y = x + 1 x = y2 print x What is the run time?

  9. Example Function Three example(n) print x print y loop n times y = x + 1 x = y2 print x The run time is 4n + 2

  10. Complexity Notation • We need some notation to help us categorize functions by how long they take to run. • Since the second two example functions will take about the same time to run, they should be in the same category. • Even functions with run times of 2n and 3n take similar time to run. • They are much more dependent on n than a function that takes constant time to run.

  11. Example A large n affects ex1() but not ex2() ex1(n) loop n times print x ex2(n) print x

  12. Big O f(n)≤cg(n) for all n≥n0

  13. Example f(n) = 4n + 2 using g(n) = n and c = 5 and n0 = 2 f(n)≤cg(n) for all n≥n0 is 4n + 2 ≤ 5n when n ≥2 So g(n) is n. The complexity of f(n) is O(n)

  14. Other Examples O(n) O(1) 4n+8 16 ¼(n-8) 296 200n+56801 1000302 O(n2) 4n2+18

  15. Others 56n + 7 0.34n – 455 0.003n2 + 3 14 5(lg n) + 5 98n4 + 2

  16. Data Structures • Data Types • A way of representing or organizing data • Examples • integer 5 • float 6.543 • character a • array

  17. Array 5 9 34 3 10 6 • Contiguous section of memory • Fixed size • Containing all one data type

  18. Abstract Data Structures • Independent of implementation • User does not care about the implementation • Set of operations to access / manipulate data • Examples: • FIFO queue • Return the largest from a set • List

  19. Abstract Data Structure • The user has a need for a specific DS, but the actual implementation is not of their concern. • The actual implementation is hidden from the user. • The programmer needs to ensure that the means of implementation allows the user to do everything that is required.

  20. Lists List L = x0 x1 x2 x3 … xn-1 n = # elements If a list is ordered than the key of xi-1 <= the key of xi for all i where 0 < i < n. The sort symbol <= can be replaced by >= or any other function that determines ordering in the keys. An unordered list does not have this restriction. Functions: access(L, i) returns xi length(L) returns n concat(L1, L2) returns a new list with L2 concatenated on to L1 createEmptyList() returns a newly created empty list isEmptyList(L) returns true if L is empty and false if it is not searchFor(L, key) returns i where key of xi = key remove(L, i) returns a list with xi removed; the old xi+1 is now xi, etc. inserti(L, i, x) returns a list with x inserted as xi; the old xi is now xi+1, etc. insert(L, x) returns a list with x added to L sort(L) returns the list in sorted order

  21. A Node NameLast: Smart FirstName: Joe StudentNumber: 8 SSN: 123-34-1112 Grade: 95

  22. Problem • We need a list that has a maximum of 100 nodes. • How can you implement this kind of list?

  23. Homework 0 • Describe how to use an array to implement an unordered list (assume a max size of 100 elements). • Determine how to do the following functions: access, length, concat, createEmptyList, isEmptyList, searchFor, remove, and insert. • How would any of these functions change if the list was to be ordered?

  24. COM212 Java Tutorial Link: https://www.codecademy.com/learn/learn-java • Unit 1: Introduction to Java Due on 2/6/19 • Unit 2: Conditionals and Control Flow Due on 2/13/19 • Unit 3: Object-Oriented Java Due on 2/20/19

  25. Recursion

More Related