Name CPTR246 Spring '17 (100 total points) Exam 3

Similar documents
MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Programming II (CS300)

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Chapter 20: Binary Trees

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

Programming II (CS300)

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

CSE 214 Computer Science II Heaps and Priority Queues

CS24 Week 8 Lecture 1

Binary Trees

12 Abstract Data Types

Programming II (CS300)

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Data Structure. IBPS SO (IT- Officer) Exam 2017

CS 308 Data Structures Spring Dr. George Bebis Final Exam

Stacks, Queues and Hierarchical Collections

3137 Data Structures and Algorithms in C++

Data Structure Advanced

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

1 Binary trees. 1 Binary search trees. 1 Traversal. 1 Insertion. 1 An empty structure is an empty tree.

Data Structures Question Bank Multiple Choice

Tree Structures. A hierarchical data structure whose point of entry is the root node

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

Data Structures And Algorithms

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Binary Trees. Directed, Rooted Tree. Terminology. Trees. Binary Trees. Possible Implementation 4/18/2013

More Group HW. #ifndef Stackh #define Stackh. #include <cstdlib> using namespace std;

Final Exam Data Structure course. No. of Branches (5)

a graph is a data structure made up of nodes in graph theory the links are normally called edges

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

CSE 230 Intermediate Programming in C and C++ Binary Tree

Recursive Data Structures and Grammars

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Algorithms and Data Structures

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

CS61B Lecture #20: Trees. Last modified: Wed Oct 12 12:49: CS61B: Lecture #20 1

ECE Spring 2018 Problem Set #0 Due: 1/30/18

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues

CMSC 341 Lecture 10 Binary Search Trees

CS 216 Exam 1 Fall SOLUTION

C Data Structures Stacks. Stack. push Adds a new node to the top of the stack

Data Structures. Binary Trees. Root Level = 0. number of leaves:?? leaves Depth (Maximum level of the tree) leaves or nodes. Level=1.

CS61BL. Lecture 3: Asymptotic Analysis Trees & Tree Traversals Stacks and Queues Binary Search Trees (and other trees)

Cpt S 122 Data Structures. Data Structures Trees

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

Trees. Tree Structure Binary Tree Tree Traversals

CS61B Spring 2016 Guerrilla Section 3 Worksheet. 12 March 2016

CS302 - Data Structures using C++

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Summer Final Exam Review Session August 5, 2009

ECE250: Algorithms and Data Structures Midterm Review

CS200 Spring 2004 Midterm Exam II April 14, Value Points a. 5 3b. 16 3c. 8 3d Total 100

Trees Algorhyme by Radia Perlman

INF2220: algorithms and data structures Series 1

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD

Lecture Data Structure Stack

CS 61B Spring 2017 Guerrilla Section 4 Worksheet. 11 March 2017

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

Why Do We Need Trees?

CS61B Lecture #20: Trees. Last modified: Mon Oct 8 21:21: CS61B: Lecture #20 1

Trees. (Trees) Data Structures and Programming Spring / 28

Course Review. Cpt S 223 Fall 2009

Computer Science 302 Spring 2007 Practice Final Examination: Part I

CSC148-Section:L0301

TREES. Trees - Introduction

Tree Data Structures CSC 221

Matriculation number:

CSE 143 SAMPLE MIDTERM

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

tree nonlinear Examples

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

Algorithms and Data Structures Exercise I

Topic 14. The BinaryTree ADT

CS301 - Data Structures Glossary By

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

CS350: Data Structures Tree Traversal

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues

Chapter 9. Priority Queue

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

Stacks and Queues

Multiple choice questions. Answer on Scantron Form. 4 points each (100 points) Which is NOT a reasonable conclusion to this sentence:

Binary Trees, Binary Search Trees

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Transcription:

Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in the drawing to indicate what must change in the linked list for each change described. (6 points) (a) Add integer 41 (b) Add integer 61 16 16 25 25 37 37 45 45 58 0 58 0 (c) Add integer 11 16 25 37 45 58 0 1

2. What does the acronym LIFO stand for? (2 points) 3. Which data structure is LIFO, stack or queue? (2 points) 4. What does the acronym FIFO stand for? (2 points) 5. Which data structure is FIFO, stack or queue? (2 points) 6. Enter the values that will be in the linked list of integers, and draw the links (arrows), of a stack after the following operations are executed. (6 points) push 12 push 23 push 34 push 45 pop pop push 56 7. Enter the values that will be in the linked list of integers, and draw the links (arrows), of a queue after the following operations are executed. (6 points) enqueue 12 enqueue 23 enqueue 34 enqueue 45 dequeue dequeue enqueue 56 2

8. Answer the following questions regarding this tree: 42 36 65 19 40 56 78 12 22 38 58 71 82 31 Is this a binary search tree? (yes or no) (2 points) What is the root? (2 points) How many nodes are in the tree? (2 points) List the leaves in the tree. (2 points) Name the children of node 36: (2 points) Name the parent of node 36: (2 points) List the nodes as they would be processed in a breadth- search: (2 points) List the nodes as they would be processed in a preorder traversal: (2 points) List the nodes as they would be processed in an inorder traversal: (2 points) List the nodes as they would be processed in a postorder traversal: (2 points) 3

Name 9. Use code stack.h as a reference. Write the following two new member functions: MakeEven takes no parameters and changes every occurrence of an odd number in the stack to an even number by adding 1 to it. It is to return the number of nodes that were changed. For example, if the stack mystack contains 1 8 9 4 and we call mystack.makeeven( ), the stack would be modified to contain 2 8 10 4 and a 2 would be returned. It therefore has no parameters, and it is to return an integer. Demote takes one integer parameter. If that integer is not in the stack, return false. If it is the integer in the stack, return false. Otherwise, move this node down one position in the stack and return true. For example, if the stack mystack contains 1 2 3 4 and we call mystack.demote(2), the stack would be modified to contain 1 3 2 4 and it would return true. The method will have one parameter and return a boolean. (a) Begin by indicating the changes that need to be made to the class declaration: (6 points) class Stack { public: // see function def's for pre and post Stack() { top = 0;} ~Stack(); bool IsEmpty() {return (top == 0);} bool IsFull(); bool Peek(int & x); void Push(int x); bool Pop(int & x); void Display(); }; private: Node * top; // points to the Node in the stack Use the following two pages to code the functions. 4

(b) Write the member function definition for MakeEven: (12 points) (repeated for your convenience) MakeEven takes no parameters and changes every occurrence of an odd number in the stack to an even number by adding 1 to it. It is to return the number of nodes that were changed. For example, if the stack mystack contains 1 8 9 4 and we call mystack.makeeven( ), the stack would be modified to contain 2 8 10 4 and a 2 would be returned. It therefore has no parameters, and it is to return an integer. 5

(c) Write the member function definition for Demote: (12 points) (repeated for your convenience) Demote takes one integer parameter. If that integer is not in the stack, return false. If it is the integer in the stack, return false. Otherwise, move this node down one position in the stack and return true. For example, if the stack mystack contains 1 2 3 4 and we call mystack.demote(2), the stack would be modified to contain 1 3 2 4 and it would return true. The method will have one parameter and return a boolean. 6

10. Use code tree.h as a reference. Write the following two new member functions: (12 points each) HaveOneChild (recursive) will return the number of nodes in the tree that have exactly one child. If the tree is empty, it should return 0. Therefore, it will have no parameters and return an integer.. TheParentOf (non-recursive and assuming that the tree is a binary search tree; that is, all nodes in the left subtree have values less than the current node and all nodes in the right subtree have values greater than or equal to the current node) takes an integer as a parameter and returns the value of its parent. If the value is not in the tree, which includes the case where the tree is empty, return -1. If the value is at the root, return -2. Therefore, it will have one parameter and return an integer. (Code HaveOneChild on this page and TheParentOf on the following page.) 7

(repeated for your convenience) TheParentOf (non-recursive and assuming that the tree is a binary search tree; that is, all nodes in the left subtree have values less than the current node and all nodes in the right subtree have values greater than or equal to the current node) takes an integer as a parameter and returns the value of its parent. If the value is not in the tree, which includes the case where the tree is empty, return -1. If the value is at the root, return -2. Therefore, it will have one parameter and return an integer. 8