1 / 67

Data Abstractions

Data Abstractions. Shyh-Kang Jeng Department of Electrical Engineering/ Graduate Institute of Communication Engineering National Taiwan University. Data Structures. Conceptual organization of data Basic data structures Homogeneous array List Stack Queue Tree. List.

kiril
Download Presentation

Data Abstractions

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. Data Abstractions Shyh-Kang Jeng Department of Electrical Engineering/ Graduate Institute of Communication Engineering National Taiwan University

  2. Data Structures • Conceptual organization of data • Basic data structures • Homogeneous array • List • Stack • Queue • Tree

  3. List • A collection of entries that appear in a sequential order • Examples • Class enrollment lists • “things-to-do” lists • Dictionaries • Sentences • Appear in both static and dynamic forms

  4. Stacks • A list in which all insertions and deletions are performed at the same end • A last-in, first-out (LIFO) structures • Push and pop Top B A C

  5. Queue • A list in which all insertions are performed at one end while all deletions are made at the other • A first-in, first-out (FIFO) structure • Head (front) and tail (rear)

  6. Organization Chart

  7. File Structure of Windows

  8. Trees

  9. Trees • Nodes • Root • Terminal (leaf) • Parent, children, siblings • Subtrees • Depth

  10. Data Abstraction • Explores ways in which users can be shielded from the details of actual data storage (memory cells and address) and be allowed to access information as though it were stored in a more convenient form – Concept of abstraction • The term user can be either human or a software module

  11. Static vs. Dynamic Structures • Static structures • Shape and size of the structure do not change over time • Easier to manage • Dynamic structures • Either shape or size of the structure changes over time • Must deal with adding and deleting data entries as well as finding the memory space required by a growing data structure

  12. Pointers • A memory cell (or perhaps a block of memory cells) that contains the address of another memory cell • Examples • Program counter as an instruction pointer • URL • Many programming languages include pointers as a primitive data type • Allow the declaration, allocation, and manipulation of pointers • Used to create dynamic data structures

  13. Use of Pointers

  14. Stack and Heap Space Heap Storage Stack Storage

  15. Homogeneous Arrays

  16. Two-Dimensional Array

  17. Storage of a 2-D Array • Row major order vs. column major order • Finding an entry in the th row and th column of a -column 2-D array stored in row major order Address polynomial

  18. Mini Review • Show how the array below would be arranged in main memory when stored in row major order

  19. Answer • 5 3 7 4 2 8 1 9 6

  20. Mini Review • Give a formula for finding the entry in the th row and th column of a 2-D array stored in column major order • In C, C++, and Java, indices of arrays start at 0 rather than 1. In this case what address polynomial is used by the translator to convert references of the form Array[i][j] into memory address?

  21. Answers

  22. Storing lists • Contiguous list = list stored in a homogeneous array • Linked list = list in which each node points to the next one • Head pointer = pointer to first entry in list • NIL pointer = non-pointer value used to indicate end of list

  23. Contiguous Lists

  24. Contiguous List • Convenient storage structure when implementing static lists • Inconvenient in dynamic cases • Delete a name • Move entries to keep the list in the same order • Add a name • Move the entire list to obtain an available block of contiguous cells large enough for the expanded list

  25. Linked List

  26. Deleting an Entry

  27. Inserting an Entry

  28. A Stack in Memory

  29. Operations on Queues

  30. Circular Queues (1)

  31. Circular Queues (2)

  32. Mini Review • Using paper and pencil, keep a record of the circular queue during the following scenario. Assume that the block reserved for the queue can contain only four entries. • Insert entries A, B, C • Remove two entries • Insert entries D, E • Remove an entry • Insert entry F • Remove an entry

  33. H T H T B C A B C H T T H H T H T C C D E C D E D T H H T E F D E F Answer

  34. Storing a binary tree • Linked structure • Each node = data cell + two child pointers • Accessed through a pointer to root node • Mapped to a contiguous array • A[1] = root node • A[2],A[3] = children of A[1] • A[4],A[5],A[6],A[7] = children of A[2] and A[3] • …

  35. Binary Tree Node

  36. Linked Storage System

  37. Storage without Pointers

  38. Inefficient Storage

  39. Mini Review • Draw a diagram representing how the tree below appears in memory when stored using the left and right child pointers. • Draw another diagram showing how the tree would appear in contiguous storage. y z x w

  40. Y X Z W Answer Y Z NIL NIL X NIL W NIL NIL

  41. Manipulating data structures • Ideally, a data structure should be manipulated solely by pre-defined procedures. • Example: A stack typically needs at least push and pop procedures. • The data structure along with these procedures constitutes a complete abstract tool.

  42. Printing a Linked List

  43. Binary Tree Package • Search for the presence of an entry • Use the binary search algorithm • Print the list in order • Insert a new entry

  44. Ordered Tree

  45. Search the Binary Tree

  46. Search Binary Tree

  47. Printing a Binary Tree

  48. Mini Review • Draw a binary tree to store the list R, S, T, U, V, W, X, Y, and Z for future searching

  49. Answer V Y T X Z U S W R

  50. Printing a Tree in Order

More Related