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.

Slides:



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

Homework - Chapter 03 Solution.
Introduction to computers Exam 2 授課教授:李錫智. Question_1 For the following program: Suppose the user enters 43 、 57 in the text boxes numberBox1 and numberBox2,
CS 171: Introduction to Computer Science II
: Arrange the Numbers ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11481: Arrange the Numbers 解題者:李重儀 解題日期: 2008 年 9 月 13 日 題意: 將數列 {1,2,3, …,N}
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
Section 1.2 Describing Distributions with Numbers 用數字描述分配.
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.
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
Introduction to Computers - 2 nd exam- 授課教授:李錫智. 1. Double the Number
: Boxes ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11003: Boxes 解題者:蔡欣燁 解題日期: 2007 年 3 月 19 日.
: Factstone Benchmark ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: : Factstone Benchmark 解題者:鐘緯駿 解題日期: 2006 年 06 月 06 日 題意: 假設 1960.
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,
:New Land ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11871: New Land 解題者:施博修 解題日期: 2011 年 6 月 8 日 題意:國王有一個懶兒子,為了勞動兒子,他想了一個 辦法,令他在某天早上開始走路,直到太陽下山前,靠.
: OPENING DOORS ? 題組: Problem Set Archive with Online Judge 題號: 10606: OPENING DOORS 解題者:侯沛彣 解題日期: 2006 年 6 月 11 日 題意: - 某間學校有 N 個學生,每個學生都有自己的衣物櫃.
: ShellSort ★★☆☆☆ 題組: Problem D 題號: 10152: ShellSort 解題者:林一帆 解題日期: 2006 年 4 月 10 日 題意:烏龜王國的烏龜總是一隻一隻疊在一起。唯一改變烏龜位置 的方法為:一隻烏龜爬出他原來的位置,然後往上爬到最上方。給 你一堆烏龜原來排列的順序,以及我們想要的烏龜的排列順序,你.
: Matrix Decompressing ★★★★☆ 題組: Contest Volumes with Online Judge 題號: 11082: Matrix Decompressing 解題者:蔡權昱、劉洙愷 解題日期: 2008 年 4 月 18 日 題意:假設有一矩陣 R*C,
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( 升冪.
: Walking on a Grid ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10913: Walking on a Grid 解題者:陳盈村 解題日期: 2008 年 5 月 2 日 題意:給定一個 N*N 矩陣,題目要求依照.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
:Problem D: Bit-wise Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10232: Problem D: Bit-wise Sequence 解題者:李濟宇 解題日期: 2006 年 4 月 16.
24-6 設定開始與結束場景中的 程式 最後我們要替這個遊戲收個尾, 幫它把開始 的等待畫面跟結束畫面處理一下。
計算機概論 - 排序 1 排序 (Sorting) 李明山 編撰 ※手動換頁.
Matlab Assignment Due Assignment 兩個 matlab 程式 : Eigenface : Eigenvector 和 eigenvalue 的應用. Fractal : Affine transform( rotation, translation,
: Fast and Easy Data Compressor ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10043: Fast and Easy Data Compressor 解題者:葉貫中 解題日期: 2007 年 3.
各種線上電子資源的特異功能 SwetsWise 的 alert, TOC alert 與 Favorites 2003/4/28 修改.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
: Problem A : MiniMice ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11411: Problem A : MiniMice 解題者:李重儀 解題日期: 2008 年 9 月 3 日 題意:簡單的說,題目中每一隻老鼠有一個編號.
第十章 再論結構. 指標與結構的關係 /* File name: ex10-1a.c */ #include int main() { struct student { char *name; int score; }; struct student st= {"Brian", 97}; struct.
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
Marble on tree ★★★☆☆ 題組: ACM Programming Contest World Finals, 1998 題號: Marble on tree 解題者:呂為萱 解題日期: 2011 年 3 月 16 日 題意: 有 n 個箱子,被擺放在 rooted.
程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0 程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0許翠婷
資料結構實習-一 參數傳遞.
第六章 陣列.
Deletion in MIN-MAX Heaps Delete min element Delete max element.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
: Lucky Number ★★★★☆ 題組: Proble Set Archive with Online Judge 題號: 10909: Lucky Number 解題者:李育賢 解題日期: 2008 年 4 月 25 日 題意:給一個奇數數列 1,3,5,7,9,11,13,15…
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 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
資料結構實習-十 Binary Tree Traversal.
Chapter 10 m-way 搜尋樹與B-Tree
Transforming Infix to Postfix
: Mini Cube ★★★★★ 題組: Problem Set Archive with Online Judge 題號: 11007: Mini Cube 解題者:郭峻維 解題日期: 2007 年 3 月 27 日 題意:找出 2x2x2 的 Rubik‘s cube 的最佳解。
中序轉後序 藉由由左向右掃瞄中序運算式產生後序運算式,遇到 運算元就直接輸出,遇到運算符號則先存入堆疊,將 優先權較高者輸出。 範例: a + b * c TokenStack [0] [1] [2] topoutput aa ++0a b+0ab *+ *1ab c+ *1abc eosabc*+
:Stupid Sequence ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11319: Stupid Sequence 解題者:李育賢 解題日期: 2008 年 11 月 23 日 題意: 一個公式 f(x)=a 0 +a 1 x+a.
: Construct the wall maze ★★★★★ 題組: Problem Set Archive with Online Judge 題號: 11050: Construct the wall maze 解題者:宋柏儀 解題日期: 2007 年 6 月 12 日.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Problem E.Stone Game ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10165: Problem E.Stone Game 解題者:李濟宇 解題日期: 2006 年 3 月 26 日 題意: Jack 與 Jim.
Review Binary Tree Binary Tree Representation Array Representation Link List Representation Operations on Binary Trees Traversing Binary Trees Pre-Order.
單元7: Heap 定義 for priority queues Leftist trees Binomial heap
Tree Traversal Inorder traversal: A/B*C*D+E (LVR)
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.
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);
Data Structures -1 st exam- 授課教師 : 李錫智 教授. 1.[10] Suppose we have the ADT Bag which has the following operations: bool isEmpty(): tests whether Bag is.
Data Structures -3 rd exam- 授課教師 : 李錫智 教授. 1.[10] Please answer the following questions about queue: [ 2] What is the response of the statement: “(new.
Chapter 12 – Data Structures
Binary Search Tree (BST)
Data Structures Using C++ 2E
Presentation transcript:

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 about queue: [2] How do you search for an item in the sorted list? [2] How do you insert an item into the sorted list? [2] How do you delete an item from the sorted list? [2] What is the efficiency of the insertion? Please express it in big O. [2] What is the efficiency of the search? Please express it in big O.

Solution of Q.1 1. 嘗試搜尋並且比較陣列裡的值,一樣時則傳回 2. 當新增一個 item 時,在要新增的位置,後面的 項目皆往後移一格 3. 當刪掉一個 item 時,在此 item 後面的項目皆往 前移一格。 4. O(n) 5. O(n) [ 若第一小題搜尋使用 binary search 答案為 O(log n)]

Question 2 Suppose we use a link to implement a sorted list. Please answer the following questions about queue: [2] How do you search for an item in the sorted list? [2] How do you insert an item into the sorted list? [2] How do you delete an item from the sorted list? [2] What is the efficiency of the insertion? Please express it in big O. [2] What is the efficiency of the search? Please express it in big O.

Solution of Q.2-1 沿著連結搜尋每一個值,找到值時則傳回。 若找到最後沒搜尋到,則回傳空值。

Solution of Q.2-2

Solution of Q.2-3

Solution of Q.2-4 & Q O(n) 5. O(n)

Question 3 Please answer the following questions about queue implementations: [5] Suppose we use a circular array to implement a queue. Let front and back are two variables storing the indices of the first and last items entering into the queue, respectively. What can a problem arise with this implementation? Suppose we use a circular array to implement a queue. Let front be a variable storing the index prior to that of the first object entering into the queue, and back be another variable storing the index of the last object entering into the queue. [3] What is the advantage of this implementation? [2] How are these variables set initially?

Solution of Q.3-1 當 queue 為 full 或 empty 時, Front 的位置,皆為 back 之下 一個

Solution of Q 能區別 full 與 empty 狀態 2. 初始值, Front = back 即可

Question 4-1 Please answer the following questions about trees: [3] Suppose we have a binary tree with height h. What is the minimal number of nodes in this tree? [2] Suppose we have a binary tree with height h. What is the maximal number of nodes in this tree? [3] Suppose we have a complete binary tree with height h. What is the minimal number of nodes in this tree? [3] Suppose we have a complete binary tree with height h. What are the maximal number of nodes in this tree?

Solution of Q.4-1 A.h (Fig. A) B.2 h -1(Fig. B) C.2 h-1 (Fig. C) D.2 h -1(Fig. C) Fig. A Fig. B Fig. C (Complete Binary Tree)

Question 4-2 Please answer the following questions about trees: [3] Suppose we have a binary tree with n nodes. What is the minimal height of this tree? [2] Suppose we have a binary tree with n nodes. What is the maximal height of this tree? [2] Suppose we have a complete binary tree with n nodes. What is the minimal height of this tree? [2] Suppose we have a complete binary tree with n nodes. What is the maximal height of this tree?

Solution of Q.4-2

Question 5 Suppose we have a binary tree as shown in Figure 1. [3] Please traverse the tree in inorder. [3] Please traverse the tree in preorder. [4] Please traverse the tree in postorder. Figure 1

Solution of Q , 70, 40, 30, 20, 80, 50, 90, , 40, 60, 70, 50, 80, 20, 90, , 60, 40, 20, 80, 10, 90, 50, 30

Question 6 Please answer the following questions about trees: [4] Store the tree of Figure 1 in an array of size 12. Please show the resulting array. Note that the nodes are stored level by level and from left to right. [3] Continuing: Suppose we delete 90 from the tree. Please show the resulting array. Please add the newly released space at the end of the free chain. Please link the parent of 90 directly to the child of 90. [3] Continuing: Suppose we add 200 as the left child of 70. Please show the resulting array. Store it in the first available space.

Solution of Q.6-1 indexvalueLR ? 10 ?11 ? root : 0 free chain start: 9

Solution of Q.6-2 indexvalueLR ? 10 ?11 ?5 root : 0 free chain start: 9

Solution of Q.6-3 indexvalueLR ?11 ?5 root : 0 free chain start: 10

Question 7 Suppose we have 15 integers: 35, 25, 55, 40, 70, 10, 65, 5, 20, 60, 30, 15, 50, 45, 75. [5] Please create a binary search tree for them by considering one by one. [3] Please delete the root from the resulting binary tree and show the resulting binary search tree? Note that a node is replaced by one that is the largest of those smaller than it. [2] Continuing: Please delete 55 from the tree and show the resulting binary search tree. Note that a node is replaced by one that is the largest of those smaller than it.

Solution of Q

Solution of Q

Solution of Q

Question 8 Please answer the following questions with general trees: Figure 2Figure 3 [5] Figure 2 is a general tree. Please draw a corresponding binary tree for it. [5] Figure 3 is a binary tree intended for storing a general tree. Please draw the general tree it represents.

Solution of Q a b f c d h g k j e i a. b.

Question 9 [10] Suppose we have 15 integers: 35, 25, 55, 40, 70, 10, 65, 5, 20, 60, 30, 15, 50, 45, 75. Please sort them in ascending order by tree sort.

Solution of Q Traverse binary search tree in inorder 5,10,15,20,25,30,35,40,45,50,55,60,65,70,75

-End-