Download presentation

Presentation is loading. Please wait.

1
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists

2
Arrays Static Allocation of elements 2023541223

3
Linked Lists Dynamic allocation of new list elements.

4
Comparison of Implementations Array-Based Lists: Insertion is O( ). Direct access is ( ). No overhead if all array positions are full. Linked Lists: Insertion is ( ). Direct access is O( ). Every element requires overhead.

5
Stacks LIFO: Last In, First Out. Restricted form of list: Insert and remove only at front of list. Notation: Insert: PUSH Remove: POP The accessible element is called TOP.

6
Queues FIFO: First in, First Out Restricted form of list: Insert at one end, remove from the other. Notation: Insert: Enqueue Delete: Dequeue First element: Front Last element: Rear

7
Graphs A graph G = (V, E) consists of a set of vertices V, and a set of edges E, such that each edge in E is a connection between a pair of vertices in V. The number of vertices is denoted by |V| or n, and the number of edges is denoted by |E| or m.

8
Paths and Cycles Path: A sequence of vertices v 1, v 2, …, v n of length n-1 with an edge from v i to v i+1 for 1 i < n. A path is simple if all vertices on the path are distinct. A cycle is a path of length 3 or more that connects v i to itself. A cycle is simple if the path is simple, except the first and last vertices are the same.

9
Connected Components An undirected graph is connected if there is at least one path from any vertex to any other. The maximum connected subgraphs of an undirected graph are called connected components.

10
Complete Graphs An undirected graph is complete if A directed graph is complete if B D C A E

11
Bipartite Graphs An undirected graph, G=(V,E), is called bipartite if V can be partitioned into two non-empty sets X and Y such that each edge e in E has one end in X and the other in Y. A complete bipartite graph is BA E C F

12
Adjacency Matrix Representation of Graphs A B C D F E ABCDEF A B C D E F A B C D F E

13
Adjacency List Representation of Graphs A B C D F E A B C D F E 0 1 2 3 4 5

14
Planar Graphs Definition: A graph G = (V,E) is planar if it can be embedded in the plane without edge crossings

15
Examples B DC A B DC A

16
B DC A B DC A

17
B DC AE F

18
Planar Graphs Properties Let m, n, and r denote the number of edges, the number of vertices, and the number of regions in a planar graph, respectively. 1. n – m + r = 2(Euler’s Formula) 2. m 3n – 6 – m = O(n)

19
Rooted Trees A tree T is a connected undirected graph containing no cycles A rooted tree is a tree with a distinguished vertex r, called the root.

20
Theorem If T is a tree with n vertices, then –Any two vertices of T are connected by a unique path. –T has exactly n-1 edges –The addition of one or more edges to T creates a cycle.

21
Binary Trees Notation: Node, children, edge, parent, ancestor, descendant, path, depth, height, level, leaf node, internal node, subtree.

22
Full and Complete Binary Trees Full binary tree: Each node is either a leaf or internal node with exactly two non-empty children. Complete binary tree: If the height of the tree is d, then all levels except possibly level d are completely full. Level d has all nodes filled in to the left side.

23
Useful Theorems Theorem: The number of leaves in a non-empty full binary tree is one more than the number of internal nodes. Theorem: The number of nodes at level j 2 j. Theorem: The number of nodes, n, in a complete binary tree T of height k is such that 2 k n 2 k+1 -1 Theorem: The height of any binary tree with n vertices is at least log n and at most n – 1.

24
Traversals (1) Any process for visiting the nodes in some order is called a traversal. Any traversal that lists every node in the tree exactly once is called an enumeration of the tree’s nodes.

25
Traversals (2) Preorder traversal: Visit each node before visiting its children. Postorder traversal: Visit each node after visiting its children. Inorder traversal: Visit the left subtree, then the node, then the right subtree.

26
Binary Search Trees BST Property: All elements stored in the left subtree of a node with value K have values = K.

Similar presentations

© 2022 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google