4 Lists, Stacks, and Queues, data structures

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

What is the correct sequence for inserting an item in a linked list?

1. Create a list node for a new item. 2. Assign a pointer of the new item to point to the next item. 3. Update the pointer of the previous node to point to the new node.

Insertion sort requires at most _____ swaps to sort a list of 20 elements.

190

The upper bound of an algorithm with best case runtime T(N)=3N+16 and worst case runtime T(N)=4N2+10N+5 is _____.

19N2

Given the following list of sorted elements, how many elements of the list will be checked to find 25 using binary search? {12, 13, 15, 20, 23, 24, 25, 36, 40}

2

Given a list (0, 1, 1, 2, 3, 5, 8, 13, 17), the binary search algorithm calls BinarySearch(list, 0, 8, 3). What is the index of the middle element?

4

Assume a full BST of height 8, how many nodes are in the tree?

511

A list of 10 elements is to be sorted using insertion sort algorithm. How many times will the outer loop be executed?

9

Which abstract data type (ADT) is most suitable to store a list of perishable products such that the product with the nearest expiry date is removed first?

A priority queue

Which of the following is best represented by a graph?

A telephone network

Which is not a characteristic of an NP-complete problem?

All NP-complete problems can be solved efficiently.

Which of the following is correct for a list ADT?

An element can be found and removed from the end of the list.

Given the list (75, 76, 68), identify the commands for the following operations. Insert item 80 at the end of the list Remove item 68 Insert item 82 at the end of the list Get the total number of items in the list Append(list, 80) Append(list, 82) Remove(list, 68) GetLength(list) Append(list, 80) Remove(list, 68) Append(list, 82) GetLength(list) Append(list, 80, 82) Remove(list, 68) GetList(list) Append(list, 80) Insert(list, 82) Remove(list, 68) GetItem(list)

Append(list, 80) Remove(list, 68) Append(list, 82) GetLength(list)

Which of the following is not an example of sorting a list?

Arranging student records neatly on a desk

True or false? Most of the time, a C++ recursive algorithm will perform more efficiently (i.e. - run faster) than a C++ iterative algorithm.

False

Which problem below would use a double recursion strategy? Euclid's Highest Common Factor Factorial Compute Sum 1 to N Fibonacci

Fibonacci

Given the list (11, 22, 25), which is the correct way to add 32 to the list in ascending order? InsertAfter(list, 25, 32) InsertAfter(list, 32) Prepend(list, 32, 25) Prepend(list, 32)

InsertAfter(list, 25, 32)

Identify the commands for the following list operations. Check that there are no items in a list Insert 10, 50, 30, 40, and 20 at the end of the list Arrange the items in ascending order IsEmpty(list) Prepend(list, 10) Prepend(list, 50) Prepend(list, 30) Prepend(list, 40) Prepend(list, 20) Sort(list) Search(list) Append(list, 10) Append(list, 50) Append(list, 30) Append(list, 40) Append(list, 20) Sort(list) IsEmpty(list) Append(list, 10) Append(list, 50) Append(list, 30) Append(list, 40) Append(list, 20) GetLength(list) IsEmpty(list) Append(list, 10) Append(list, 50) Append(list, 30) Append(list, 40) Append(list, 20) Sort(list)

IsEmpty(list) Append(list, 10) Append(list, 50) Append(list, 30) Append(list, 40) Append(list, 20) Sort(list)

Which of the following rules does a valid BST follow? Left subtree keys ≥ node's keys Left subtree keys ≤ node's keys Right subtree keys ≤ node's keys Right subtree keys ≤ left subtree keys

Left subtree keys ≤ node's keys

Which of the following statements is true with reference to searching?

Linear search will compare all elements if the search key is not present.

Identify the correct way to insert 52 at the end of the following list: 12, 24, 36, 48. ListPrepend(list, node 52) InsertAfter(list, node 52) ListInsert (tail, node 52) ListAppend(list, node 52)

ListAppend(list, node 52) As ListPrepend as the name suggests it will insert 52 as start. And ListInsert will insert at the tail means in place of 48. and InsertAfter has the wrong syntax.

If myList is initially empty, what sequence of operations creates the list (75, 76, 68)? ListAppend(myList, node 75) ListAppend(myList, node 76) ListAppend(myList, node 68) ListPrepend(myList, node 75) ListPrepend(myList, node 76) ListPrepend(myList, node 68) ListPrepend(myList, node 75) ListInsert(myList, node 76) ListInsert(myList, node 68) ListInsert(myList, node 75) ListAppend(myList, node 76) ListAppend(myList, node 68)

ListAppend(myList, node 75) ListAppend(myList, node 76) ListAppend(myList, node 68)

Given the singly-linked list (11, 33, 44, 66), identify the commands for inserting 22 and 55, such that the final list is (11, 22, 33, 44, 55, 66). ListInsertAfter(list, node 11, node 22) ListInsertAfter(list, node 44, node 55) ListInsertAfter(list, node 0, node 22) ListInsertAfter(list, node 3, node 55) ListInsertAfter(list, node 11, node 22, node 55) ListInsertAfter(list, node 22) ListInsertAfter(list, node 55)

ListInsertAfter(list, node 11, node 22) ListInsertAfter(list, node 44, node 55)

Which is the correct code to prepend an item to a list? ListPrepend(list,newNode){if(list⇢head==null){list⇢head=newNodelist⇢tail=newNode}else{list⇢head⇢next=newNodelist⇢head=newNode}} ListPrepend(list,newNode){if(list⇢head==null){list⇢head=newNodelist⇢tail=newNode}else{newNode⇢next=list⇢taillist⇢tail=newNode}} ListPrepend(list,newNode){if(list⇢head==null){list⇢head=newNodelist⇢tail=newNode}else{newNode⇢next=list⇢headlist⇢head=newNode}} ListPrepend(list, newNode) { if (list⇢head == null) { list⇢head = newNode list⇢tail = newNode } else { list⇢tail⇢next = newNode list⇢tail = newNode } }

ListPrepend(list,newNode){if(list⇢head==null){list⇢head=newNodelist⇢tail=newNode}else{newNode⇢next=list⇢headlist⇢head=newNode}} 4.2.5: Singly-linked list: Prepending a node.

Which algorithm is best suited for a plagiarism check?

Longest common substring

Which of the following is the fastest algorithm to sort a string?

Merge sort

Which of the following is an example of a recursive function?

MySalaryCalulator(tempSal) { if (tempSal <= 500) return -1 else MySalaryCalculator(tempSal - 500) }

The Big O notation of the algorithm 7+12N+3N2 is _____.

N^2

An algorithm is written to return the first name beginning with "L" in a list of employee names. Which of the following is the algorithm's worst case scenario?

No names in the list begin with "L."

The best case runtime complexity of an algorithm that searches an array of size N is _____.

O(1)

What is the Big O notation for a recursive function with a runtime complexity of T(N)=5N+T(N−1)?

O(N^2)

What is the Big O notation for the following algorithm?

O(N^2)

In a linked list, each node stores a _____ the next node.

Pointer to

Given the list (24, 36, 48), which is the correct way to add 12 at the start of the list? Append(list, 12) Prepend(list, 12) InsertBefore(list, 12) Append(list, 0, 12)

Prepend(list, 12)

Given the list (40, 42, 45, 46, 47), identify the commands for the following operations. Remove 45 Confirm that 45 is removed Remove(list, 45) IsEmpty(list, 45) Delete(list, 45) Search(list, 45) Remove(list, 45) Search(list, 45) Remove(list, 45) Sort(list, 45)

Remove(list, 45) Search(list, 45)

For the list {Allen, Barry, Christopher, Daisy, Garry, Sandy, Zac}, what is the second name searched when the list is searched for Garry using binary search?

Sandy

_____ sort is a sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly picks the proper next value to move from the unsorted part to the end of the sorted part.

Selection

Which is not true for a linear search algorithm?

The algorithm starts at the end of the list.

Which of the following statements is correct?

The list ADT supports the printing of the list contents but the queue ADT does not.

Which of the following is the main requirement for a binary search algorithm?

The list must be sorted in ascending order.

In a computational problem for finding the highest salary of an employee in a company, what is the input?

The list of employees' salaries

What happens when a leaf node is removed?

The parent's left or right child node becomes null

Given the singly-linked list (88, 99), which node will be removed by the ListRemoveAfter(list, node 88) command? The head node The tail node No node will be removed. The list will be removed.

The tail node 88 99, and 88 is head and 99 is tail so, after node 88 is node 99

True or false? Run-time stack is the name of the structure, created by the operating system, that stores local variable data, function parameter values, and returning function values of a running program.

True

When is a new node inserted as the left child?

When the new node's key is less than the current node and the current node's left child is null

What values are stored in the list numList?

[0, 2, 4, 6, 8]

Which abstract data type (ADT) is suited to check whether a given string is a palindrome?

a deque

Which abstract data type (ADT) is best suited to store the names of all currently available smartphone models?

a set

The process of providing only the essentials and hiding the details is known as _____.

abstraction

In the ListInsertAfter function for singly-linked lists, the curNode parameter points to _____ node. the head the tail any existing the middle

any existing

An algorithm's _____ is the scenario where the algorithm does the minimum possible number of operations.

best case

Name a type of binary tree which has the maximum number of nodes on every level except the last, and on this last level, the nodes occur exactly from left to right.

complete

Which function best represents the number of operations in the worst-case? for (i = 0; i < N; ++i) { if (numbers[i] % 2 == 1) factor = 2.5 }

f(N)=5N+2

Which XXX will complete the algorithm to separate numberList into two lists (even and odd) using an array? SCREENSHOT OF CODE

if (numberList[i] % 2 == 0)

Which XXX base case completes the algorithm to count the number of occurrences of a value in a list of numbers? SCREENSHOT OF CODE

if (startIndex >= numbersLength) return 0

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

low = 5, high = 8

Which XXX completes the following algorithm for inserting a new node into a singly-linked list? ListInsertAfter(list, curNode, newNode) { if (list⇢head == null) { list⇢head = newNode list⇢tail = newNode } else if (curNode == list⇢tail) { list⇢tail⇢next = newNode list⇢tail = newNode } else { XXX } } newNode⇢next = curNode⇢next curNode⇢next = null newNode⇢next = null curNode⇢next = list⇢tail⇢next newNode⇢next = curNode⇢next curNode⇢next = newNode newNode⇢next = curNode⇢next curNode⇢next = newNode

newNode⇢next = curNode⇢next curNode⇢next = newNode 4.3.1: Singly-linked list: Insert nodes.

find_if()'s notation is find_if(iteratorFirst, iteratorLast, boolFunction). find_if() passes elements to boolFunction _____.

one-by-one

the list's head pointer In a singly-linked list with 1 element, the tail pointer ____ and the next pointer of the head node ____. points to the last node, points to the first node is null, is null is null, points to the head node points to the head node, is null

points to the head node, is null

A _______________ traversal would be used if you needed to save the contents of a BST on file with the same shape. This type of traversal would also be used if you wanted to make an exact copy of a BST.

pre-order

Which data type is best suited to store the names and grades of students?

record

A(n) _____ is a function f(N) that is defined in terms of the same function and operates on a value less than N.

recurrence relation

Appending an element in an array involves increasing the array's _____.

size

Which XXX sorts animalVec in ascending order? vector<string> animalVec; animalVec.push_back("bat"); animalVec.push_back("ant"); animalVec.push_back("dog"); animalVec.push_back("goat"); animalVec.push_back("cat"); XXX;

sort(animalVec.begin(), animalVec.end())

In a recursive function, the base case _____ the function.

terminates

In the ListInsertAfter function for singly-linked lists, the curNode parameter is ignored when _____. the list's head and tail pointers point to different nodes the newNode argument is also null the list has more than 2 items the list's head pointer is null

the list's head pointer is null

During sorting the algorithm swaps _____.

two elements at a time

Which XXX completes the following insertion sort algorithm to sort in descending order? SCREENSHOT OF CODE

while(j > 0 && numbers[j] > numbers[j-1])

In selection sort, the smallest element is selected and swapped with the _____ unsorted element.

leftmost

A stack abstract data type (ADT) is implemented using a(n) _____ data

linked list

A stack abstract data type (ADT) is implemented using a(n) _____ data structure.

linked list

A recursive function calls _____.

itself

Given the list (-45, 35, -32, 67, -89, 23, -11), what will be the final sorted list?

(-89, -45, -32, -11, 23, 35, 67)

Given the list (20, -35, 50, -52, 65, -53), what is the list after sorting by the 1's digit?

(20, 50, -52, -53, -35, 65)

What is the height of a BST built by inserting nodes in the order 20, 10, 30?

1

How many additional recursive partitioning levels are required for a list of 64 elements compared to a list of 8 elements?

3

What is the height of a BST built by inserting nodes in the order 12, 24, 23, 48, 47?

3

Given the list (7, 23, 12, 8, 5, 6), what is the order of the elements after the third insertion sort swap?

7, 8, 12, 23, 5, 6

Which of the following lists is sorted?

89, 79, 63, 22

Which is an abstract data type (ADT)?

A list

A manufacturing plant has many ways to assemble a product. Which algorithm will be useful to find the quickest way?

Dijkstra's shortest path

Which of the following statements is correct?

Every data structure has a specific algorithm to implement a certain operation.

Identify the correct way to remove 18 from the singly-linked list (18, 20, 22, 24). ListRemoveAfter(list, 18) ListRemoveAfter(list, node 0) ListRemoveAfter(list, node 18) ListRemoveAfter(list, null)

ListRemoveAfter(list, null) Null as there no node 84 in the list so, it will return Null.

ADTs allow programmers to _____.

focus on higher-level operations as per a program's needs

Given the following code for generating the Fibonacci series for N numbers, which XXX would replace the missing statement? FibonacciNumber(N) { XXX return 0 else if (N == 1) return 1 else return FibonacciNumber(N - 1) + FibonacciNumber(N - 2) }

if (N == 0)

Sorting algorithms ______ elements in a list, comparing their values to sort.

swap


Set pelajaran terkait

General psychology final pt 2 - 1

View Set

Sanskrit Terms- Asian Philosophy

View Set

Chapter 27 AP Euro, AP Euro Chapter 29, AP Euro Chapter 27

View Set