1.[10] Suppose we have 14 integers: 10, 100, 30, 130, 80, 50, 140, 20, 60, 70, 120, 40, 90, 110. Please create a 2-3 tree by inserting one integer at a.

Slides:



Advertisements
Similar presentations
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
Advertisements

Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Breadth-First Search Text Read Weiss, § 9.3 (pp ) Breadth-First Search Algorithms.
Graph Searching CSE 373 Data Structures Lecture 20.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Breadth-First Search Seminar – Networking Algorithms CS and EE Dept. Lulea University of Technology 27 Jan Mohammad Reza Akhavan.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 8, Part I Graph Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Data Structure and Algorithms (BCS 1223) GRAPH. Introduction of Graph A graph G consists of two things: 1.A set V of elements called nodes(or points or.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
CHAPTER 13 Graphs DATA ABSTRACTION AND PROBLEM SOLVING WITH C++ WALLS AND MIRRORS Third Edition Frank M. Carrano Janet J. Prichard Data Abstraction and.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
1 Representing Graphs. 2 Adjacency Matrix Suppose we have a graph G with n nodes. The adjacency matrix is the n x n matrix A=[a ij ] with: a ij = 1 if.
授課教授:李錫智 Data Structures -3 rd exam-. 1.[5] Refer to the two trees in Fig. 1. Let’s define the balance factor BF of a node to be the absolute value of.
Midterm 2 Overview Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Huffman Coding Draw the tree, label all nodes w/ index, leaves w/ letter and all links(0 or 1) What is the most frequent letter? What is the least frequent.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Graphs Chapter 28 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Exam 2 Review. Teams Dan C, Z, Hugh, Zane, Alexis Mark, Jamie, Ryan, Alex H, Andrew Katie, Emily, Riley, Rohan, Alex D Dawn, Patrick, Jacapo, Catharine,
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Chapter 28 Weighted Graph Applications. 2 Objectives F To represent weighted edges using adjacency matrices and priority queues (§28.2). F To model.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 28 Weighted Graph.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
§3 Dynamic Programming 3. Optimal Binary Search Tree —— The best for static searching (without insertion and deletion) Given N words w 1 < w 2 < ……
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Review for Final Exam – cs411/511 Definitions (5 questions, 2 points each) Algorithm Analysis (3 questions, 3 points each) General Questions (3 questions,
Data Structures -Final exam- 2015/6/22 授課教授:李錫智. Question 1. Let a hash table have 13 entries. Suppose we have 10 integer keys: 68, 100, 58, 80, 72, 101,
Data Structures -3 st exam- 授課教師 : 李錫智 教授. 1. [5] Assume we have a binary tree which is implemented in a pointer-based scheme. Describe how to know the.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graphs Upon completion you will be able to:
Graph Theory. undirected graph node: a, b, c, d, e, f edge: (a, b), (a, c), (b, c), (b, e), (c, d), (c, f), (d, e), (d, f), (e, f) subgraph.
Graph and Digraph Sung Yong Shin TC Lab. CS Dept., KAIST.
Hello Everyone!!! 1. Tree And Graphs 2 Features of Trees  Tree Nodes Each node have 0 or more children A node have must one parent  Binary tree Tree.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Exam 2 Review. Teams David P, Sebastian, Nathan P, Harrison Scott, Josh, Patrick, Peter Michael, Alexia, Betsey, Keith Ty, Casey, Jesi, Lexa Maddie, Nathan.
AVL Tree: Balanced Binary Search Tree 9.
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
Graphs Chapter 20.
Minimum Spanning Tree Chapter 13.6.
Binary search tree. Removing a node
Week 11 - Friday CS221.
Ellen Walker CPSC 201 Data Structures Hiram College
CS 3343: Analysis of Algorithms
CS120 Graphs.
Comp 245 Data Structures Graphs.
Chapter 15 Lists Objectives
Graph Algorithm.
Graphs Chapter 13.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Chapter 11 Graphs.
ITEC 2620M Introduction to Data Structures
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

1.[10] Suppose we have 14 integers: 10, 100, 30, 130, 80, 50, 140, 20, 60, 70, 120, 40, 90, 110. Please create a 2-3 tree by inserting one integer at a time in the order shown. Please draw the resulting 2-3 tree after each insertion for the last five insertions. Ans: 1010, , , , , , , , , , 2050, , 140

30, , 2050, , , , Insert , , , 80 Insert , , , 130

Insert , 20 70, , , 50 Insert , , 20 40,

Insert , , 20 40, ,

2.[10] Suppose we have 14 integers: 10, 190, 100, 30, 130, 80, 180, 50, 140, 20, 200, 60, 160, 120. Please create a tree by inserting one integer at a time in the order shown. Please draw the resulting tree after each insertion for the last five insertions

3-1( 插入 100) 3.[10] Suppose we have 14 integers: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140. Please create an AVL tree by inserting one integer at a time in the order shown. Please draw the resulting AVL tree after each insertion for the last five insertions.

3-2 ( 插入 110)

3-3 ( 插入 120)

3-4 ( 插入 130)

3-5 ( 插入 140)

4. [10] Suppose we have 14 integers: 10, 20, 30, 40, 50, 80, 100, 120, 130, 160, 180, 29, 48, 68. Please create a hash table of size 17, with linear probing and the hash function h(x) = x%17, by inserting one integer at a time in the order shown. Please draw the resulting hash table after each insertion for the last two insertions. 4-1( 紅色字代表插入的數字 ) 4-2( 紅色字代表插入的數字 )

5.[10] Suppose we have 14 integers: 10, 20, 30, 40, 50, 80, 100, 120, 130, 160, 180, 29, 48, 68. Please create a hash table of size 17, with double hashing and the hash functions h 1 (x) = x%17 and h 2 (x) = 7 – (x%7), by inserting one integer at a time in the order shown. Please draw the resulting hash table after each insertion for the last two insertions. 5-1( 紅色字代表插入的數字 ) 5-2( 紅色字代表插入的數字 )

6.[10] Suppose we have a 2-3 tree shown in Figure 1. Please answer the following questions: a)[2.5] Please insert 45 into Figure 1 and show the resulting 2-3 tree. Ans: 30, 35 37, , , 20 33, , 35 37, , , 45 10, 20 33,

b)[2.5] Please insert 15 into Figure 1 and show the resulting 2-3 tree. Ans: c)[2.5] Please insert 32 into Figure 1 and show the resulting 2-3 tree. Ans: 39 70, , , ,

d)[2.5] Please insert 25 into Figure 1 and show the resulting 2-3 tree. Ans: 39 70, ,

7.[10] Suppose we have a 2-3 tree shown in Figure 1. Please answer the following questions: a)[5] Please delete 34 from Figure 1 and show the resulting 2-3 tree. Ans: 30, 35 37, , , 20 33, , 35 37, , ,

b)[5] Please delete 50 from Figure 1 and show the resulting 2-3 tree. Note that a deleted node is replaced by the least number in its right subtree. Ans: 30, 35 37, , 20 33, , 80 36

8.[10] Suppose we have a tree shown in Figure 2. Please answer the following questions: [2.5] Please insert 45 into Figure 2 and show the resulting tree. [2.5] Please insert 18 into Figure 2 and show the resulting tree. [2.5] Please insert 31 into Figure 2 and show the resulting tree. [2.5] Please insert 16 into Figure 2 and show the resulting tree.

a

b

c

d

9.[10] Suppose we have a tree shown in Figure 2. Please answer the following questions: [5] Please delete 33 from Figure 2 and show the resulting tree. [5] Please delete 35 from Figure 2 and show the resulting tree. Note that a deleted node is replaced by the least number in its right subtree.

a

b

10.[10] Suppose we have an undirected graph shown in Figure 3. Please answer the following questions: [2.5] Please show the adjacency matrix for this graph (ignore the weights). [2.5] Please show the adjacency list for this graph (ignore the weights). Note that the nodes in a linked list should be alphabetically ordered. [2.5] Please find a minimum spanning tree for this graph starting from node a using the algorithm introduced in the class. Note that a node that is alphabetically smaller should be selected earlier. Hint: The addition of an edge should not cause a cycle. [2.5] Please using the breadth-first search algorithm to visit the graph starting from node a. Note that a node that is alphabetically smaller should be visited earlier. Please indicate the order of each node in the traversal.

abcdefghi a b c d e f g h i a.

b.

C. D. a b c d e f h g i a cbd h e f ig

11.[10] Suppose we have a directed graph shown in Figure 4. Please answer the following questions: [2] Please show the adjacency matrix for this graph (ignore the weights). [2] Please show the adjacency list for this graph (ignore the weights). Note that the nodes labeled with smaller numbers should appear earlier in a linked list. [6] Find the shortest distances from node 0 to all the other nodes using the algorithm introduced in the class. Note that the nodes labeled with smaller numbers should be selected earlier. A

B.

C Step Step Step Step Step Step Step Step Step Step