CSE12 QUIZ5

Ace your homework & exams now with Quizwiz!

T or F: A complete tree is one where every level (except possibly the last) is completely filled, and all nodes are as far right as possible.

-F

T or F: A pre-order traversal visits in the same order as the items were inserted.

-F

T or F: A priority queue is often implemented via a binary search tree.

-F

T or F: For the Tree of hw9, the code still has to delete pointers to TNodes to prevent memory leaks.

-F

T or F: For the following declaration, the const parameter object is not necessarily a constant in the caller: void func (const UCSDStudent &);

-F

T or F: For the following declaration, the parameter object is constant only during the method execution and not necessarily const when that method passes it to other methods: void func (const UCSDStudent &);

-F

T or F: For the following member method declaration, any calling object cannot change during the method execution: void func (const UCSDStudent &);

-F

T or F: If you create UCSDStudent objects only by passing parameters to the constructor, a default constructor is needed.

-F

T or F: If you create UCSDStudent objects only without passing parameters to the constructor, a UCSDStudent default constructor is needed.

-F

T or F: In hw8 when exceeding the threshold on balance, the memory for the current TNode will be deallocated when the last line of SHAB is executed.

-F

T or F: Removing from a heap data structure can be done anywhere in the tree.

-F

T or F: TNode's RARM will not always find a predecessor Tnode.

-F

T or F: The predecessor TNode always has a null left pointer.

-F

T or F: The semi-colon following the close curly brace in C++ at the end of a class definition is optional.

-F

T or F: Using guaranteed initialization, data fields can be listed in any order.

-F

T or F: When using an input parameter, the caller is expecting the parameter to change.

-F

T or F: When using templates with a polymorphic generic container, if the name listed between < and > is a name that isn't an existing type, the code is likely for the user of a generic container.

-F

T or F: When using templates with a polymorphic generic container, if the name listed between < and > is the name of an existing type, the code is likely for the implementation of a generic container.

-F

T or F: With a successful "lazy" remove, the height of all nodes along the search path decrease by one to correctly describe the resultant tree.

-F, only occupancy was changed

ABCD, F. Nowhere

-F. Nowhere

As discussed in class, how did we compute the balance of a node in a tree?

-False

T or F: A loop based solution often uses more memory than a recursive solution.

-False

T or F: A loop based solution often uses the same amount of memory than a recursive solution.

-False

T or F: A recursive solution usually involves more code that a loop based solution.

-False

T or F: An ideal for a C++ class is to have as many friends as possible.

-False

T or F: Heap memory allocation is more efficient than RTS memory allocation.

-False

T or F: In a binary search tree, smaller items go right.

-False

T or F: References in C++ can be reset to refer to another variable within the same function.

-False

T or F: Spindly trees are preferable to bushy trees

-False

T or F: When class A announces that class B is a friend, class A can directly access private fields of class B.

-False

T or F: When class A is a friend of class B, class B is also a friend of class A.

-False

T or F: With a successful "lazy" remove, the balance of all nodes along the search path decrease by one to correctly describe the resultant tree.

-False

T or F: With a successful "lazy" remove, the removed node is displayed when displaying the tree to the user.

-False

T or F: With a successful "lazy" remove, the removed node is present in the tree, but the name of the item stored there is cleared.

-False

T or F: cerr is the keyword for the command to send output to stderr.

-False

T or F: cout is the keyword for the command to send output to stdout.

-False

T or F: infinite recursion is one cause of an infinite loop.

-False

from each recursive call.

-False

method.

-False

T or F: cin is the keyword for the command to read input from stdin.

-False (not a keyword, it is a stream)

What is the term for the last node that was inserted into a heap data structure?

-Final leaf

Why was a Tree or parentTNode used as a parameter to the TNode constructors of hw8?

-For occupancy and tree_count

What happens when a valid function pointer is stored into the PC (program counter).

-Function is called

What happens when a valid return address is stored into the PC (program counter).

-Function is returned

that must be met so that it could be inserted into a SymTab in hw6 and hw7?

-Had to derive/extend Base

met so that it could be inserted into a SymTab in hw6 and hw7?

-Had to provide all member method definitions

What is the term for the property of a heap data structure in which data of parent nodes are greater than data of child nodes?

-Heap order

A const reference parameter is most likely to be an ______ parameter. I)nput O)utput

-I)nput

What is the best tree traversal to make an identical copy of a Tree?

-In Order

What are the three types of tree traversals discussed in class?

-In/Pre/Post Order

When using an array to implement a binary tree, what is the formula to determine the index of the left child?

-Index of left child: (index * 2) + 2

When using an array to implement a binary tree, what is the formula to determine the index of the parent node?

-Index of parent: floor integer result of: (index -1) / 2

When using an array to implement a binary tree, what is the formula to determine the index of the right child?

-Index of right child: (index * 2) + 2

When a program overflows the Run-Time Stack, what is the typical cause?

-Infinite Recursion (stack overflow)

What can't you do using an abstract class?

-Instantiate

Using templates, what is the term for the name that is listed between < and >: Ex: SymTab<UCSDStudent> ST;

-Instantiation only

What capability did UCSDStudent attain by being a derived class from Base?

-It allowed them to be inserted into the containers

What is the name of the term for the way to sequentially access or traverse each object in a container or collection?

-Iterator

Is "final" a keyword in C++ or in Java or both?

-Java

Is "abstract" a keyword in C++, Java or both?

-Java, "virutal" in C++

What is the term for a node in a tree that has no children?

-Leaf

What are the names of the two node pointers that point downward serving as the infrastructure of a binary tree?

-Left, Right

If inserting the alphabet from a to z into a binary search tree of hw7, the resultant tree would resemble what other data structure?

-Link list because it is not self balancing

more likely to be loop based or recursive?

-Loop

A reference in C++ is ______ ______ for a variable that exists elsewhere.

-Name

member, C. Neither: if (stu1 == stu2) {

-Neither

does the following code fragment call UCSDStudent's operator == method? if (stu1 == stu2) {

-No, you have to dereference. This would compare the addresses.

In hw8 besides being allocated on the RTS, what is a unique attribute of the TNode elementTNode parameter to TNode's Remove?

-Not in the tree

What is the big-O value for the best efficiency possible?

-O(1)

A non-const reference parameter is most likely to be an ______ parameter. I)nput O)utput

-O)utput

In the majority of hw8 Tree code, pointerInParent was an _______ parameter. I)nput O)utput

-O)utput

In any non-empty binary tree, how many nodes exist without a parent?

-One

What is the return type of all of the overloaded << methods of class ostream?

-Ostream reference

Write the return statement most likely existing in every overloaded << method of class ostream:

-Ostream reference

The _______ TNode was found by going left once and all the way right. P)redecessor S)uccessor

-P)redecessor

What is the name of the one optional pointer that points upward in a tree?

-Parent

What is the best tree traversal to deallocate a Tree?

-Post Order

What is the best tree traversal to display contents of a Tree to a user?

-Pre Order

For the ASCII file input of hw9, what situation always uses cout?

-Printing out the Tree and result

What are the constraints on an object to be inserted into a Tree of hw8?

-Provide all the methods that will be called for the insert onto the generic container

What is the term for the following declaration if it exists in a class definition in C++: virtual int func () = 0;

-Pure virtual function

What is the C++ term for the equivalent to an abstract method in Java?

-Pure virtual method

A TNode is serialized from disk to memory by TNode's _______ method. R)ead W)rite

-R)ead

What is the section of memory used to allocate all TNodes of hw9?

-RTS

Translate the following hw8 code to hw9 code: left->Insert (a, left);

-Read constructor to instantiate, then call the Read parameter to to read the parameters. Therefore, left.Insert(a, left); is equivalent to Tnode<Whatever>leftTNode(left,fio); leftTNode.Insert(a,left);

For the ASCII file input of hw9, besides checking for EOF, when else do we care if the input is coming from a file or from the keyboard?

-Reading from the file

What is the term for a method that calls itself?

-Recursive

likely to be loop based or recursive?

-Recursive

Use of the & symbol in a C++ declaration is declaring what kind of entity?

-Reference

completes?

-Return address

What is the name of the first node in a tree?

-Root

What is the term for the node that is the entry point into a tree?

-Root

Local variables are created in what section of memory?

-Run-time stack (RTS)

The _______ TNode was found by going right once and all the way left. P)redecessor S)uccessor

-S)uccessor

What is the term for the nodes visited from root to a leaf in search of an item in a tree?

-Search Path

What is the term for reading or writing an entire object byte by byte continuously in one operation?

-Serialization

What is the term for nodes that share the same parent in a tree?

-Siblings

What is the cause of the run time error that occurs with infinite recursion?

-Stack Overflow

T or F: A complete tree is one where every level (except possibly the last) is completely filled, and all nodes are as far left as possible.

-T

T or F: A priority queue is often implemented via a heap data structure

-T

T or F: Before calling RARM, the data from the target TNode is saved to send back to the caller of Tree's Remove.

-T

T or F: For the Tree of hw9, the code no longer has to delete pointers to TNodes to prevent memory leaks.

-T

T or F: For the following declaration, the const parameter object is also a constant in the caller: void func (const UCSDStudent &);

-T

T or F: For the following declaration, the parameter object is constant both during the method execution and when that method passes it to other methods: void func (const UCSDStudent &);

-T

T or F: For the following member method declaration, any calling object cannot change during the method execution: void func (UCSDStudent &) const;

-T

T or F: For the following member method declaration, any calling object cannot change during the method execution: void func (const UCSDStudent &) const;

-T

T or F: If you create UCSDStudent objects with and without passing parameters to the constructor, a UCSDStudent default constructor is needed.

-T

T or F: In hw8 when exceeding the threshold on balance, the memory for the current TNode will be deallocated before SHAB returns.

-T

T or F: PointerInParent is another name for the pointer that was followed to get the next TNode along a search path.

-T

T or F: Removing from a heap data structure is always done at the root node.

-T

T or F: TNode's RARM will always find a predecessor Tnode.

-T

T or F: The heap order is a property of a heap data structure in which data of parent nodes are greater than data of child nodes.

-T

T or F: The initial call to TNode's RARM is from TNode's Remove when the target TNode has 2 children.

-T

T or F: The predecessor TNode always has a null right pointer.

-T

T or F: The semi-colon following the close curly brace in C++ at the end of a class definition is mandatory.

-T

T or F: The sizeof a union object in C is the sizeof its largest data field.

-T

T or F: Using guaranteed initialization, data fields must be listed in the same order as they are declared in the class definition.

-T

T or F: When the parameter is a non-const reference, the method being called is expected to update the reference parameter.

-T

T or F: When using an output parameter, the caller is expecting the parameter to change.

-T

T or F: When using templates with a polymorphic generic container, if the name listed between < and > is a name that isn't an existing type, the code is likely for the implementation of a generic container.

-T

With a private derivation, what are the access rights on fields that originated from the private section of the parent?

-inaccessible

With a protected derivation, what are the access rights on fields that originated from the private section of the parent?

-inaccessible

With a public derivation, what are the access rights on fields that originated from the private section of the parent?

-inaccessible

Is a parent pointer most likely found in a recursive or loop based implementation of a binary tree?

-loop based

In hw8 besides being a TNode not in the Tree, what is a unique attribute of the TNode elementTNode parameter to TNode's Remove?

-on the RTS

member method: if (stu1 == stu2) {

-operator == (stu1, stu2); This is non-member method.

algorithms.

-outside class definition

of code called infrequently.

-outside class definition

With a private derivation, what are the access rights on fields that originated from the protected section of the parent?

-private

With a private derivation, what are the access rights on fields that originated from the public section of the parent?

-private

For the ASCII file input of hw9, what is the best word that describes the program output that is ignored?

-prompts

With a protected derivation, what are the access rights on fields that originated from the protected section of the parent?

-protected

With a protected derivation, what are the access rights on fields that originated from the public section of the parent?

-protected

With a public derivation, what are the access rights on fields that originated from the protected section of the parent?

-protected

With a public derivation, what are the access rights on fields that originated from the public section of the parent?

-public

code called frequently.

-return *this;

When exceeding the threshold on balance, after the call to TNode's Remove from SHAB where does pointerInParent point?

-right child (replacement)

Before doing a read or write disk operation, what other disk operation is always needed?

-seek

Assuming stu is a UCSDStudent, write the most equivalent code to: operator<< (stu, cout);

-stu << cout

Assuming stu is a UCSDStudent, write the most equivalent code to: stu.operator<< (cout);

-stu << cout

method: if (stu1 == stu2) {

-stu1.operator==(stud2); This is a member method.

Assuming executing code at the predecessor TNode, write the code to overwrite the data at the targetTNode with the data of the predecessor Tnode.

-targetTNode.data = data

Persistence means that program data exists longer than _______.

-the program execution

When entering a method with a pointerInParent parameter, what is the value of pointerInParent?

-this

When exceeding the threshold on balance, at the start of SHAB where does pointerInParent point?

-this

When inserting an item into the hw9 Tree, what field of the child TNode is assigned to the left or right field of the parent?

-this_position

When updating a hw9 TNode, what field was used to locate where it belonged on disk?

-this_position

Are methods in Java by default virtual or final?

-virtual

For the ASCII file input of hw9, what situation always uses cin?

-while loop in main

T or F: The successor TNode always has a null right pointer.

T or F: The successor TNode always has a null left pointer.

If your code overwrites a RTS array overwriting return addresses, what can't your program do?

-Can't return, or cannot produce a stack trace

Why does "const" exist?

-Catch errors in compile time versus run time.

constraint methods originate?

-Class Base

Besides maintaining "heap order", what is the other property of a binary tree that makes it a heap data structure?

-Complete

What is the term for a tree where every level (except possibly the last) is completely filled, and all nodes are as far left as possible?

-Complete

A constructor that has a reference to the same type of object being constructed is known as what kind of constructor?

-Copy constructor

Translate the following hw8 code to hw9 code: left->Remove (a, left);

-

Guaranteed Initialization ________ be used to initialize const data fields in a class. A) must B) can optionally C) cannot

- A) must

A binary tree is so named due to what data fields?

- Left, Right

The predecessor TNode was the alphabetically _____ found in the _____ subtree. A) largest, right B) largest, left C) smallest, right D) smallest, left

-D) smallest, left

In what section of memory can you find the "cerr" object?

-Data

In what section of memory can you find the "cin" object?

-Data

In what section of memory can you find the "cout" object?

-Data

What is the attribute of the TNode data that was convenient to read and write all fields as one unit of memory.

-Data was flat (no pointers)

resolution operator in C++?

-Define a member method outside of the definition

What is the term for a node in a search path that follows from an ancestor?

-Descendent

Assuming stu is a UCSDStudent, write the most equivalent code to: operator<< (cout, stu);

-cout << stu

Write the most equivalent fragment: cout << "Hello World\n.";

-cout operator<<("Hello World\n");

Are functions in C++ by default virtual or final?

-final

What is the keyword in C++ that extends membership access to non-members?

-friend

private methods?

-friend

For the Tree of hw9, how many calls need to exist in your code to TNode's deleteAllTNodes?

-0

As discussed in class, how did we compute the height of a node in a tree?

-1 + height of the tallest subtree

In an array-based binary tree using where the root node is at index 0, what is the index of the right child node for a parent node at index 4?

-10

What is the number of nodes to check for an unsuccessful search into an optimally balanced binary search tree of 7 items?

-3

What is the number of nodes to check for an unsuccessful search into an optimally balanced binary search tree of (2^31)-1 items?

-31

In an array-based binary tree using where the root node is at index 0, what is the index of the parent node for the node at index 10?

-4

What is the number of nodes to check for an unsuccessful search into an optimally balanced binary search tree of 15 items?

-4 from the root down to the bottom (height + 1) or 2n -1

What is the number of nodes to check for an unsuccessful search into an optimally balanced binary search tree of 31 items?

-5

In an array-based binary tree using where the root node is at index 0, what is the index of the left child node for a parent node at index 4?

-9

When finding the predecessor TNode, the code to go left once is most likely in TNode's ________ method. A) Remove B) RARM

-A) Remove

The disk file containing the Tree of hw9 is ___________ file. A) an ASCII B) a binary

-A) a binary

Guaranteed Initialization ________ be used to initialize reference data fields in a class. A) must B) can optionally C) cannot

-A)must

Guaranteed Initialization ________ be used to pass parameter required to initialize parent data fields in a class. A) must B) can optionally C) cannot

-A)must

Guaranteed Initialization ________ be used to pass parameters required to initialize object data fields in a class. A) must B) can optionally C) cannot

-A)must

preferable: A. Member, B. Non-Member, C. Neither

-A. Member

tree. B. On the way back up the tree. C. Either on the way up or on the way down.

-A. On the way up the tree.

Order the following items in a post-order traversal: A. go left, B. go right, C. visit

-A.B.C

Order the following items in an in-order traversal: A. go left, B. go right, C. visit

-A.C.B

What is the Java term for the equivalent to a pure virtual function in C++?

-Abstract method

of the scope resolution operator in C++?

-Access static data or static method

If inserting the alphabet from z to a into a binary search tree of hw7, the resultant tree would resemble what other data structure?

-Alphabet in reverse

What is the term for a node in a search path that terminates with a descendant?

-Ancestors

The predecessor TNode was found by going _____ once and then all the way _____. A) right, left B) left, right

-B) left, right

Guaranteed Initialization ________ be used to initialize primitive data fields in a class. A) must B) can optionally C) cannot

-B)can optionally

more.

-B. 1 or more

Guaranteed Initialization ________ be used to initialize array data fields in a class. A) must B) can optionally C) cannot

-C)cannot

When removing from the Tree of hw8 or hw9, the _______ TNode is "in charge" of restructuring the pointers in the Tree. P)arent or C)hild.

-C)hild

The successor TNode was the alphabetically _____ found in the _____ subtree. A) largest, right B) largest, left C) smallest, right D) smallest, left

-C)smallest, right

Is "virtual" a keyword in C++ or in Java or both?

-C++

parent? A. 0 or more, B. 1 or more, C. All of them

-C. All of them

Order the following items in a pre-order traversal: A. go left, B. go right, C. visit

-C.A.B

T or F: When using templates with a polymorphic generic container, if the name listed between < and > is the name of an existing type, the code is likely for the user of a generic container.

-T

T or F: With a successful "lazy" remove, the balance of all nodes along the search path are unchanged in the resultant tree.

-T

T or F: With a successful "lazy" remove, the height of all nodes along the search path are unchanged in the resultant tree.

-T

T or F: constructors for data allocated objects are called before main is called.

-T

T or F: destructors for data allocated objects are called after main execution is completed.

-T

Write Java for C++: TNode::occupancy++;

-TNode.occupancy++;

Write C++ for Java: TNode.occupancy++;

-TNode::occupancy++;

What is the term for a method that calls itself only from the end of a method?

-Tail Recursion

What is the term for visiting all nodes in a tree?

-Traversal

Besides inserting nodes such that the tree is complete, what is the other property of a binary tree makes it a heap data structure?

-Tree has the heap order (data of the parent nodes are greater than the children nodes)

T or F: A loop based solution often uses less memory than a recursive solution.

-True

T or F: A recursive solution usually involves less code than a loop based solution.

-True

T or F: A tree is a container object composed of 0 or more nodes.

-True

T or F: An ideal for a C++ class is to have as few friends as possible.

-True

T or F: Before a function execution begins, the address of the next instruction is pushed on the RTS.

-True

T or F: Bushy trees are preferable to spindly trees

-True

T or F: In a binary search tree, smaller items go left.

-True

T or F: In designing a recursive solution, code to avoid the recursive call must be part of the solution.

-True

T or F: Parameters act like local variables initialized by the calling method.

-True

T or F: Parameters are distinct from the original variable that is passed to a function call.

-True

T or F: RTS memory allocation is more efficient than heap memory allocation.

-True

T or F: References in C++ cannot be reset to refer to another variable within the same function.

-True

T or F: References in C++ give the programmer the power of pointers without pointer syntax.

-True

T or F: References in C++ must be established at the time of declaration.

-True

T or F: The Tree of hw7 is an example of a polymorphic generic container.

-True

T or F: The Tree of hw8 is an example of a polymorphic generic container.

-True

T or F: Using References in C++, the compiler enforces that the reference is not NULL.

-True

T or F: When class A announces that class B is a friend, class B can directly access private fields of class A.

-True

T or F: When class A is a friend of class B, class B is not necessarily a friend of class A.

-True

T or F: With recursion, each local variable exists multiple times, one copy for each recursive call.

-True

T or F: With recursion, the return address is comingled with parameters and local variables on the RTS.

-True

T or F: cerr is a global instance of class ostream.

-True

T or F: cin is a global instance of class istream.

-True

T or F: cout is a global instance of class ostream.

-True

first declared in the Base object definition.

-True

in the file of the method called.

-True

variables for that function.

-True

How many children can a node in a binary tree have?

-Two

Other than the root TNode, what is the minimum number of TNodes to write to disk when inserting an item into the Tree?

-Two, one that your adding fresh and it's parent

What is the term for the action to take when at a node when traversing a tree?

-Visit

A TNode is serialized from memory to disk by TNode's _______ method. R)ead W)rite

-W)rite

Why was operator << not a member method of UCSDStudent?

-We wanted to have consistance in using cout

the following code fragment call UCSDStudent's operator == method? if (stu1 == stu2) {

-Yes it does

For the ASCII file input of hw9, besides initiating reading from a file, when else do we care if the input is coming from a file or from the keyboard?

-checking for EOF

Write C++ for Java: class UCSDStudent extends Base {

-class UCSDStudent : public Base{

Write Java for C++: class UCSDStudent : public Base {

-class UCSDStudent extends Base {

What is the evaluation result of the following expression: cout << "Hello World\n";

-cout

The successor TNode was found by going _____ once and then all the way _____. A) right, left B) left, right

A)right, left

When finding the predecessor TNode, the code to go all the way right is most likely in TNode's ________ method. A) Remove B) RARM

B) RARM

Select the best word: loop _____ recursion.

OR OF -OR


Related study sets

Airway management and emergencies test EMT

View Set

Behavioral Neuroscience Chapter 12- Ingestive Behavior

View Set

Chapter 42 Circulation and Gas Exchange

View Set

Healthcare professionals (Metabolic Syndrome and Related Conditions)

View Set