Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.

Similar presentations


Presentation on theme: "ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material."— Presentation transcript:

1 ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE

2 Syllabus Introduction Linear List Stack Queue Tree Implementation

3 2 Abstract Data Structures A data structure is a method or mechanism for representing and storing data in a computer. Data structure design depends on:  the type of data being stored  how the data is organized  how the data should be accessed Many commonly used data structures are examples of graphs.

4 3 Graph → abstract data structure in which a set of nodes (or vertices) are connected together by a set of links (or edges) Link connections represent node relationships. A node contains:  Data  Link(s) (i.e., which other nodes it is connected to)

5 4 Examples of different graph sub-classes: Abstract data structures are used to model:  Computer and communication networks (graphs)  Binary search and heaps (trees)  Stacks and queues (lists) General Graph Any node may connect to any other node and cycles are allowed General Tree A graph in which no cycles are allowed Hierarchical Tree (Binary version) Each node descends from one parent node and has zero or more child nodes Linear List A sequential set of nodes Ring A list that forms a closed loop

6 5 Operations on Abstract Data Structures Typical types of operations performed on an abstract data structure include:  Create node  Insert node  Remove node  Traverse nodes  Search nodes  Check if node is empty

7 6 Linear List Insert and remove operations can occur anywhere within the list. A B C list Linear List A B C “insert” operation list A B D C A D C D “remove” operation A B D C list

8 7 Stack – Last In, First Out (LIFO) Insert (“push”) and remove (“pop”) operations can only occur at the top of the stack. A B C top D A B C D A B C Stack A B C top “push” operation A B C D top “pop” operation

9 8 Queue – First In, First Out (FIFO) Insert (“enqueue”) operations occur at the tail, while remove (“dequeue”) operations occur at the head. A B C head D Queue tail A B C “enqueue” operation head tail A B C D head tail B C D head tail “dequeue” operation A B C head D tail

10 9 Graphs and Trees Insert and remove operations are more complicated, especially if a balanced structure is required.

11 10 Implementation of Abstract Data Structures The C language’s struct type is used to represent a node. The structure’s member variables contain:  Data  Link information

12 11 Ways to implement abstract data structures:  Array of nodes The maximum number of nodes is fixed at compile-time (though run-time allocation can get around this). Any node can be directly accessed via the array index. Link information is the array index of another node.  Nodes connected by pointers The maximum number of nodes is determined at runtime (can grow or shrink). Nodes must be accessed sequentially via pointer links. Link information is a pointer to another node.

13 12 Conceptual implementations of data structures: Singly-linked List (array) data next: 1 0 data next: 2 1 data next: 3 2 data next: -1 3 Singly-linked List (pointer) data next data next data next data next NULL p Doubly-linked List (pointer) data nextprev data nextprev data nextprev data nextprev NULL p data leftright data leftright Binary Tree (pointer) NULL data leftright NULL data leftright NULL p


Download ppt "ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material."

Similar presentations


Ads by Google