Docsity

Chapter 1--Introduction to Data Structures & Algorithms, Exams of Data Structures and Algorithms

Toggle sidebar
bg1
Chapter 1--Introduction to
Data Structures & Algorithms
A list ADT is commonly implemented using - ANSarrays or linked list data
structures.
A list ADT's underlying data structure has no impact on the program's
execution. t/f - ANSf. different underlying data structures will require different
algorithms to perform same list ADT operation, which will have different
runtimes. Ex: For prepending an item to a list, a linked list-based
implementation is more efficient than an array-based implementation.
A list node's data can store a record with multiple subitems.True/False -
ANSTrue
A node in binary tree can have zero, one, or two children.True/False - ANSTrye
abstract data type (ADT) is a - ANSdata type described by predefined user
operations, such as "insert data at rear," without indicating how each
operation is implemented.
Abstraction means - ANSto have a user interact with an item at a high-level,
with lower-level internal details hidden from the user.
Abstraction simplifies________.ADTs allow programmers to focus on choosing
which ______ best match a program's needs. - ANS- programming.
- ADTs
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Chapter 1--Introduction to Data Structures & Algorithms and more Exams Data Structures and Algorithms in PDF only on Docsity!

Chapter 1--Introduction to

Data Structures & Algorithms

A list ADT is commonly implemented using - ANSarrays or linked list data structures. A list ADT's underlying data structure has no impact on the program's execution. t/f - ANSf. different underlying data structures will require different algorithms to perform same list ADT operation, which will have different runtimes. Ex: For prepending an item to a list, a linked list-based implementation is more efficient than an array-based implementation. A list node's data can store a record with multiple subitems.True/False - ANSTrue A node in binary tree can have zero, one, or two children.True/False - ANSTrye abstract data type (ADT) is a - ANSdata type described by predefined user operations, such as "insert data at rear," without indicating how each operation is implemented. Abstraction means - ANSto have a user interact with an item at a high-level, with lower-level internal details hidden from the user. Abstraction simplifies________.ADTs allow programmers to focus on choosing which ______ best match a program's needs. - ANS- programming.

  • ADTs

ADTs are only supported in standard libraries. - ANSf. Many third-party libraries, which are not built in to the programming language standard, implement ADTs. ADTs in standard libraries - ANSMost programming languages provide standard libraries that implement common abstract data types. ADTs support abstraction by - ANShiding the underlying implementation details and providing a well-defined set of operations for using the ADT. algorithm - ANSdescribes a sequence of steps to solve a computational problem or perform a calculation. Algorithm efficiency is typically measured by - ANSthe algorithm's computational complexity. An algorithm to solve this computation problem must be written using a programming language. T/F - ANSFalse.An algorithm can be described in English, pseudocode, a programming language, hardware, etc., as long as the algorithm precisely describes the steps of a computational procedure. An algorithm's auxiliary space complexity is - ANSthe 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. An algorithm's best case - ANSis the scenario where the algorithm does the minimum possible number of operations. An algorithm's computational complexity includes - ANSruntime and memory usage.

Computational complexity is - ANSthe amount of resources used by the algorithm. Computational Problem - ANScomputational problem specifies an input, a question to be answered about the input that can be answered using a computer, and the desired output. computational problems and common algorithms: DNA analysis-- CP: Given two DNA sequences from different individuals, what is the longest shared sequence of nucleotides? What is the common algorithm? - ANSLongest common substring problem: A longest common substring algorithm determines the longest common substring that exists in two inputs strings.DNA sequences can be represented using strings consisting of the letters A, C, G, and T to represent the four different nucleotides. computational problems and common algorithms: Navigation---Given a user's current location and desired location, what is the fastest route to walk to the destination? - ANSDijkstra's shortest path: Dijkstra's shortest path algorithm determines the shortest path from a start vertex to each vertex in a graph.The possible routes between two locations can be represented using a graph, where vertices represent specific locations and connecting edges specify the time required to walk between those two locations. data structure - ANSway of organizing, storing, and performing operations on data Do two student essays share a common phrase consisting of a sequence of more than 100 letters? - ANSlongest common substring. if the longest common substring between the two essays is greater than 100, then the two essays share a common phrase consisting of more than 100 letters. Ex: ADT- A list is a common ADT for holding ordered data, having operations like - ANSappend a data item, remove a data item, search whether a data item exists, and print the list.

Ex: The space complexity of an algorithm that duplicates a list of numbers is

  • ANSS(N) = 2N + k, where k is a constant representing memory used for things like the loop counter and list pointers. Example computational problems and common algorithms: Search engines-- Given a product ID and a sorted array of all in-stock products, is the product in stock and what is the product's price? - ANSBinary 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). 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 } a. What is the maximum possible size of the returned list? b. What is the minimum possible size of the returned list? c. What is the worst case auxiliary space complexity of GetEvens if N is the list's size and k is a constant? d. What is the best case auxiliary space complexity of GetEvens if N is the list's size and k is a constant? - ANSa.listSize----If all items in the input list were even, then the returned list would have the same size. b. 0---If the input list doesn't have any even numbers, then the returned list will be empty. c. 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. d. 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.

how is algorithm efficiency measured?? - ANSis most commonly measured by the algorithm runtime, and an efficient algorithm is one whose runtime increases no more than polynomially with respect to the input size. Inserting an item at the beginning of a 999-item array requires how many items to be shifted? - ANS999.Inserting at the beginning requires making room for the new item. So every current item must be shifted once. inserting an item at the beginning of a 999-item linked list requires how many items to be shifted? - ANS0. No shifting of other items is required, which is an advantage of using linked lists. Inserting an item at the end of a 999-item array OR linked list requires how many items to be shifted? - ANS0. Appending an item just places the new item at the end of the array. No shifting of existing items is necessary Items stored in an array can be accessed using a positional index. T/F - ANSarray elements are stored in sequential locations, so can be easily accessed using an index Knowledge of an ADT's underlying implementation is needed to analyze or impove the runtime efficiency. t/f - ANSt. Different ADTs' implementations may have different runtimes for various operations. Ex: Accessing the ith list element is more efficient in an array-based implementation than a linked list implementation. LinearSearch(numbers, numbersSize, key) { i = 0 while (i < numbersSize) { if (numbers[i] == key) return i i = i + 1 } return -1 // not found

numbers: 54 79 26 91 29 33 key= 26(neither best nor worst case) key=24: best case key = 82: worst case - ANS-The search for 26 is neither the best nor the worst case. -Searching for 54 only requires one comparison and is the best case: The key is found at the start of the array. No other search could perform fewer operations. -Searching for 82 compares against all array items and is the worst case: The number is not found in the array. No other search could perform more operation linked list - ANSA linked list is a data structure that stores an ordered list of items in nodes, where each node stores data and has a pointer to the next node. list (adt) - ANSitems are ordered based on how items are added. Duplicate items are allowed. Measuring runtime and memory usage allows - ANSdifferent algorithms to be compared.

Some algorithms utilize data structures to __________ during the algorithm execution. Ex: An algorithm that determines a list of the top five salespersons, may use an array to store salespersons sorted by their total sales. - ANSstore and organize data space complexity - ANSis a function, S(N), that represents the number of fixed-size memory units used by the algorithm for an input of size N. t/f A programmer must know the underlying implementation of the list ADT in order to use a list. - ANSf. A programmer need not have knowledge of the underlying implementation to use a list ADT. T/F: A linked list stores items in an unspecified order. - ANSF. A linked list stores an ordered list of items. The links in each node define the order in which items are stored. T/F: An algorithm with a polynomial runtime is considered efficient. True False - ANST. 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: The linear search algorithm's best case scenario is when N = 0. - ANSf: 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. the _____ ADT is the better match for the program's requirements. - ANSlist. The list ADT provides an abstraction that satisfies each program requirement, including iterating in reverse order, which the queue ADT doesn't provide.

The underlying data structure for a list data structure is the same for all programming languages. t/f - ANSf. The underlying data structures used to implement ADTs may vary between implementations. Some programming languages allow programmers to select a specific implementation. Ex: Java's list ADTs can be implemented using arrays or linked lists. Two different algorithms that produce the same result have the same computational complexity. True False - ANSF: Two different algorithms can produce the same result in various ways and may have different computational complexities. Using abstract data types enables programmers or algorithm designers to focus on _______, thus improving ________ - ANS-higher-level operations and algorithms. -programmer efficiency. What is the problem output? - ANSThe computational problem's question can be phrased as: How many times does the user-specified word appear on the list? The answer to that problem is an integer value for the frequency of the specified word. Which can be used as the problem input? - ANSThe input must include a list of all words and the specific word for which determining the frequency is desired. While common operations include inserting, removing, and searching for data, the algorithms to implement those operations are typically - ANSspecific to each data structure.