CSC205 Finale

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

When evaluating an algorithm, which of the following most likely contributes to the efficiency of the algorithm?

The number of comparisons made to process each item

Given the list (27, 40, 15, 25, 10, 19, 30), what are the new partitioned lists if the pivot is 25?

(10, 15, 19, 25) and (27, 30, 40)

A for loop of the form for (i = 0; i < N; ++i) {} that does not have nested loops or function calls, and does not modify i in the loop will always have a complexity of O(N).

True

The asymptotic complexity is determined by the dominant term, which is generally the term with the largest exponent of the variable. This is the term whose value dominates the value of the polynomial for sufficiently large values of the variable

True

Suppose a sorted list of 1024 elements is searched with binary search. How many distinct list elements are compared against a search key that is less than all elements in the list?

10 elements

How many times longer will sorting a list of 500 elements take compared to a list of 50 elements?

100

Assume an ordered list containing the English alphabet. Using linear search, how many letters are checked to locate the letter "K"?

11

Given a list with items 40, 888, -3, 2, what does GetLength(list) return?

4

When sorting a list with 50 elements, indexSmallest will be assigned to a minimum of _____ times.

49

An algorithm has liner time complexity and can process an input of size n in a certain amount of time. If the algorithm runs on a computer that has a processor that is 5 times as fast, how large of an input can be processed in the same amount of time?

5n

Suppose BinarySearch is used to search for a key within a list with 64 numbers. If the key is not found, how many recursive calls to BinarySearch are made?

7

A list of 10 elements is to be sorted using insertion sort algorithm. How many times will the outer loop be executed?

9

A list is a common ________ 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

Abstract data type

_______ is the classification of runtime complexity that uses functions that indicate only the growth rate of a bounding function

Asymptotic notation

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

Big O notation

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

before the method's return type

A _______________ search is more efficient than a linear search.

binary

The ___________________ algorithm sorts values by repeatedly comparing neighboring elements in the list and swapping their position if they are not in order relative to each other

bubble sort

________ can be used to sort the same set of objects in multiple ways

comparator objects

A binary tree is _______ 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.

complete

The notation < E extends Comparable > ________.

declares a generic type that implements the Comparable interface

A node's _______ is the number of edges on the path from the root to the node. The root node thus has depth 0

depth

A ________ 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.

doubly-linked

The link from a node to a child is called an_________

edge

public enum Face { ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING }

enum type

Which function best represents the number of operations in the worst-case? i = 0 sum = 0 while (i < N) { sum = sum + numbers[i] ++i }

f(N) = 3N+3

A binary tree is ________-if every node contains 0 or 2 children. A binary tree is _______, if all internal nodes have 2 children and all leaf nodes are at the same level.

full, perfect

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

generic type

The __________________ algorithm sorts a list of values by repetitively inserting a particular value into a subset of the list that has already been sorted.

insertion sort

A Java collection ________.

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

In a binary search, _______________________________

it is assumed that the search pool is ordered

If the growth function for an algorithm is expressed as a polynomial, then the asymptotic complexity of the algorithm is determined by the term with the ________________ .

largest exponent of the variable

In selection sort, the smallest element is selected and swapped with the _____ unsorted element.

left

A __________________ search looks through the search pool one element at a time.

linear

A growth function that is O(n) is ___________________

linear

What aspect of linked lists makes adapting array-based sorting algorithms to linked lists difficult?

Elements in a linked list cannot be accessed by index.

A loop is never a constant time operation. True False

FALSE

The ArrayList implements what collections interface?

list

________traverse the left subtree, then visit the root, then traverse the right subtree, LVR

Inorder

_________ is 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.

Insertion sort

A node with at least one child.

Internal node

The three major categories of Java collections are ________

lists, sets, and maps

______A tree node with no children.

Leaf

We need to examine _______________ when evaluating the order of an algorithm.

loops, nested loops and method calls

Finding the middle of the list requires searching linearly from the head of the list. The merge algorithm can also merge lists without additional storage.

merge sort

_________ traverse the subtrees from left to right, then visit the root, LRV

postorder

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

singly-linked

One of the advantages of using generics is ________.

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

_______ provides a growth rate for an algorithm's upper bound.

O notation

What is the big-O notation for the best-case runtime? i = 0 belowMinSum = 0.0 belowMinCount = 0 while (i < N && numbers[i] <= maxVal) { belowMinCount = belowMinCount + 1 belowMinSum = numbers[i] ++i } avgBelow = belowMinSum / belowMinCount O(1) O(N)

O(1)

Which of the following complexity measures is the most efficient?

O(1)

What is the big-O notation for the worst-case runtime?for (i = 0; i < N; ++i) { if ((i % 2) == 0) { outVal[i] = inVals[i] * i } }

O(N)

Which of the following Big O notations is equivalent to O(734·N)?

O(N)

Which of the following Big O notations is equivalent to O(N+9999)?

O(N)

Which of the following Big O notations is equivalent to O(12·N +6·N3 + 1000)?

O(N)^3

A selection sort has a _____ runtime complexity.

O(N^2)

A loop body is controlled by the following statement: for (int count = 2; count <= n; count +=2) If the statements in the body of the loop are all O(1), what is the order of the loop?

O(n^2)

A Set holds a unique group of values/objects.

true

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

Parent, ancestors

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

Root

Big - Oh notation establishes a(n) ____________ on a growth function

upper bound

public static String stripVowels(String str) { String v = ""; for (int i=0; i<str.length(); i++) if (isConsonant(str.charAt(i))) v+=str.charAt(i); return v; }

Strip Vowels

Recurrence relations have

T on both sides of equation

_______ provides a growth rate that is both an upper and lower bound.

Θ notation

______ provides a growth rate for an algorithm's lower bound.

Ω notation

Determine the simplified Big O notation. 3*N*0(N^2)

O(N^3)

Assuming nVal is an integer, what is the big-O notation for the worst-case runtime?

O(log N)

_________is 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.

Selection sort

A tree's _______ is the largest depth of any node. A tree with just one node has height 0.

height

Identify the correct sequence of performing a binary search.

1. Binary search first checks the middle element of the list. 2. If the search key is not found, the algorithm: i. checks the left sublist if the search key is less than the middle element or ii. checks the right sublist if the search key is greater than the middle element.

How many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?

4

Using the Big O runtime complexity, how many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?

4

____________ similarly on doubly-linked lists. Requires searching from the head of the list for an element's insertion position for singly-linked lists.

Insertion sort operates

The concrete classes that implement the List interface are ________.

LinkedList and ArrayList

What is the big-O notation for the worst-case runtime? negCount = 0 for(i = 0; i < N; ++i) { if (numbers[i] < 0 ) { ++negCount } }

O(N)

Determine the simplified Big O notation. 10+O(N)^2

O(N^2)

Which is the worst case runtime for a quicksort algorithm?

O(N^2)

A file in a file system tree is always a leaf node.

TRUE

In the code below, suppose str1 is a pointer or reference to a string. The code only executes in constant time if the assignment copies the pointer/reference, and not all the characters in the string. str2 = str1

TRUE

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

TRUE

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

constant time operation

Suppose that a loop executes n times. The loop contains a method call whose order is O(n2), and some other statements that are O(1). From a complexity standpoint, the order of the loop is

n^3

visit the root, then traverse the subtrees from left to right, VLR

preorder

Which sorting technique does not compare two values and then sort the values?

radix sort


Kaugnay na mga set ng pag-aaral

Chapter 4 : Nucleic Acids and RNA - Homework Questions

View Set

Economics 2302 Chapter 11: Price Discrimination

View Set

SOPHIA Human Biology Unit 2 Challenge 2: Skeletal Muscles

View Set

Chapter 3 Inflammation and Tissue Repair

View Set

Ch.2 The Market System and the Circular Flow

View Set

Society The Basics: Gender Stratification

View Set