This comprehensive guide delves into the world of data structures, covering fundamental concepts such as arrays, lists, stacks, queues, and trees. It explores how data is organized, manipulated, and stored, highlighting the differences between static and dynamic structures. The guide illustrates key operations on stacks and queues, the concept of pointers, and the specifics of storing binary trees. With practical examples and mini-reviews, this resource is essential for anyone interested in computer science and efficient data management.
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
More Related Content
Presentation Transcript
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 • 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
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
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)
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
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
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
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
Mini Review • Show how the array below would be arranged in main memory when stored in row major order
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?
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
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
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
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
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] • …
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
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.