data structures chapter 6. data structure a data structure is a representation of data and the...

14
Data Structures Chapter 6

Upload: amos-booker

Post on 18-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Data Structures

Chapter 6

Page 2: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Data Structure

A data structure is a representation of data and the operations allowed on that data.

Examples:

1. Array

2. Record

3. String

Page 3: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Examples of data structures

1. Stack2. Queue3. Linked List4. Tree5. Hash Table6. Priority Queue7. Heap8. Binary Search Tree

Page 4: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Stack

A stack is a data structure into which items may be inserted and from which items may be deleted at one end, called the top of the stack. That is, a data structure in which access is restricted to the most recently inserted item.

A stack is a LIFO structure – last in first out.

Page 5: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Operations on Stacks

1. push – add an element to the top of the stack2. pop – read and remove an element from the

top of the stack3. top – read the top element (without removing

it)4. isEmpty – returns true if no element in the

stack5. isFull – returns true if the stack can hold no

more elements6. Destroy – get rid of stack

Page 6: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Queue

A queue is a data structure from which items may be deleted at one end (called the front of the queue) and into which items may be inserted at the other end (called the rear of the queue). That is, a data structure which restricts access to the least recently inserted item.

A queue is a FIFO structure – first in first out

Page 7: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Operations -- Queue 1. enqueue – add an element at the rear of the

queue2. dequeue – read and remove an element from

the front of the queue.3. getFront – read (without removing) the element

in front of the queue.4. isEmpty – returns true if there is no element in

the queue5. isFull – returns true if the queue can hold no

more elements6. destroy – get rid of the queue

Page 8: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Linked List

A linked list is collection of items in which items have a position. That is, a collection of nodes that hold data and pointers to the next node (and possibly to the previous node) in the list.

Page 9: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Operations – Linked list

1. Add an element

2. Remove an element

3. Find an element

4. Check for an empty list

5. Destroy the list

Page 10: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Tree

A tree consists of a set of nodes and a set of edges that connect pairs of nodes such that

1. One node is distinguished as the root.

2. Every node c, except the root, is connected by an edge from exactly one other node p. p is c’s parent and c is one of p’s children.

3. A unique path traverses from the root to each node.

Page 11: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Tree Operations

1. Insert element

2. Remove element

3. Find element (Search)

4. Traverse – move through the tree and visit each node

5. Check if the tree is empty

Page 12: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Binary Tree

A binary tree is a tree such that each node has at most two children.

A binary search tree is a binary tree that has its data values arranged as follows: each node in the tree contains a value that is larger than each value in its left subtree and smaller than each value in its right subtree.

Page 13: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Hash Table

A data structure that allows very fast find, add, and delete operations (most of the time).

Hash Function - converts a data value into an index.

Page 14: Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record

Priority Queue

A priority queue is like a queue, but elements are deleted in order of priority

Uses:– Emergency room– Main Frame Job Control

• payroll would be assigned a higher priority than some other jobs

– Event-driven simulation– Printer Queue