UD CISC 220 - Final COK Review

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How long does something exist in the stack?

as long as the function is running

How many predecessors does the root have?

0

How many successors may each node in a tree have?

0 or more

Given int x[4] = {3, 2, 4, 1}; what does cout << arr[3] << endl; print?

1

How can you find the depth of a node?

1 + the depth of the parent

How many steps does it take to find a node in a binary search tree?

O log n

Define AVL tree.

a balanced binary search tree in which every subtree is also an AVL tree.

Define tree.

a collection of elements

What is an abstract data type?

a description of a data type

Define call by pointer.

a function argument in which a copy of the address is passed into the parameter

Define call by value.

a function argument in which a copy of the value is passed into the parameter

Define destructor.

a function that is called when an object goes out of scope

What does an asterisk denote?

a pointer

Define variable.

a storage location identified by a memory address paired with an associated symbolic name which contains a value

Define a full tree.

a tree in which every node has 0 or 2 non-null children

Define binary search tree.

a tree in which the data in every left node is less than the data in its parent, and the data in every right node is greater than the data in its parent

Define binary tree.

a tree in which the root has two subtrees, which are also binary trees

Define a complete tree.

a tree of height h that is filled to depth h-1 and, at depth h, unfilled nodes are on the right

Define subtree of a node.

a tree whose root is a child of that node

What does an ampersand denote?

an address

Define object.

an instance of a class

What is the default function argument for C++?

call by value

Is C++ compiled or interpreted?

compiled

What are Huffman codes used for?

compressing information

Given int x = 3;, how would you print the value of x?

cout << x << endl;

How do you add a first node to a linked list?

create a new node, set the first pointer to point to the new node, set the last pointer to point to the new node, increase the size of the list by one

How do you add a node to the end of list?

create a new node, set the last node's next pointer to point to the new node, set the last pointer to point to the new node, increase the size of the list by one

How do you dynamically allocate an array?

create a variable that will hold the address of the array and then set aside space in memory for the array and place the address of the array into the variable when needed

What is in order tree traversal used for?

creating a sorted list

How do you delete arrays on the heap?

delete every value in the array and then delete the array

What is postorder tree traversal used for?

deleting

What do we want to do at the ADT level?

describe what the data type is and what it should do

How could you create an array inside of a function and then have the array continue to exist after the function is done running?

dynamically allocate the array

Is the stack fast or slow?

fast

How do you find the address of the array?

find the address of the first value of the array

Where are variables and functions declared in a class?

in its header file

Where are functions called in a class?

in its main file

How would you generate a random number between 1 and 10?

int x = rand() % 10;

How would you generate a random number between 5 and 10?

int x = rand() % 5 + 5;

Why is it beneficial to use call by pointer rather than call by value? (2 reasons)

it allows changes made to the parameter to affect the value outside of the function; it has a smaller memory footprint than call by value

What is C++'s relationship to C?

it is a superset of C

What is a downside of using the heap for memory management?

it is slower and less efficient

What are the three parts of a variable?

it's name, it's value, and it's address

What happens on the stack when a function is called?

its variables are pushed onto the stack

Define branches.

links from a node to its successors

How do you print a linked list?

make a temp node that points to the first node in the list, print out the data in that node, set the temp point to point to the next value in the list, repeat until you you hit the end of the list

If a node has one child, how would you remove it?

make the parent point to the node's child and remove the node

What do arrays group?

many objects of the same type

What type of language is C++?

middle level

Define call by reference.

produces similar results as in call by pointer

Are struct properties public or private by default?

public

If a node has no children, how would you remove it?

remove the node and make its parent point to NULL

What does the keyword "delete" do?

removes something from the heap

If a node has two children, how would you remove it?

replace the node to be removed with the minimum value in the right subtree and make the minimum value's parent point to NULL

What does the "new" keyword do?

sets aside memory on the heap

Why do we specify type? (2 reasons)

so we know what we can do with a variable; so we know how much space to set aside in memory for the variable

How do you construct a linked list?

start with a NULL list, make first pointer point to NULL, make last pointer point to NULL, set size to 0

Define balanced.

when the height of the left subtree and the height of the right subtree differ at most by 1

How do you get the size of an array?

you can't, you must pass it in when you create the array

What is call by reference also known as?

aliasing

What happens on the stack when a function ends?

all of its variables are popped off the stack

What does "friend" do?

allows a class to have access to another class' private fields and methods

Define friends.

functions and classes defined with the "friend" keyword

What does a class include?

functions and variables

What does sizeOf() do?

gets the length of something in bytes

What is a pointer?

holds the address of a variable

How do you create an array of length 4?

int arr[4];

How do you find the balance of a node n?

n->left->height - n->right->height

What are the three characteristics of a linked list?

no fixed size, no wasted space, sequential access

Define leaves.

nodes with no children

Define siblings.

nodes with the same parent

What do classes group?

objects of different types

What do structs group?

objects of different types

How many predecessors does each node in a tree have?

one

What are the three kinds of tree traversal?

preorder, in order, and postorder

Why would it NOT be beneficial to always use call by pointer?

using call by value makes it so you can't accidentally change a value in another function

What is the algorithm for preorder tree traversal?

visit root, traverse left, traverse right

Define unbalanced.

when at least one node has a balance of 2 or -2

How can you avoid getting the same sequence of random numbers when using a random number generator?

you must give a specific seed in the main function

What is preorder tree traversal used for?

copying

Given int x = 3;, how would you print the address of x?

cout << &x << endl;

How long does something exist in the heap?

until the programmer deletes it

How do you seed your program? (2 things you must include in the main)

#include <time.h> srand(time(NULL));

Given int arr[4] = {2, 16, 8, 23};, if we know the size of ints, and that arrays occur sequentially in memory, what is the absolute minimum we need to know about the array to find any of the values in the array?

the address of the first value in the array

Given int x[4] = {3, 2, 4, 1};, what does cout << &arr[0] << endl; print?

the address of the first value in the array

Given int x = 4; and int *y = &x;, what does cout << y << endl; print?

the address of x

Given int x = 4;, what does cout << &x << endl; print?

the address of x

Given int x = 4; and int *y = &x;, what does cout << &y << endl; print?

the address of y

What controls the stack?

the compiler

What two parts make up an element in a linked list?

the data, a pointer to the data

Define depth of a node.

the distance from the root to that node

What are the four characteristics of a list?

the items have an order, it has a size, data can be duplicated, all elements have the same data type

Define tree traversal.

the process of walking a tree and visiting all the nodes in a certain order

What controls the heap?

the programmer

What are the types of memory

the stack and the heap

Given int x = 4; and int (star)y = &x;, what does cout << (star)y << endl; print?

the value in x

Given int x = 4;, what does cout << x << endl; print?

the value in x

What is the algorithm for postorder tree traversal?

traverse left, traverse right, visit root

What is the algorithm for in order tree traversal?

traverse left, visit root, traverse right

How many types of memory are there?

two


Kaugnay na mga set ng pag-aaral

CHAPTER 9: INTERPERSONAL ATTRACTION

View Set

Cognitive Psychology Exam 3 (Quizzes 9, 11, & 12)

View Set

Principles of Real Estate II: Ch. 9

View Set

Node.js Interview Questions - Beginner Level

View Set

Policy provisions and contract laws

View Set

C++ CPT-232 Chapter 4 Review questions (1-30 & 42-58)

View Set

7th Grade - Ratios and Proportional Reasoning Review

View Set

learner's permit: For Georgia 2016

View Set