1 / 12

CS1020 Data Structures and Algorithms I Lecture Note #17

CS1020 Data Structures and Algorithms I Lecture Note #17. Mix-and-Match Data Structures with Multiple Organisation. Basic Data Structures. We can combine them to implement different data structures for different applications. Arrays Linked Lists Trees (to be covered in CS2010).

johnnym
Télécharger la présentation

CS1020 Data Structures and Algorithms I Lecture Note #17

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. CS1020 Data Structures and Algorithms ILecture Note #17 Mix-and-Match Data Structures with Multiple Organisation

  2. Basic Data Structures We cancombine them to implement different data structures for different applications. Arrays Linked Lists Trees (to be covered in CS2010) [CS1020 Lecture 17: Mix-and-Match]

  3. Mix-and-Match 1 2 3 • Array of Linked Lists • E.g.: Adjacent list for representing graph • E.g.: Hash table with separate chaining [CS1020 Lecture 17: Mix-and-Match]

  4. v2 v3 v1 v5 v4 G Adjacency List for Directed Graph 1 2 4 2 3 2 4 4 3 4 5 [CS1020 Lecture 17: Mix-and-Match]

  5. v2 v3 v1 v5 v4 G Adjacency Matrix for Directed Graph Matrix[i][j] = 1 if (vi, vj)E 0 if (vi, vj)E [CS1020 Lecture 17: Mix-and-Match]

  6. CS1102 AY2003 [CS1020 Lecture 17: Mix-and-Match]

  7. CS1102 AY2003: Use Adjacency Matrix O(1) O(1) O(1) O(n) [CS1020 Lecture 17: Mix-and-Match]

  8. CS1102 AY2003: Use Adjacency List 1 O(1) 2 3 O(n) 4 O(n) O(ni) [CS1020 Lecture 17: Mix-and-Match]

  9. Problem Use hashing. (i, j) as key and the hash value returned by hash function to be index to a hash table where (i, j) is stored together with the reference to the node in the linked list. Searching on an unsorted linked list is O(n) How to improve it to O(1)? [CS1020 Lecture 17: Mix-and-Match]

  10. Use Adjacency List 1 2 3 4 Is delete (i, j) O(1)? [CS1020 Lecture 17: Mix-and-Match]

  11. CS1102 AY2003 Build an adjacency list of the graph, where the lists are doubly linked. Build a hash table with (i, j) as key, and a reference to the node representing (i, j) in the adjacency list as value. [CS1020 Lecture 17: Mix-and-Match]

  12. End of file

More Related