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,

Slides:



Advertisements
Similar presentations
Author : Chia-Hung Lin, Chia-Yin Hsu, and Sun-Yuan Hsieh Publisher : IEEE TRANSACTIONS ON PARALLEL AND DISTRIBUTED SYSTEMS.
Advertisements

Colorings of graphs and Ramsey’s theorem
O(N 1.5 ) divide-and-conquer technique for Minimum Spanning Tree problem Step 1: Divide the graph into  N sub-graph by clustering. Step 2: Solve each.
The swap edges of a multiple source routing tree * 樹德資工 † 台大資工 Bang Ye Wu* Chih-Yuan Hsiao † Kun-Mao Chao †
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Prim’s Algorithm from a matrix A cable TV company is installing a system of cables to connect all the towns in the region. The numbers in the network are.
Instructor: Ching-Chi Lin 林清池 助理教授
3Com Switch 4500 切VLAN教學.
授課教授:李錫智 Data Structures -2 nd exam-. 1.[15] A simple way for implementing the vector ADT is to use an array A, where A[i] stores the element at rank.
授課教授:李錫智 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.
授課教授:李錫智 Data Structures -4 th exam-. 1.[10] Suppose we have a text and a pattern shown in Fig.1. You apply the brute-force pattern matching algorithm.
Introduction to Computers - 2 nd exam- 授課教授:李錫智. 1. Double the Number
Midterm 2 Overview Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Graph V(G 1 )={0, 1, 2, 3, 4, 5, 6, 7, 8, 9} E(G 1 )={(0, 2), (0, 3), (1, 4), (2, 3), (2, 5), (2, 6), (3, 6), (3, 7), (4, 7), (5, 6), (5,
: ShellSort ★★☆☆☆ 題組: Problem D 題號: 10152: ShellSort 解題者:林一帆 解題日期: 2006 年 4 月 10 日 題意:烏龜王國的烏龜總是一隻一隻疊在一起。唯一改變烏龜位置 的方法為:一隻烏龜爬出他原來的位置,然後往上爬到最上方。給 你一堆烏龜原來排列的順序,以及我們想要的烏龜的排列順序,你.
Binary Search (I) Date: June 17, 2009 Introducer: Hsing-Yen Ann.
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
程式註解說明. 2 程式註解格式 塊狀註解 對檔案、 class 、 method 、資料結構、一段程式 …. 等程式區塊 做說明。 第一行的開頭必需為 “/*” 且沒有其他文字,最後一行的開頭 必需以 “*/” 做為結束,在中間每一行的開頭都必需是一個 “*” 。 單行註解 佔據一整行的說明。 以.
8.1 何謂高度平衡二元搜尋樹 8.2 高度平衡二元搜尋樹的加入 8.3 高度平衡二元搜尋樹的刪除
: The Playboy Chimp ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10611: The Playboy Chimp 解題者:蔡昇宇 解題日期: 2010 年 2 月 28 日 題意:給一已排序的數列 S( 升冪.
Failure Candidate Identification for Silicon Debug 指導教授:林榮彬 教授 李婉如 許智涵.
第 5 章 深入 Response 物件 製作. 網頁的轉向與強制輸出 - 讓網頁轉彎的 Redirect 敘述 運用 Response 物件的 Redirect 方法,將瀏覽器顯 示的網頁,導向至其他網頁,語法如下: Response.Redirect 網頁路徑與名稱 此網頁路徑與名稱  若是導向到同一台.
計算機概論 - 排序 1 排序 (Sorting) 李明山 編撰 ※手動換頁.
: Happy Number ★ ? 題組: Problem Set Archive with Online Judge 題號: 10591: Happy Number 解題者:陳瀅文 解題日期: 2006 年 6 月 6 日 題意:判斷一個正整數 N 是否為 Happy Number.
Digital Signal Processing with Examples in M ATLAB ® Chap 1 Introduction Ming-Hong Shih, Aug 25, 2003.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Johnson’s algorithm Johnson’s演算法可用於計算All pairs shortest path問題。
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
從此處輸入帳號密碼登入到管理頁面. 點選進到檔案管理 點選「上傳檔案」上傳資料 點選瀏覽選擇電腦裡的檔案 可選擇公開或不公開 為平台上的資料夾 此處為檔案分類,可顯示在展示頁面上,若要參加 MY EG 競賽,做品一律上傳到 “ 98 MY EG Contest ” 點選此處確定上傳檔案.
資料結構實習-一 參數傳遞.
Deletion in MIN-MAX Heaps Delete min element Delete max element.
4 堆疊與佇列 4.1 前言 四種基本的資料結構 (可儲存資料的容器) 陣列 (Array)、串列(List): 最基本
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
資料結構實習-二.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
Review of Chapter 9 張啟中. Inheritance Hierarchy Min PQ Max PQ Min Heap Mergeable Min PQ DeapMin-Max Min-LeftistMin-SkewMinFHeap MinBHeap DEPQMax Heap Symmetric.
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Chapter 10 m-way 搜尋樹與B-Tree
: Function Overloading ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11032:Function Overloading 解題者:許智祺 解題日期: 2007 年 5 月 8 日 題意:判對輸入之數字是否為.
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
INFORMATION RETRIEVAL AND EXTRACTION 作業: Program 1 第十四組 組員:林永峰、洪承雄、謝宗憲.
中序轉後序 藉由由左向右掃瞄中序運算式產生後序運算式,遇到 運算元就直接輸出,遇到運算符號則先存入堆疊,將 優先權較高者輸出。 範例: a + b * c TokenStack [0] [1] [2] topoutput aa ++0a b+0ab *+ *1ab c+ *1abc eosabc*+
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
著作權所有 © 旗標出版股份有限公司 第 14 章 製作信封、標籤. 本章提要 製作單一信封 製作單一郵寄標籤.
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,
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.
Graph Theory Chapter 7 Eulerian Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)
IT 60101: Lecture #151 Foundation of Computing Systems Lecture 15 Searching Algorithms.
CS Data Structures II Review & Final Exam. 2 Topics Review Final Exam.
Chapter 3 Trees and Forests 大葉大學 資訊工程系 黃鈴玲
Final Exam Tuesday, December 22nd 2:00 - 3:50pm room 102 Warren Weaver Hall.
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 -3 rd test- 2015/06/01 授課教授:李錫智. Question 1 Suppose we use an array to implement a sorted list. Please answer the following questions.
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.
6.1.3 Graph representation.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Data Structures -2 nd exam- 授課教師 : 李錫智 教授 1. 1.[10] Please answer the following questions about stack: What is the response of the statement “(new stack()).isEmpty()”?
Data Structures -3 rd exam- 授課教授:李錫智. 1.[10] Suppose we want to implement a queue by using the following List operations: getLength(); remove(position);
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.
Data Structures -3 rd exam- 授課教師 : 李錫智 教授. 1.[10] Please answer the following questions about queue: [ 2] What is the response of the statement: “(new.
Group 2 Block 胡貴蓉 Project 2 JMVC code tracing.
Chapter 28 Weighted Graphs and Applications
Chapter 13 Graph Algorithms
6.1.3 Graph representation.
Presentation transcript:

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, 24, 34, 45, 16. Let the hash function be h(x) = x%13 and the linear probing be used for resolving collisions. (a) Insert these keys into the hash table in order. Show the hash table after the insertions. (b) Please describe the process of finding 45 from the hash table. (c) Please describe the process of inserting 46 into the hash table.

Solution to Q1. (a) (b) 先檢查 index: 45%13=6, 若 index 6 存放的 integer keys 不為 45 ,則檢查 index: (6+i)%13, i 為 1~12 ,直至找到 45 或空的 index 為止 (c) 46%13=7 ,檢查 index 7 是否有空位,若沒有 空位則檢查 index 8 ,直至找到空位或找完為止

Question 2. Let a hash table have 13 entries. Suppose we have 10 integer keys: 68, 100, 58, 80, 72, 101, 24, 34, 45, 16. Let the hash function be h(x) = x%13 and the quadratic probing be used for resolving collisions. (a) Insert these keys into the hash table in order. Show the hash table after the insertions. (b) Please describe the process of finding 45 from the hash table. (c) Please describe the process of inserting 46 into the hash table.

Solution to Q2. (a) (b) 45%13=6 ,比對 hash table index 為 (6+n 2 )%13 的位址內是否為 45 ,其中 n=0, 1, 2, …. ,若是 45 則回傳 (6+n 2 ) % 13 就是 45 的 hash table 位址 (c) 46%13=7 ,尋找 hash table index 為 (7+n 2 ) % 13 的位址,其中 n=0, 1, 2, …. ,直到找到第一個 空的位址或找完為止

Question 3. Let a hash table have 13 entries. Suppose we have 10 integer keys: 68, 100, 58, 80, 72, 101, 24, 34, 45, 16. Let double hashing be used for resolving collisions and the hash functions be h1(x) = x%13 and h2(x) = 7 – (x%7). (a) Insert these keys into the hash table in order. Show the hash table after the insertions. (b) Please describe the process of finding 45 from the hash table. (c) Please describe the process of inserting 46 into the hash table.

Solution to Q3. (a) (b) 先檢查 index: h1(45)= 45%13=6 ,若沒找到則 檢查 h1(45)+i*h2(45)=6+i*4, 其中 i=1, 2, … 直到找 到 45 或空位為止 (c) 先檢查 index: h1(46)= 46%13=7 是否有空位, 若沒有則檢查 h1(46)+i*h2(46)=6+i*3, 其中 i=1, 2, … 直到找到空位或找完為止

Question 4. Let a hash table have 13 entries. Suppose we have 10 integer keys: 68, 100, 58, 80, 72, 101, 24, 34, 45, 16. Let the hash function be h(x) = x%13 and the separate chaining be used for resolving collisions. Note that a key is inserted as the head of a link. (a) Insert these keys into the hash table in order. Show the hash table after the insertions. (b) Please describe the process of finding 45 from the hash table. (c) Please describe the process of inserting 46 into the hash table.

Solution to Q (a) (b)45%13=6 ,在 index 6 的 link 上依次尋找 45 ,直 到找到或找完 (c)46%13=7 ,在 index 7 的 head 端接上 46 ,並將原 先存於 head 端的 index 接到 46 之後

Question 5. Suppose we have 20 integer keys: 50, 90, 20, 70, 120, 150, 10, 30, 40, 60, 80, 100, 110, 130, 140, 160, 170, 180, 190, 200. (a) Please construct a binary search tree and show the resulting tree. (b) Please construct a 2-3 tree by inserting the keys one by one. Show the tree each time the height of the tree increases by one. Also, please show the final tree. (c) Please construct an AVL tree by inserting the keys one by one. Show the tree each time the height of the tree increases by one.

Solution to Q5-a. (a)

Solution to Q5-b , , , , ,

Solution to Q5-c

Question 6. Suppose we have an 2-3 tree shown in Figure 1. Let a deleted item be replaced by the smallest of its right child. Please do the following: (a) From Figure 1, delete 130 and show the resulting tree. (b) From Figure 1, delete 10 and show the resulting tree. (c) From Figure 1, delete 160 and show the resulting tree. (d) From Figure 1, delete 120 and show the resulting tree. (e) From Figure 1, delete 60 and show the resulting tree.

50, , , , 110 (a) Solution to Q6-a.

50, , , , (b) 50, , , , (c) Solution to Q6-b.

50, , , , (d) 90 20, , , , , (e) 70, 80 Solution to Q6-c.

Question 7. Consider Figure 2. and answer the following questions: (a) Please show the graph in the form of adjacency matrix. (b) Please show the graph in the form of adjacency list.

Solution to Q7. (a) abcdeF a∞10∞3∞2 b∞∞∞∞∞∞ c1∞∞∞∞∞ d257∞6∞ e∞∞49∞8 f115∞∞∞∞ (b) a -> b,10 -> d,3 -> f,2 b c -> a,1 d -> a,2 -> b,5 -> c,7 -> e,6 e -> c,4 -> d,9 -> f,8 f -> a,1 -> b,15

Question 8. Consider Figure 3. and answer the following questions: (a) Please do the graph traversal using the depth-first search, starting with vertex a. (b) Please do the graph traversal using the breadth-first search, starting with vertex a. Note that if two or more vertices qualify, then the one with the least alphabetical order is selected.

Solution to Q8. (a) a, b, c, d, e, f, g, h, i (b)a, b, h, i, c, d, g, e, f

Question 9. Consider Figure 2. Let vertex a be the origin. Please find the shortest paths from a to the other vertices using the Dijkstra’s shortest-path algorithm. Note that if two or more vertices qualify, then the one with the least alphabetical order is selected. (a) Please show the table after one vertex is selected. (b) Please show each path from vertex a and its distance.

Solution to Q9. (a) abCdeF a010∞3∞2 a, f010∞3∞2 a, f, d a, f, d, b a, f, d, b, e a, f, d, b, e, c (b) a-f : 2 a-d : 3 a-d-b : 8 a-d-e : 9 a-d-c : 10

Question 10. Consider Figure 4. Let vertex a be the origin. Please find the minimum spanning tree for it using the Prim’s algorithm. Note that if two or more vertices qualify, then the one with the least alphabetical order is selected.

Solution to Q10.

Question 11. Consider Figure 3. Let vertex a be the origin. Please find a spanning tree for it using the breadth-first search algorithm. Note that if two or more vertices qualify, then the one with the least alphabetical order is selected.

Solution to Q11.

-END-