Presentation is loading. Please wait.

Presentation is loading. Please wait.

Heaps Chapter 6 Section 6.9.

Similar presentations


Presentation on theme: "Heaps Chapter 6 Section 6.9."— Presentation transcript:

1 Heaps Chapter 6 Section 6.9

2 A particular kind of binary tree, called a heap
It has two properties: The value of each node is greater(max heap)/less (min heap) than or equal to the value stored in each of its children. The tree is perfectly balanced, and the leaves in the last level are all in the leftmost positions. Heaps can be implemented by arrays. Elements in a heap are not perfectly ordered. There is no relation between siblings .

3

4 Example: the array [2 8 6 1 10 15 3 12 11] seen as a tree
Different heaps constructed with the same elements

5 6.9.1 Heaps as Priority Queues
A heap is a way to implement priority queues. Using linked list to implement priority queue is ineffective with large number of nodes . Heap is perfectly balanced tree, so reaching a leaf requires less searches. Two procedures has to be implemented : Enqueue an element : the element is added at the end of the heap as the last leaf .

6

7 Dequeue an element : remove the root element from the heap. Why ?

8

9 Chapter 8 Graphs

10 Even though trees are flexible and have many applications, they have one limitation:
They can only represent relations of hierarchical type, such as relations between parent and child. Other relations are only represented indirectly. Graph, a generalization of a tree, is a data structure that contain a collection of vertices( or nodes) and the connections between them.

11 Terminology Graph collection of nodes (vertices)
collection of line segments connecting vertices (edges) Directed Each line segment has a direction (Arc) Undirected No direction on any line segment (Edge)

12

13 Neighbors Two vertices are said to be neighbors if an edge directly connects them Path A sequence of vertices in which each vertex is adjacent to the other Cycle A path that start and ends with the same vertex Loop A single Arc that begins and ends with the same vertex

14 Connected Graph There is a path from any vertex to any other vertex Vertex Degree Indegree Number of arcs entering the vertex Outdegree Number of arcs leaving the vertex

15 Storage Structures Two sets Vertices Edges Two Representations
Arrays (Adjacency Matrix) Linked Lists (Adjacency List)

16

17


Download ppt "Heaps Chapter 6 Section 6.9."

Similar presentations


Ads by Google