CSCI 211 Chapter 1-6

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Given list: (20, 4, 114, 23, 34, 25, 45, 66, 77, 89, 11). How many list elements will be compared to find 77 using linear search?

9

Inserting an item at the beginning of a 999-item array requires how many items to be shifted?

999

An algorithm's best and worst case scenarios are always different.

An algorithm can have the same best and worst case, in which case the algorithm always does the same number of operations regardless of input data.

O(5) has a _____ runtime complexity.

Constant

Longest Common Substring

Do two student essays share a common phrase consisting of a sequence of more than 100 letters?

Collections gather and organize objects known as ______________ and define how they can be accessed?

Elements

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

The underlying data structure for a list data structure is the same for all programming languages.

False. The underlying data structures used to implement ADTs may vary between implementations. Some programming languages allow programmers to select a specific implementation.

The linear search algorithm's best case scenario is when N = 0.

False. The variable value N cannot be replaced with a constant of 0 to describe a best case scenario. A best case scenario must describe the contents of the data being processed.

Two different algorithms that produce the same result have the same computational complexity.

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

In Junit 4, to test for an exception, you only add a fail assertion statement at the end of the method.

False. You must also include the expected Exception to the annotation.

Test methods should simply be named test1, test2, etc. True False

False. You should be as specific as possible when naming test methods, so you don't have to dig through the code to know what test passed or failed.

Binary Search

Given a sorted list of a company's employee records and an employee's first and last name, what is a specific employee's phone number?

Shortest path algorithm

Given the airports at which an airline operates and distances between those airports, what is the shortest total flight distance between two airports?

In a circular linked list with at least 2 nodes, where does the tail node's next pointer point to?

List head

In a circular doubly-linked list with at least 2 nodes, where does the head node's previous pointer point to?

List trail

Collections are broken into how many categories?

2. Linear and non-linear

Given a list of 10,000 elements, and if each comparison takes 2 µs, what is the longest possible runtime for linear search?

20000µs

What does FibonacciNumber(8) return?

21

Given a list of 10,000 elements, and if each comparison takes 2 µs, what is the fastest possible runtime for linear search?

2µs

Given list: (20, 4, 114, 23, 34, 25, 45, 66, 77, 89, 11). How many list elements will be checked to find the value 114 using linear search?

3

What does FibonacciNumber(4) return?

3

Computational complexity analysis allows the efficiency of algorithms to be compared.

True

For method, border cases might include 0, a very large negative number, and a very large positive number.

True

In Junit 4, you don't have to do any extra imports to add a message to an assert.

True

In a circular linked list with 1 node, the tail node's next pointer points to the tail.

True

Items stored in an array can be accessed using a positional index.

True

Junit is the standard tool for test driven development in Java True False

True

ListTraverse can be used to traverse a doubly-linked list. True False

True

ListTraverseRecursive works for an empty list. True False

True

ListTraverseRecursive works for both singly-linked and doubly-linked lists.

True

Python, C++, and Java all provide built-in support for a deque ADT.

True

StackPop points a local variable to the list's head node.

True

The base case is what ensures that a recursive algorithm eventually terminates.

True

The dummy node's next pointer points to the first list item.

True

The statement below that assigns x with y is a constant time operation. y = 10 x = y

True

Using assertions is a preferred way to test a method. True False

True

When comparing two floating point values in the assertEquals method, you must use the method with the "delta" argument.

True

Unit refers to

a part of a program, typically a method. Unit testing means to test just that part, separately from other program parts.

An empty stack is indicated by a list head pointer value of _____.

null

O(N + N2) has a _____ runtime complexity.

quadtric

Each node in a doubly-linked list contains data and _____ pointer(s).

two

A test harness is

typically a separate program whose purpose is to test a method. Modifying an existing program and then modifying it back could introduce bugs.

An algorithm with a polynomial runtime is considered efficient.

True

An efficient algorithm to solve an NP-complete problem may exist.

True

A linear search has a _____ runtime complexity.

0(N)

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

0(N)

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

0(N)

A selection sort has a _____ runtime complexity.

0(n sqaure)

An interface cannot be instantiated. True False

True

An interface contains method declarations, as opposed to method definitions.

True

An item can be appended to an array-based list, provided the length is less than the array's allocated size.

True

Annotations before a method in Junit testing are required and indicates how the method should be executed.

True

Certain hardware may execute division more slowly than multiplication, but both may still be constant time operations.

True

What does FibonacciNumber(2) return?

1

Given list: (20, 4, 114, 23, 34, 25, 45, 66, 77, 89, 11). How many list elements will be checked if the search key is not found using linear search?

11

If ListTraverse is called to traverse a list with 10 nodes, how many calls to ListTraverseRecursive are made?

11

Inserting an item at the beginning of a 999-item linked list requires how many items to be shifted?

0

Inserting an item at the end of a 999-item array requires how many items to be shifted?

0

Inserting an item at the end of a 999-item linked list requires how many items to be shifted?

0

Junit 4 imports the same API as Junit 5 True False

False

The presence of a base case is what identifies an algorithm as being recursive.

False

Which sorting algorithm uses a gap value to jump between elements, and is difficult to adapt to linked lists for this reason?

Shell

A class may not simultaneously "extend" a class and "implement" an interface.

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

A linked list stores items in an unspecified order. True False

False. A linked list stores an ordered list of items. The links in each node define the order in which items are stored.

A loop is never a constant time operation. True False

False. A loop with a constant number of iterations can be a constant time operation.

Runtime and memory usage are the only two resources making up computational complexity.

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

An array-based list can have a default allocation size of 0. True False

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

Only a doubly-linked list can be circular. True False

False. Either a singly-linked or doubly-linked list can be circular.

A recursive algorithm applies itself to a smaller subproblem in all cases.

False. In the base case, the recursive algorithm completes without applying itself.

An efficient algorithm exists for all computational problems.

False. Many computational problems exist for which an efficient algorithm is unknown. Such problems are often encountered in real applications.

ADTs are only supported in standard libraries. True False

False. Many third-party libraries, which are not built in to the programming language standard, implement ADTs.

For a method with three integer inputs, about 3-5 test vectors is likely sufficient for testing purposes.

False. One might instead test dozens of normal cases, and perhaps ten or so border cases.

The head and tail pointers always point to the dummy node.

False. The head pointer always points to the dummy node, but the tail pointer will not point to the dummy node unless the list is empty.

The length of an array-based list equals the list's array allocation size.

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

The hardware running the code is the only thing that affects what is and what is not a constant time operation.

False. The programming language also affects what is a constant time operation.

Stacks are processed in a ______________ manner?

LIFO (last in first out)

Which operation should usually be preceded by a check that the stack is not empty?

Pop

A good programmer takes the time to test all possible input values for a method.

Testing all possible input values is simply not practical except for the most trivial of methods. A method with just one integer parameter has over 4 billion possible input values.

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 False

True

A key advantage of generic classes is relieving the programmer from having to write redundant code that differs only by type.

True

A lambda expression is a method without a name. True False

True

A list node's data can store a record with multiple subitems.

True

A node in binary tree can have zero, one, or two children. True False

True

Which operation determines if the queue contains no items?

isEmpty

Which operation determines if the stack contains no items?

isEmpty

O(N log N) has a _____ runtime complexity.

linearithemic

Why are sorting algorithms for arrays generally more difficult to adapt to singly-linked lists than to doubly-linked lists?

singly-linked list do not support backward traversal

A binary search recursive call is made when

the list element at index mid is less than the key. A base case does not involve a recursive call.

ListTraverse begins with _____.

the list's head node


Set pelajaran terkait

Finance Kansas License Practice Exam pt. 2

View Set

SIE Practice Exam #1 (score: 84%)

View Set

Pediatric Exam 2: School Age Child/Adolescent Developmental Notes, Acute Pediatric Illnesses Notes: Respiratory, Cardiac, GI, GU

View Set

Anatomy Week #3: Upper Limb II - Forearm, Wrist Joint & Hand

View Set

Bio172 TopHat Questions Section 2

View Set