Midterm 1 Data Struct

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Appending node K to rentalList executes which of the following statements?

list->head = Newnode

ListAppend(callList, node 5) executes which statement?

list->tail->next = newNode

numsList: 3, 57, 28, 40 ListRemoveAfter(numsList, null)

57, 28, 40

how many times will the outer loop run to bubble sort the list 98,12,34,78,35,78,45

6

Given list (10, 20, 6, 14, 7), what will be the list after completing the second outer loop iteration (i = 2)? Type answer as: 1, 2, 3

6, 10, 20, 14, 7

For a function 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

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

false

Insertion sort is a fast sorting algorithm.

false

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

false

Calling ListSearch results in a minimum of _____ calls to ListSearchRecursive.

1

Given list (10, 11, 12, 13, 14, 15), how many comparisons will be made during the third outer loop execution (i = 3)?

1

Given list (9, 8, 7, 6, 5), how many swaps will occur during the first pass of the outer loop (i = 0)?

1

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

About how many times longer will sorting a list of 10X elements take compared to sorting a list of X elements?

100

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

1024

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

11

Given list (20, 14, 85, 3, 9), what value will be in the 0th element after the first pass over the outer loop (i = 1)?

14

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

2 us

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

20000

numsList: 23, 17, 8 ListInsertAfter(numsList, node 23, node 5)

23,5,17,8

Given list (1, 9, 17, 18, 2), how many swaps will occur during the outer loop execution (i = 4)?

3

42 is appended to an array-based list with allocationSize = 8 and length = 4. Appending assigns the array at index _____ with 42.

4

About how many times longer will sorting a list of 2X elements take compared to sorting a list of X elements?

4

At what index does the following statement insert the word "end"? Assume the first list element is located at index 0. Enter a number. wordsFromFile.push_back("end");

4

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

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

In the worst case, assuming each comparison takes 1 µs, how long will insertion sort algorithm take to sort a list of 10 elements?

45

Given list (10, 11, 12, 13, 14, 7), how many comparisons will be made during the final outer loop execution (i = 5)?

5

Given list (9, 8, 7, 6, 5), what value will be in the 0th element after the first pass over the outer loop (i = 0)?

5

Given the original list initialization above, how many elements does wordsFromFile contain after the following statement? wordsFromFile.push_front("fifth")

5

If Factorial(6) is called, how many additional calls are made to Factorial to compute the result of 720?

5

What is the list's length after 63 is appended?

5

Given list (5, 9, 8, 7, 6) and i = 1, what will be the list after completing the second outer loop iteration? Type answer as: 1, 2, 3

5,6,8,7,9

numsList: 5, 9 ListInsertAfter(numsList, node 9, node 4)

5,9,4

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

50

Given list (18, 23, 34, 75, 3), how many total comparisons will insertion sort require?

7

What is the list's allocation size after 63 is appended?

7

What are the list's contents after all operations have completed?

76,22,38,16,91

What is the list's allocation size after all operations have completed?

8

Which operation causes ArrayListResize to be called?

ArrayListAppend(list,42)

Which operation causes ArrayListResize to be called?

ArrayListInsertAfter(list,3,91)

A test harness involves temporarily modifying an existing program to test a particular function within that program. True or False?

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

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

71 and 99 will be placed into the same bucket.

FALSE

A linked list must have a list data structure.

FALSE

Calling quickselect with argument k equal to 1 returns the smallest element in the list.

FALSE

No bucket will have more than 1 number.

FALSE

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

FAlse

When using a range-based for loop, an iterator is used to traverse a list.

FAlse

A bounded stack's maximum length and initial allocation size are always equal.

False

Array-based stack implementations commonly reallocate when popping.

False

If a list ADT has operations lime sort or printreverse, the list is clearly implemented using an array.

False

ListInsertAfter(list, null, newNode) will insert newNode before the list's dummy node.

False

Only a doubly-linked list can be circular.

False

Suppose ReverseList is called on a list of size 3, a start index of 0, and an out-of-bounds end index of 3. The base case ensures that the function still properly reverses the list. True False

False

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

False

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

False

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

False. Testing all possible input values. Is simply not practical except for the most trivial functions. A function with just one integer parameter has over 4 billion possible input values.

Unit testing means to modify function inputs in small steps known as units. True or False?

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

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 tail

A fast sorting algorithm's worst case runtime complexity must be O(�����) or better.

false

Suppose dataList is a singly-linked list with a dummy node. Which statement removes the first item from the list?

ListRemoveAfter(dataList,dataList->head)

Suppose the following statement is executed:node19 = numbersList⇢head⇢next⇢nextWhich subsequent operations swap nodes 73 and 19?

ListRemoveAfter(numbersList,numbersList->head->next) ListPrepend(numbersList,node19)

What is the condition for the base case in the CumulativeSum function?

N equals 0

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

Shell sort

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

Singly-linked lists do not support backward traversal.

The following function produces the same result as quickselect, albeit with a different runtime complexity. Quickselect(numbers, first, last, k) { Quicksort(numbers, first, last) return numbers[k] }

TRue

Calling every function at least once is a prerequisite for 100% code coverage

True. If a test bench doesn't call a function that functions.

Which does not describe a base case for BinarySearch?

The list element at index mid is less than the key.

A bounded stack implementation may throw an exception if a push operation occurs when full.

True

A linked list has O(n) space complexity, whether a list data structure is used or not.

True

A list data structure can have additional information besides the head and tail pointers.

True

Given a list with items 'Z', 'A', 'B', Sort(list) yields 'A', 'B', 'Z'.

True

Given k = 4, if the quickselect call Partition(numbers, 0, 10) returns 4, then the element being selected is in the low partition.

True

If 10 buckets were used instead of 5, no bucket would have more than 1 number.

True

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

True

ListPrepend(list, newNode) is equivalent to ListInsertAfter(list, list⇢head, newNode).

True

ListRemove's implementation must not allow removal of the dummy node.

True

ListTraverseRecursive works for an empty list.

True

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

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 following code can be used to traverse a circular, doubly-linked list in reverse order. CircularListTraverseReverse(tail) { if (tail is not null) { current = tail do { visit current current = current⇢previous } while (current != tail) } }

True

The following code changes the values of all elements in authorList. for (string& authorName : authorList) { authorName = "Something"; }

True

Using assert() is a preferred way to test a function. True or False?

True, enables a concise test harness, and simplifies spotting a failed test vector in the programs output.

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

True. Border cases typically include large-magnitude values, and atypical inputs like 0.

A class should be tested individually (as a "unit") before use in another program

True. The user expects the class to work, and may not even be able to debug the class. Bugs would also be harder to find.

When does a push operation resize the stack's array?

When length == allocationSize

When list⇢head == list⇢tail is true in _____, the list is empty.

a list with 1 dummy node

list⇢head⇢next is always non-null in _____.

a list with 2 dummy nodes.

In theory, an unbounded stack can grow in length indefinitely. In reality, the stack can _____.

grow only until the resize operation fails to allocate memory.

given a list(0,1,1,2,3,5,8,13,17) the binary search algorithm calls BinarySearch(list, 0, 8,) What will the low and high argument values be for the second recursive call?

low = 5 , high =8

If myList is a singly-linked list with a dummy node, which statement is true when the list is empty?

myList->head == myList->tail

list⇢tail may be null in _____.

neither list type that has a dummy node(s)

Suppose dataList is a singly-linked list with a dummy node. Which is a requirement of the ListPrepend function?

newNode is not NULL

ListPrepend(earningsList, node 977) executes which statement?

newNode->next = list->head

When the key is not found, ListSearch returns _____.

null

Given the original list initialization above, write a statement to add the word "The" before the element "fowl". wordsFromFile.

push_front("The")

Which fast sorting algorithm's worst case runtime complexity is worse than O(�����)?

quicksorts

When more than 1 of the list's nodes contains the search key, ListSearch returns _____ node containing the key.

the first

Radix sort is a fast sorting algorithm.

true

The fastest average runtime complexity of a comparison sorting algorithm is O(�����).

true

merge sort is a fast sorting algorithm

true

selection sort can be used to sort an array of strings

true

Given the list(xlsx,xls,xlr,txt,ods) what is the order of the elements after completing sorts second outer loop iteration?

xlr,xls,xlsx,txt,ods


संबंधित स्टडी सेट्स

biol 1002 fungi and protists exam 2

View Set

Anatomy: Intrinsic muscles of the back

View Set

the first 20 element of the periodic table

View Set

Microbiology Exam 1 - Ch. 1, 3, 4, 10, 12

View Set