Intro to data structures and algorithms

Ace your homework & exams now with Quizwiz!

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 Which is Best, Worst, or neither Key = 26 Key= 54 Key = 82

26 is neither best nor worst 54 is best 82 is worst

FindMax(inputArray) { max = inputArray[0] for (i = 1; i < inputArray.size; ++i) { if (inputArray[i] > max) { max = inputArray[i] } } return max } What will return from this array of integers? 13, 7, 45,-3,92,17

92 because it's the max number

Using that same code from question 18: To adapt the algorithm to display the top 10 salesperson, what modifications are required? A) only the array creation B) all loops in the algorithm C) Both the creation and loops

A only the array creation

The _____ ADT is the better match for the program's requirements. A) queue B) list C) A and B

B list

DisplayTopFiveSalespersons(allSalespersons) { topSales = Create array with 5 elements // Initialize all array elements with a negative sales total for (i = 0; i < topSales⇢length; ++i) { topSales[i]⇢name = "" topSales[i]⇢salesTotal = -1 } for each salesPerson in allSalespersons { if (salesPerson⇢salesTotal > topSales[topSales⇢length - 1]⇢salesTotal) { topSales[topSales⇢length - 1]⇢name = salesPerson⇢name topSales[topSales⇢length - 1]⇢salesTotal = salesPerson⇢salesTotal SortDescending(topSales) } } // Display the top five salespersons for (i = 0; i < topSales⇢length; ++i) { Display topSales[i] } } Which of the following is not equal to the number of items in the topSales array? A) topSales--->length B) 5 C) allSalesperson--->length

C allSalesperson--->length

The list ADT _____. A) Can be implemented using an array B) Can be implemented using a linked list C) Can be implemented in numerous ways

C can be implemented in numerous ways

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

False

A list ADT's underlying data structure has no impact on the program's execution. True or False

False

A programmer must know the underlying implementation of the list ADT in order to use a list. True or False

False

ADTs are only supported in standard libraries. True or False

False

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

False

An efficient algorithm exists for all computational problems. True or False

False

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

False

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

False

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

False

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

False

What are the most common resources considered?

Runtime and Memory Usage

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

True

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

True

An algorithm with a polynomial runtime is considered efficient. True or False

True

An efficient algorithm to solve an NP-complete problem may exist True or False

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

Knowledge of an ADT's underlying implementation is needed to analyze the runtime efficiency. True or False

True

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

True

Use code on question 18: If allSalespersons only contains three elements, the DisplayTopFiveSalespersons algorithm will display elements with no name and negative sales. True or False

True

NP-complete

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

algorithm

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

Binary tree

is a data structure in which each node stores data and has up to two children, known as a left child and a right child.

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.

Array

is a data structure that stores an ordered list of items, where each item is directly accessible by a positional index.

Hash Table

is a data structure that stores unordered items by mapping (or hashing) each item to a location in an array.

abstract data type (ADT)

is a data type described by predefined user operations, such as "insert data at rear," without indicating how each operation is implemented.

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.

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.

Data Structure

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

Set

is an ADT for a collection of distinct items.

Dynamic Array

is an ADT for holding ordered data and allowing indexed access.

List

is an ADT for holding ordered data.

Queue

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

Stack

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

Computational complexity

is the amount of resources used by the algorithm.

Record

is the data structure that stores subitems, often called fields, with a name associated with each subitem.

worst case

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

best case

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

auxiliary space complexity

is the space complexity not including the input data.

Algorithm efficiency

is typically measured by the algorithm's computational complexity.

Bag

s an ADT for storing items in which the order does not matter and duplicate items are allowed.

computational problem

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


Related study sets

Exam #3 MKT 305 (Chapters 11-14)

View Set

delmars Post traumatic stress disorders

View Set

MSM 6650 - Strategic Management, MSM 6650 Combined

View Set

Earth Science Chapter 3 - Rocks and their origins

View Set

Energy Balance and Body Composition

View Set

Google Project Management Coursera

View Set

AGB 144 Sudbrock Modules 8-14 Quizzes

View Set