Data Structures Exam 1 - Chapter 3

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

(T/F) Runtime and memory usage are the only two resources making up computational complexity

False! These are just two of the most commonly evaluated factors

(T/F) The linear search algorithm's best case scenario is when N=0

False! Must always treat input size as a variable

(T/F) Two different algorithms that produce the same result have the same computational complexity

False! The same output does not relate to memory use, time to run, etc.

Consider the following function, which builds and returns a list of even numbers from the input list. GetEvens(list, listSize) { i = 0 evensList = Create new, empty list while (i < listSize) { if (list[i] % 2 == 0) Add list[i] to evensList i = i + 1 } return evensList } What is the minimum possible size of the returned list? + listSize/2 + 1 + 0

0 the list is initialized with size 0, so if none of the numbers are even, the function will return an empty list

(T/F) When evaluating complexity of an algorithm, it is sufficient to say that the best case scenario is when an algorithm has N=0

A best case or worst case scenario describes contents of the algorithm's input data only. The input data size must remain a variable, N. Otherwise, the overwhelming majority of algorithms would have a best case of N=0, since no input data would be processed. In both theory and practice, saying "the best case is when the algorithm doesn't process any data" is not useful. Complexity analysis always treats the input data size as a variable.

computational problem

A computational problem specifies an input, a question about the input that can be answered using a computer, and the desired output.

(T/F) Algorithms must be written using a programming language

False!

algorithm

An algorithm describes a sequence of steps to solve a computational problem or perform a calculation. An algorithm can be described in English, pseudocode, a programming language, hardware, etc.

Algorithm efficiency

An algorithm describes the method to solve a computational problem. Programmers and computer scientists should use or write efficient algorithms. Algorithm efficiency is typically measured by the algorithm's computational complexity.

runtime complexity

An algorithm's runtime complexity is a function, T(N), that represents the number of constant time operations performed by the algorithm on an input of size N.

Space complexity

An algorithm's space complexity is a function, S(N), that represents the number of fixed-size memory units used by the algorithm for an input of size N. Ex: The space complexity of an algorithm that duplicates a list of numbers is S(N) = 2N + k, where k is a constant representing memory used for things like the loop counter and list pointers. Space complexity includes the input data and additional memory allocated by the algorithm.

worst case

An algorithm's worst case is the scenario where the algorithm does the maximum possible number of operations.

best case

Because an algorithm's runtime may vary significantly based on the input data, a common approach is to identify best and worst case scenarios. An algorithm's best case is the scenario where the algorithm does the minimum possible number of operations

What is a common algorithm used in search engines?

Binary search Binary search: The binary search algorithm is an efficient algorithm for searching a list. The list's elements must be sorted and directly accessible (such as an array).

Computational complexity

Computational complexity is the amount of resources used by the algorithm. The most common resources considered are the runtime and memory usage.

relationship between algorithms and data structures

Data structures not only define how data is organized and stored, but also the operations performed on the data structure. While common operations include inserting, removing, and searching for data, the algorithms to implement those operations are typically specific to each data structure. Example: linked list vs. array

(T/F) An algorithm's best and worst case scenarios are always different

False

(T/F) An efficient algorithm exists for all computational problems

False (example: NP Problems)

NP-complete problems

NP-complete problems are a set of problems for which no known efficient algorithm exists.

characteristics of NP-complete problems

No efficient algorithm has been found to solve an NP-complete problem. No one has proven that an efficient algorithm to solve an NP-complete problem is impossible. If an efficient algorithm exists for one NP-complete problem, then all NP-complete problems can be solved efficiently.

Consider the following function, which builds and returns a list of even numbers from the input list. GetEvens(list, listSize) { i = 0 evensList = Create new, empty list while (i < listSize) { if (list[i] % 2 == 0) Add list[i] to evensList i = i + 1 } return evensList } What is the worst case auxiliary space complexity of GetEvens if N is the list's size and k is a constant? + S(N) = N + k + S(N) = k

S(N) = N +k In the worst case, all items from the input list are added to the returned list. As the input size N increases, the output size increases to match.

Consider the following function, which builds and returns a list of even numbers from the input list. GetEvens(list, listSize) { i = 0 evensList = Create new, empty list while (i < listSize) { if (list[i] % 2 == 0) Add list[i] to evensList i = i + 1 } return evensList } What is the best case auxiliary space complexity of GetEvens if N is the list's size and k is a constant? + S(N) = N + k + S(N) = k

S(N) = k In the best case, the input list contains only odd numbers and the output size is 0, whether the list has 10 odd numbers or 1000 odd numbers. A constant output size of zero corresponds to an auxiliary space complexity of k.

(T/F) an algorithm with a polynomial runtime is considered efficient

True An efficient algorithm is generally one whose runtime increases no more than polynomially with respective to the input size. In contrast, an algorithm with an exponential runtime is not efficient.

(T/F) Computational complexity analysis allows the efficiency of algorithms to be compared

True for example, runtime and space complexity analysis provide a mathematical way to compare algorithm efficiency

(T/F) An efficient algorithm to solve an NP-complete problem may exist

True! Part of the criteria of a NP-problem is that while there is not an efficient algorithm, no one has proved that an efficient algorithm does not exist

Consider the problem of determining the number of times (or frequency) a specific word appears in a list of words Which can be used as the problem input? + string for user-specified word + array of unique words and string for user-specified words + array of all words and string for user-specified word

array of all words and string for user-specified word

Consider the problem of determining the number of times (or frequency) a specific word appears in a list of words What is the problem output? + integer value for the frequency of most frequent word + string value for the most frequent word in input array + integer value for the frequency of specified word

integer value for the frequency of specified word

Consider the following function, which builds and returns a list of even numbers from the input list. GetEvens(list, listSize) { i = 0 evensList = Create new, empty list while (i < listSize) { if (list[i] % 2 == 0) Add list[i] to evensList i = i + 1 } return evensList } What is the maximum possible size of the returned list?

listSize This could occur if all of the numbers are even

Auxiliary space complexity

n algorithm's auxiliary space complexity is the space complexity not including the input data. Ex: An algorithm to find the maximum number in a list will have a space complexity of S(N) = N + k, but an auxiliary space complexity of S(N) = k, where k is a constant.


Set pelajaran terkait

Ch. 10 Strategy and the Master Budget

View Set

CIS-202 Chapter 4 - Data Modeling and the Entity-Relationship Model

View Set