CSC205 Exam 3 Practice

¡Supera tus tareas y exámenes ahora con Quizwiz!

An interface cannot be instantiated. (TRUE OR FALSE)

True Explanation: An interface only declares methods, and does not provide complete method definitions. Thus, it cannot be instantiated.

What must a recursive algorithm include?

A recursive algorithm must have a base case: A case where a recursive algorithm completes without applying itself to a smaller subproblem.

What is a Singly-linked list data structure?

A singly-linked list is a data structure for implementing a list ADT, where each node has data and a pointer to the next node. In-depth explanation: A singly-linked list's first node is called the head, and the last node the tail. A singly-linked list is a type of positional list: A list where elements contain pointers to the next and/or previous elements in the list.

What is Radix sort?

A sorting algorithm designed specifically for integers. The algorithm makes use of a concept called buckets and is a type of bucket sort. Radix Sort Algorithm Explanation: The algorithm processes one digit at a time starting with the least significant digit and ending with the most significant. Two steps are needed for each digit. First, all array elements are placed into buckets based on the current digit's value. Then, the array is rebuilt by removing all elements from buckets, in order from lowest bucket to highest.

What is bubble sort?

A sorting algorithm that iterates through a list, comparing and swapping adjacent elements if the second element is less than the first element.

Unordered lists have no ordering. (TRUE OR FALSE)

False

Runtime and memory usage are the only two resources making up computational complexity. (TRUE OR FALSE)

False Explanation: Although runtime and memory usage are the most common, computational complexity can include other factors, such as network communication.

A class may not simultaneously "extend" a class and "implement" an interface. (TRUE OR FALSE)

False Explanation: A class can both extend a class and implement an interface.

A directory in a file system tree is always an internal node. (TRUE OR FALSE)

False Explanation: A directory containing 1 or more files or directories is an internal node, but an empty directory is a leaf node

An array-based list can have a default allocation size of 0. (TRUE OR FALSE)

False Explanation: An array-based list starts with a length of 0, but the default allocation size must be >= 1.

The length of an array-based list equals the list's array allocation size. (TRUE OR FALSE)

False Explanation: The list's length and allocation size are two separate values, such that the length is <= array allocation size.

Two different algorithms that produce the same result have the same computational complexity. (TRUE OR FALSE)

False Explanation: Two different algorithms can produce the same result in various ways and may have different computational complexities.

An efficient algorithm exists for all computational problems. (TRUE OR FALSE)

False Many computational problems exist for which an efficient algorithm is unknown.

BSTInsert will not work if the tree's root is null. (TRUE OR FALSE)

False Explanation: At the beginning of BSTInsert, a null root node is handled as a special case. The node will be inserted as the tree's root.

A node in binary tree can have zero, one, or two children. (TRUE OR FALSE)

True

An iterator provides a way to retrieve items from a list in a sequential manner.

True

Computational complexity analysis allows the efficiency of algorithms to be compared. (TRUE OR FALSE)

True

Items stored in an array can be accessed using a positional index. (TRUE OR FALSE)

True

An algorithm with a polynomial runtime is considered efficient. ( TRUE OR FALSE)

True An efficient algorithm is generally one whose runtime increases no more than polynomially with respect to the input size.

A file in a file system tree is always a leaf node. (TRUE OR FALSE)

True Explanation: A file cannot contain additional files, and therefore is always a leaf node in a file system tree.

A stack is a container that allows elements to be stored and removed ________.

in a last-in-first-out fashion (LIFO)

A Java collection ________.

is an object that is used as a container for other objects

If the head pointer is null, the queue _____.

is empty Explanation: A value of null indicates that the pointer points to nothing, so the queue is empty.

A list is a ______________ collection.

linear

The three major categories of Java collections are ________.

lists, sets, and maps

Given that parkingQueue has no items (i.e., is empty) What does GetLength(parkingQueue) return?

0 Explanation: If 0 items exist, length is 0.

What are the basic data structures?

1 - Record : A record is the data structure that stores subitems, often called fields, with a name associated with each subitem. 2 - Array : Stores an ordered list of items, where each item is directly accessible by a positional index. 3 - Linked List : stores an ordered list of items in nodes, where each node stores data and has a pointer to the next node. 4 - Binary Tree : a data structure in which each node stores data and has up to two children, known as a left child and a right child. 5 - Hash Table : a data structure that stores unordered items by mapping (or hashing) each item to a location in an array. 6 - Heap : A max-heap is a tree that maintains the simple property that a node's key is greater than or equal to the node's childrens' keys. A min-heap is a tree that maintains the simple property that a node's key is less than or equal to the node's childrens' keys. 7 - Graph : A graph is a data structure for representing connections among items, and consists of vertices connected by edges. A vertex represents an item in a graph. An edge represents a connection between two vertices in a graph.

Starting with an empty list, what is the list contents after the following operations? Append(list, 11) Append(list, 4) Append(list, 7)

11, 4, 7 (11 is appended to an empty list, yielding: 11 , 4 is appended, yielding: 11, 4 , 7 is appended, yielding: 11, 4, 7)

Given numStack: 41, 8 (top is 41) What is the stack after the following operations? Pop(numStack) Push(numStack, 2) Push(numStack, 15) Pop(numStack)

2, 8 Explanation: The first pop removes 41. The stack becomes: 8Pushing 2 yields: 2, 8Pushing 15 yields: 15, 2, 8The final pop removes 15. The stack becomes: 2, 8

A remove operation for a list ADT will remove the specified item. Given a list with contents: 2, 20, 30, what is the list contents after the following operation? Remove(list, item 2)

20, 30 (Item 2 is removed from the list, yielding: 20, 30)

Given rosterQueue: 400, 313, 270, 514, 119 What does GetLength(rosterQueue) return?

5 Explanation: GetLength returns the number of items in the queue, which contains five items: 400, 313, 270, 514, 119.

Given numStack: 5, 9, 1 (top is 5) What is the stack after the following pop operation?

9, 1 Explanation: The pop operation removes the stack's top item, 5. Remaining stack elements are: 9, 1.

What is a BST node's predecessor?

A BST node's predecessor is the node that comes before in the BST ordering.

What is a BST node's successor?

A BST node's successor is the node that comes after in the BST ordering, Example: (In the A B C, A's successor is B, and B's successor is C).

What is a queue?

A queue is an ADT in which items are inserted at the end of the queue and removed from the front of the queue.

What is a queue referred to?

A queue is referred to as a first-in first-out ADT. (FIFO)

When would a binary tree be considered complete?

A binary tree is complete if all levels, except possibly the last level, contain all possible nodes and all nodes in the last level are as far left as possible.

When would a binary tree be considered full?

A binary tree is full if every node contains 0 or 2 children.

When would a binary tree be considered perfect?

A binary tree is perfect, if all internal nodes have 2 children and all leaf nodes are at the same level.

What is a bucket?

A bucket is a collection of integer values that all share a particular digit value. Any array of integer values can be subdivided into buckets by using the integer values' digits.

What is a constant time operation?

A constant time operation is an operation that, for a given processor, always operates in the same amount of time, regardless of input values.

What is a data structure?

A data structure is a way of organizing, storing, and performing operations on data.

What is a doubly-linked list?

A doubly-linked list is a data structure for implementing a list ADT, where each node has data, a pointer to the next node, and a pointer to the previous node.

What is a doubly-linked list reverse traversal?

A doubly-linked reverse traversal visits all nodes starting with the list's tail node and ending after visiting the list's head node.

What is a generic class?

A generic class is a class definition having a special type parameter that may be used in place of types in the class. (A variable declared of that generic class type must indicate a specific type.)

What is a generic method?

A generic method is a method definition having a special type parameter that may be used in place of types in the method

What is a list?

A list is a common ADT for holding ordered data, having operations like append a data item, remove a data item, search whether a data item exists, and print the list.

What is a linked list traversal?

A list traversal algorithm visits all nodes in the list once and performs an operation on each node.

What is a nearly sorted?

A nearly sorted list only contains a few elements not in sorted order. Ex: (4, 5, 17, 25, 89, 14) is nearly sorted having only one element not in sorted position.

What is a parent in a binary tree?

A node with a child is said to be that child's parent. A node's ancestors include the node's parent, the parent's parent, etc., up to the tree's root.

What is an internal node in a binary tree?

A node with at least one child.

What is the peek operation?

A peek operation returns an item in the deque without removing the item.

What is insertion sort?

A sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly inserts the next value from the unsorted part into the correct location in the sorted part.

What is selection sort?

A sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly selects the proper next value to move from the unsorted part to the end of the sorted part.

What is a stack?

A stack is an ADT in which items are only inserted on or removed from the top of a stack.

What is a stack referred to?

A stack is referred to as a last-in first-out ADT. (LIFO)

What is a leaf in a binary tree?

A tree node with no children.

which of the following are not a queue operation? A. remove B. enqueue C. dequeue D. isEmpty

A. remove

What is an algorithm?

An algorithm describes a sequence of steps to solve a computational problem or perform a calculation.

What is a recursive algorithm?

An algorithm that breaks the problem into smaller subproblems and applies the algorithm itself to solve the smaller subproblems.

In an ordered list, list elements are ordered by ________. A. magic B. some relationship inherent to the objects C. sorting the list D. the listOrder method

B. some relationship inherent to the objects

The notation < E extends Comparable<E> > ________. A.will be rejected by the Compiler as an error B. is used when there is a recursive definition of the generic type E C. declares a generic type that implements the Comparable interface D. None of the above

C. declares a generic type that implements the Comparable interface

One of the advantages of using generics is ________. A. that programs that use generic code require less effort in design and development B. that programs that use generics are smaller when translated to byte code C. that more type problems can be uncovered at compile-time rather than at run time D. that program that use generics execute faster than programs that do not

C. that more type problems can be uncovered at compile-time rather than at run time

Elements can be added only to one end of a linked list.

False

A linked list stores items in an unspecified order. (TRUE OR FALSE)

False

Queues are ________ in, first out structure.

First (FIFO)

In the declaration ArrayList<T>, T is a(n) _________.

Generic Type

What is the append operation of a doubly-linked list?

Given a new node, the Append operation for a doubly-linked list inserts the new node after the list's tail node. The append algorithm behavior differs if the list is empty versus not empty: Append to empty list: If the list's head pointer is null (empty), the algorithm points the list's head and tail pointers to the new node. Append to non-empty list: If the list's head pointer is not null (not empty), the algorithm points the tail node's next pointer to the new node, points the new node's previous pointer to the list's tail node, and points the list's tail pointer to the new node.

What is the append operation of a singly-linked list?

Given a new node, the Append operation for a singly-linked list inserts the new node after the list's tail node.

What is the InsertAfter operation of a doubly-linked list?

Given a new node, the InsertAfter operation for a doubly-linked list inserts the new node after a provided existing list node.

What is the InsertAfter operation of a singly-linked list ?

Given a new node, the InsertAfter operation for a singly-linked list inserts the new node after a provided existing list node.

What is the prepend operation of a singly-linked list ?

Given a new node, the Prepend operation for a singly-linked list inserts the new node before the list's head node.

What is the prepend operation of a doubly-linked list?

Given a new node, the Prepend operation of a doubly-linked list inserts the new node before the list's head node and points the head pointer to the new node.

What is the RemoveAfter operation of a singly-linked list ?

Given a specified existing node in a singly-linked list, the RemoveAfter operation removes the node after the specified list node.

The length from the longest path from the root to the leaf is -----?

Height

Why do we only care about the highest term when determining Big O and Growth Rates?

In Big O notation, all functions that have the same growth rate (as determined by the highest order term of the function) are characterized using the same Big O notation. In essence, all functions that have the same growth rate are considered equivalent in Big O notation.

A binary tree each node has up to __ children?

In a binary tree, each node has up to two children, known as a left child and a right child.

Which operation determines if the queue contains no items?

IsEmpty Explanation: IsEmpty returns true if the queue has no items, and false if the queue contains one or more items.

What is Java's Collections class?

Java's Collections class provides static methods that operate on various types of lists such as an ArrayList.

What are the two basic searching algorithms?

Linear search and Binary search. Explanation: Linear search is a search algorithm that starts from the beginning of a list, and checks each element until the search key is found or the end of the list is reached. Binary search is a faster algorithm for searching a list if the list's elements are sorted and directly accessible (such as an array). Binary search first checks the middle element of the list. If the search key is found, the algorithm returns the matching location. If the search key is not found, the algorithm repeats the search on the remaining left sublist (if the search key was less than the middle element) or the remaining right sublist (if the search key was greater than the middle element).

The concrete classes that implement the List interface are ________.

LinkedList and ArrayList

The ArrayList implements what collections interface?

List

What is sorting?

Sorting is the process of converting a list of elements into ascending (or descending) order.

What is the remove operation of a doubly-linked list?

The Remove operation for a doubly-linked list removes a provided existing list node.

What does the queue "enqueue" operation do?

The queue enqueue operation inserts an item at the end of the queue.

what does the implements keyword tell the compiler?

The implements keyword tells the compiler that a class implements, instead of extends, a particular interface (e.g., Comparable<EmployeeData>).

What is the root in a binary tree?

The one tree node with no parent. (the "top" node).

What does the queue "dequeue" operation do?

The queue dequeue operation removes and returns the item at the front of the queue.

A list node's data can store a record with multiple subitems. (TRUE OR FALSE)

True

What does the stack "pop" operation do?

The stack pop operation removes and returns the item at the top of the stack.

What does the stack "push" operation do?

The stack push operation inserts an item on the top of the stack.

What are trees commonly used to represent?

Trees are commonly used to represent hierarchical data. (A tree can represent files and directories in a file system, since a file system is a hierarchy.)

A Set holds a unique group of values/objects. (TRUE OR FALSE)

True

Using a tree data structure to implement a file system requires that each directory node support a variable number of children. (TRUE OR FALSE)

True Explanation: Unlike binary trees that have a fixed number of children per node, a file system tree must support a variable number of children per directory node.

An efficient algorithm to solve an NP-complete problem may exist. (TRUE OR FALSE)

True Whether or not an efficient algorithm exists for NP-complete problems is an open research question. However, the current consensus is that such an algorithm is unlikely.

BSTGetHeight would also work if the recursive call on the right child was made before the recursive call on the left child. (TRUE OR FALSE)

True Explanation: The order of the two recursive calls does not matter. As long as the 2 recursive calls are made and the greater of the 2 returned heights is used, BSTGetHeight will properly determine the tree height.

BSTRemoveNode may use recursion. (TRUE OR FALSE)

True Explanation: When an internal node with 2 children is being removed, BSTRemoveNode uses recursion to remove the successor node.

Lower bound

When A function f(N) that is ≤ the best case T(N), for all values of N ≥ 1.

Upper bound

When A function f(N) that is ≥ the worst case T(N), for all values of N ≥ 1.

What is Big O notation?

a mathematical way of describing how a function (running time of an algorithm) generally behaves in relation to the input size.

What is an efficient algorithm?

an efficient algorithm is one whose runtime increases no more than polynomially with respect to the input size.

Elements can be added to _______.

any location in a list.

In a generic method, a type parameter is defined ________.

before the method's return type

What is the link from a node to a child called?

edge

Linked lists are made up of individual ________.

nodes

What is Computational complexity?

the amount of resources used by the algorithm. (The most common resources considered are the runtime and memory usage.)

What is an algorithm's worst case scenario?

the scenario where the algorithm does the maximum possible number of operations.

What is an algorithms best case scenario?

the scenario where the algorithm does the minimum possible number of operations.

In an array-based implementation of a stack, an operation that needs to add a new element to the stack may not be able to complete because the array is full. In this case, the failed operation should ________.

throw some appropriately defined exception

Going through the entire list starting with the head/front is called _______ the list.

traversing

A HashMap ________.

uses hash codes to store keys


Conjuntos de estudio relacionados

PN PASSPOINT (Anxiety Disorders)

View Set

Prep 2: How Does Evolution Relate to Influenza?

View Set

Ethical Hacking and Network Defense Chpt 4-6

View Set

Leadership Test 1 oriented questions

View Set

UNT: PSYC 4520 - Personality - Chapters 11-13

View Set

Anxiety Disorders Adaptive Quizzing

View Set

BCOM 3950 Ch 7: Evaluating Emails

View Set