Data Structures -3 rd exam- 授課教師 : 李錫智 教授. 1.[10] Please answer the following questions about queue: [ 2] What is the response of the statement: “(new.

Slides:



Advertisements
Similar presentations
1 AVL Trees (10.2) CSE 2011 Winter April 2015.
Advertisements

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
CS 171: Introduction to Computer Science II
DictionaryADT and Trees. Overview What is the DictionaryADT? What are trees? Implementing DictionaryADT with binary trees Balanced trees DictionaryADT.
授課教授:李錫智 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.
Priority Queues. Container of elements where each element has an associated key A key is an attribute that can identify rank or weight of an element Examples.
A Binary Tree root leaf. A Binary Tree root leaf descendent of root parent of leaf.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
BST Data Structure A BST node contains: A BST contains
Review of Chapter 5 張啟中. Threaded Binary Tree 利用 Binary Tree 節點中的 0-links ,指向中序的先行 者或後繼者,以方便中序追蹤。 Threading Rules  A 0 RightChild field at node p is.
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L12 (Chapter 20) Lists, Stacks,
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Binary Tree Properties & Representation. Minimum Number Of Nodes Minimum number of nodes in a binary tree whose height is h. At least one node at each.
Transforming Infix to Postfix
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
CST 230 Razdan et alhttp://dcst2.east.asu.edu/~razdan/cst230/ Razdan with contribution from others 1 Tree Traversals Pre-order traversal –process root.
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
1 Chapter 8 Priority Queues. 2 Implementations Heaps Priority queues and heaps Vector based implementation of heaps Skew heaps Outline.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 20: Binary Trees.
Chapter 18 - basic definitions - binary trees - tree traversals Intro. to Trees 1CSCI 3333 Data Structures.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
TREES A tree's a tree. How many more do you need to look at? --Ronald Reagan.
Foundation of Computing Systems Lecture 6 Trees: Part III.
Review Binary Tree Binary Tree Representation Array Representation Link List Representation Operations on Binary Trees Traversing Binary Trees Pre-Order.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
12-CRS-0106 REVISED 8 FEB 2013 CSG2A3 ALGORITMA dan STRUKTUR DATA.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
For Monday Read Weiss, chapter 7, sections 1-3. Homework –Weiss, chapter 4, exercise 6. Make sure you include parentheses where appropriate.
Tree Traversal Inorder traversal: A/B*C*D+E (LVR)
Binary Search Tree Traversal Methods. How are they different from Binary Trees?  In computer science, a binary tree is a tree data structure in which.
1 Binary Trees (7.3) CSE 2011 Winter November 2015.
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
CPSC 252 Binary Heaps Page 1 Binary Heaps A complete binary tree is a binary tree that satisfies the following properties: - every level, except possibly.
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 -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,
Discrete Mathematics Chapter 5 Trees.
CS223 Advanced Data Structures and Algorithms 1 Priority Queue and Binary Heap Neil Tang 02/09/2010.
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 Using C++ 2E Chapter 11 Binary Trees.
Binary Tree Implementation. Binary Search Trees (BST) Nodes in Left subtree has smaller values Nodes in right subtree has bigger values.
Foundation of Computing Systems Lecture 4 Trees: Part I.
More Binary Search Trees, Project 2 Bryce Boe 2013/08/06 CS24, Summer 2013 C.
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.
ISOM MIS 215 Module 5 – Binary Trees. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Data Structure and Algorithms
Binary search tree. Removing a node
Binary Search Tree (BST)
Tree.
Data Structures Using C++ 2E
Chapter 20: Binary Trees.
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Chapter 21: Binary Trees.
Priority Queue and Binary Heap Neil Tang 02/12/2008
Chapter 16 Tree Implementations
Chapter 20: Binary Trees.
Data Structures Using C++ 2E
A Binary Tree is a tree in which each node has at most 2 children
Presentation transcript:

Data Structures -3 rd exam- 授課教師 : 李錫智 教授

1.[10] Please answer the following questions about queue: [ 2] What is the response of the statement: “(new queue()).isEmpty()”? [2] What is the response of the statement: “((new queue()).enqueue(item)).peekFront()”? [2] What is the response of the following statement: “(((new queue()).enqueue(item)).peekFront()).dequeue()”? [2] What is the response of the following statement: “((((new queue()).enqueue(item)).peekFront()).dequeue()).enqueue(item)” ? [2] What is the response of the following statement: “((((new queue()).enqueue(item)).peekFront()).dequeue()).dequeue()”?

Ans: (a)true (b)item (c)true (d)true (e)false

2.[10] Please answer the following questions about queue implementations: 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 objects entering into the queue, respectively.[3] What can a problem arise with this implementation? [2] How do you solve it? 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?

Ans: (a) problem: 當 circular queue 為空的或滿的, front 都等於 back+1 ,無法由判斷 circular queue 目前的情況 solve: 令一額外變數儲存目前 circular queue 裡面的個數 (b) Advantage: 不用再用額外變數儲存目前 circular queue 裡 面的個數,直接可藉由 front 和 back 判斷 circular queue 的 狀況 Initial set: front=back

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

Ans: (a) h,2 h -1 (b) 2 h-1, 2 h -1 (c) Log 2 (n+1),n

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

Ans: Inorder:60,70,40,30,20,80,50,90,10 Preorder:30,40,60,70,50,80,20,90,10 Postorder:70,60,40,20,80,10,90,50,30

5.[10] 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.

Ans:(a)

(b)

(c)

6.[10] Suppose we have 15 integers: 35, 25, 55, 40, 70, 10, 65, 5, 20, 60, 30, 15, 50, 45, 75. [3] Please create a binary search tree for them by considering one by one. [4] How do you save this binary search tree in an array and reconstruct the same tree later? [3] 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.

Ans: (a)

(b) 先用 preorder: 之後再建一次 binary search tree

(c)

7.[10] Please answer the following questions with general trees: Fig. 2

Fig. 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.

Ans:(a)

a bfj ceg h i d k (b)

8.[10] Suppose we have 15 integers: 35, 25, 55, 40, 70, 10, 65, 5, 20, 60, 30, 15, 50, 45, 75. Please create a heap, starting with a complete binary tree with 15 nodes. Show the tree each time one level is completed during the adjustment process.

Ans: Level1

Level2

Level3

9.[10] Suppose we have a heap represented in an array shown below: 20, 17, 16, 13, 12, 15, 7, 2, 5 [3] Please add 19 into it. Show the resulting heap. [3] Continuing: Please add 25 into it. Show the resulting heap. [4] Continuing: Please remove the root. Show the resulting heap.

Ans:

10.[10] Suppose we have 7 integers: 35, 25, 55, 40, 70, 10, 65. Please sort them in ascending order using heap sort. Please using an array of size 7 to implement it. Please draw the array each time the root of the heap is removed.

Ans: