ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139



Similar documents
Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Data Structures. Level 6 C Module Descriptor

DATA STRUCTURES USING C

Binary Search Trees (BST)

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Ordered Lists and Binary Trees

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

Data Structures, Practice Homework 3, with Solutions (not to be handed in)

Data Structure [Question Bank]

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Data Structures and Algorithms

PES Institute of Technology-BSC QUESTION BANK

Binary Search Trees CMPSC 122

10CS35: Data Structures Using C

Analysis of a Search Algorithm

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Parallelization: Binary Tree Traversal

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

From Last Time: Remove (Delete) Operation

Data Structure with C

CSE 326: Data Structures B-Trees and B+ Trees

TREE BASIC TERMINOLOGIES

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

Cpt S 223. School of EECS, WSU

Exam study sheet for CS2711. List of topics

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : ,

Data Structures UNIT III. Model Question Answer

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

Converting a Number from Decimal to Binary

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Cpt S 223. School of EECS, WSU

Algorithms and Data Structures

Data Structures Using C++ 2E. Chapter 5 Linked Lists

CS211 Spring 2005 Final Exam May 17, Solutions. Instructions

Algorithms and Data Structures Exercise for the Final Exam (17 June 2014) Stack, Queue, Lists, Trees, Heap

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Data Structures and Algorithms Written Examination

Full and Complete Binary Trees

Algorithms and Data Structures Written Exam Proposed SOLUTION

S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India Dr. R. M.

Chapter 14 The Binary Search Tree

Sequential Data Structures

Structural Design Patterns Used in Data Structures Implementation

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Algorithms and data structures

LINKED DATA STRUCTURES

Lecture 12 Doubly Linked Lists (with Recursion)

CompSci-61B, Data Structures Final Exam

Sample Questions Csci 1112 A. Bellaachia

Class Notes CS Creating and Using a Huffman Code. Ref: Weiss, page 433

Symbol Tables. Introduction

Lecture Notes on Binary Search Trees

Exercises Software Development I. 11 Recursion, Binary (Search) Trees. Towers of Hanoi // Tree Traversal. January 16, 2013

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

ER E P M A S S I CONSTRUCTING A BINARY TREE EFFICIENTLYFROM ITS TRAVERSALS DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A

Heaps & Priority Queues in the C++ STL 2-3 Trees

A COMPARATIVE STUDY OF LINKED LIST SORTING ALGORITHMS

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Binary Heap Algorithms

STACKS,QUEUES, AND LINKED LISTS

Object Oriented Software Design

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

Data Structures Using C++

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

How To Create A Tree From A Tree In Runtime (For A Tree)

EE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE)

Linked Lists Linked Lists, Queues, and Stacks

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Any two nodes which are connected by an edge in a graph are called adjacent node.

To My Parents -Laxmi and Modaiah. To My Family Members. To My Friends. To IIT Bombay. To All Hard Workers

Data Structures and Algorithms Lists

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

International Journal of Software and Web Sciences (IJSWS)

Chapter 8: Bags and Sets

Data Structures and Data Manipulation

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

Introduction to Object-Oriented Programming

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

Section IV.1: Recursive Algorithms and Recursion Trees

Analysis of Algorithms I: Binary Search Trees

Introduction to Data Structures and Algorithms

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

Binary Trees and Huffman Encoding Binary Search Trees

The ADT Binary Search Tree

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

ADTs,, Arrays, Linked Lists

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. Course Curriculum. DATA STRUCTURES (Code: )

How To Teach C++ Data Structure Programming

Data Structures and Algorithms(5)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Transcription:

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139 Instructions: No aides. Turn off all electronic media and store them under your desk. If there is insufficient room, use the back of the previous page. You may ask only one question during the examination: May I go to the washroom? If you think a question is ambiguous, write down your assumptions and continue. Do not leave during the first 30 minutes of the examination. Do not leave during the last 15 minutes of the examination. Do not stand up until all exams have been picked up. Bonus of 1 for obeying all these instructions. You must stop writing when you are told that the examination is finished. No exceptions, not even for your name. (-5 mark penalty.) Attention: The questions are in the order of the course material, not in order of difficulty. I have read and understood all of these instructions and will accept a grade of 0 if I fail to follow them: Name: UW Student ID Number: Signature: Page 1 of 8

Relationships 1. [4] Given the numbers -1, 0, 1, 2, 3, 4, 5, 6, group these into equivalence classes based on a ~ b if (a % 4) == (b % 4) where % is the C++ modulo/remainder operator. Runtime Analysis 2. [6] List six functions in Table 2 in the order f 0 = 1, f 1,..., f 6, f 7 = n 3 so that f k = o(f k + 1 ). Each inversion, error, or missing entry results in -1 with a minimum score of 0. Table 2. 1 n 3 3. [2] Show that n 1/2 ln(n) = o(n) by using limits. 4. [8] What is the run time of each of the following loops? The standard function min retruns the minimum of the two arguments. for ( int i = 0; i < n; ++i ) { for ( int j = 0; j < n/2; ++i ) { ++sum; for ( int i = 0; i < n; ++i ) { for ( int j = 0; j < std::min( 10, i ); ++j ) { ++sum; for ( int i = 0; i*i < n; ++i ) { ++sum; Page 2 of 8

5. [4] A perfect quaternary tree of height h is either a single node if h = 0 or a root node with four sub-trees each of which is a perfect quaternary tree of height h 1. Use induction to show that the number of nodes in a perfect quaternary tree is 4 h + 1 /3 1/3. Note that the formula, while involving fractions, always produces an integer: 1, 5, 21, 85, 341, 1365,.... 6. [3] Show by induction that the following sum is n(n + 1). n k= 1 2 k Page 3 of 8

Arrays and Linked Lists 7. [8] A doubly linked list contains nodes which, in addition to a pointer storing the address of the next node, have a pointer which stores the address of the previous node in the list. The first node has a previous pointer which is 0. Implement the functions push front and pop front which preserve the state of the doubly linked list. Functionality is expected to be similar to that of the single list class in Project 1. template <typename Object> class Double_node { private: Object elem; // element Double_node *nn; // next node Double_node *pn; // previous node public: Double_node( const Object & e, Double_node *n = 0, Double_node *p = 0 ):elem(e), nn(n), pn(p) { // empty Object retrieve() const; Double_node *next() const; Double_node *prev() const; ; template <typename Object> class Double_list { private: Double_node<Object> *lh; Double_node<Object> *lt; int count; public: Double_list():lh(0), lt(0), count(0) { /* empty */ // list_head // list_tail ; // functions similar in name and functionality to Project 1 template <typename Object> void Double_list<Object>::push_front( const Object & obj ) { template <typename Object> Object Double_list<Object>::pop_front() { Page 4 of 8

Stacks, Queues, and Deques 8. [4] Why would a singly linked list (for example, your implementation in Project 1) be an inappropriate data structure to implement a deque? Provide quantitative analysis in your arguments. Tree Definitions 9. [1] A node A is a descendant of B if there is a path from to. 10. [5] Give the best description of the relationship between the node D and the nodes shown Figure 10 as listed in Table 10. Place your answer in the table. Table 10. Nodes in Figure 10 Node Relationship: D is of Node B E I A C Tree Traversals Figure 10. A general tree. 11. [2] Perform a pre-order depth-first traversal on the binary tree shown in Figure 11 and put your answer in Table 11. Table 11. Pre-order depth-first traversal. Figure 11. A general tree. Page 5 of 8

12. [2] Figure 12 shows a tree missing four entries. Figure 12. A tree. Table 12 shows a breadth-first traversal of the tree. Fill in the missing nodes. Table 12. Breadth-first traversal. A B I E K V S V F 13. [2] Figure 13 shows a tree missing four nodes. Figure 13. A tree. Table 13 shows a post-order depth-first traversal of the tree. Fill in the missing nodes. Table 13. Post-order depth-first traversal. E T R B P F R I A Binary Search Trees 14. [4] Without any balancing, insert the elements 1, 0, 7, 3, 6, 8, 5, 9, 4, 2 into an initially-empty binary search tree. The elements must be inserted in the given order. Page 6 of 8

AVL Trees 15. [7] Perform the following insertions into the given AVL trees and perform the appropriate rotations to rebalance the tree. 15a. Add 11 to the AVL tree shown in Figure 15. Figure 15a. An AVL tree. 15b. Add 20 to the AVL tree shown in Figure 15b. Figure 15b. An AVL tree. 15c. Add 25 to the AVL tree shown in Figure 15c. Figure 15c. An AVL tree. Page 7 of 8

16. [4] Remove the node 19 from the AVL tree shown in Figure 16 using the technique shown in class and rebalance the resulting tree. Figure 16. An AVL tree. Unix 17. [3] Write the Unix commands necessary to submit Project 1 assuming you have copied the files relevant header files to Unix. You should end up with an appropriately zipped file. Page 8 of 8