Chapter 23

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Suppose a heap is stored in an array list as follows: {100, 55, 92, 23, 33, 81}. The parent of 81 is

92

Which of the following statements are true? A. A heap is a complete binary tree. B. Each node is greater than or equal to any of its children. C. A binary tree is complete if every level of the tree is full except that the last level may not be full and all the leaves on the last level are placed left-most. D. A heap is a full binary tree.

A. A heap is a complete binary tree. B. Each node is greater than or equal to any of its children. C. A binary tree is complete if every level of the tree is full except that the last level may not be full and all the leaves on the last level are placed left-most.

The best-time complexity for bubble sort is

O(n)

Finds the smallest number in the list and swaps it with the first element. It then finds the smallest number remaining and swaps it with the second element, and so on, until only a single number remains.

Selection sort

To add a new node, you need to start a process by first placing it as _______ and move it up to maintain the heap property.

the last node in the heap

To remove the root, you need to start a process by first placing _______ to the place of the root and move it down to maintain the heap property.

the last node in the heap

Suppose a heap is stored in an array list as follows: {100, 55, 92, 23, 33, 81}. After inserting 103, what is the content of the array list?

{103, 55, 100, 23, 33, 81, 92}

Using the partition algorithm to partition an array {5, 8, 10, 3, 4, 19, 2} for a quick sort, what is the resulting array after the partition?

{3, 2, 4, 5, 10, 19, 8}

The average-time complexity for heap sort is

O(nlogn)

The best-time complexity for insertion sort is

O(n)

The time to merge two sorted lists of size n is

O(n)

Based on the bucket sort, but only uses ten buckets

Radix sort

Length of the longest path from the root to a leaf node.

height of a heap

The average-case and worst-case complexity for a merge sort. Average time for a quick sort.

O(nlogn)

The average-time complexity for quick sort is

O(nlogn)

The worst-time complexity for heap sort is

O(nlogn)

The worst-time complexity for merge sort is

O(nlogn)

Works as follows: The algorithm selects an element, called the pivot, in the array. It divides the array into two parts, so that all the elements in the first part are less than or equal to the pivot and all the elements in the second part are greater than the pivot. The algorithm is then recursively applied to the first part and then the second part.

Quick sort

Suppose a list is {2, 9, 5, 4, 8, 1}. After the first pass of bubble sort, the list becomes

2, 5, 4, 8, 1, 9

Suppose you choose the first element as a pivot in the list {5 2 9 3 8 4 0 1 6 7}. Using the partition algorithm in the book, what is the new list after the partition?

4 2 1 3 0 5 8 9 6 7

Can be described recursively as follows: The algorithm divides the array into two halves and applies a merge sort on each half recursively. After the two halves are sorted, merge them.

Merge sort

Height of a heap containing a single element

0

Sorts the array in multiple phases. Each pass successively swaps the neighboring elements if the elements are not in order.

Bubble sort

Sorts the elements by distributing the elements into a sequence of buckets and then collects the elements from the buckets.

Bucket sort

What is correct about a pivot? A. A pivot divides a list into two sublists of equal size. B. A pivot can be chosen arbitrarily. C. A pivot divides a list into two sublists, the elements in the first list are no larger than the pivot and the elements in the second list are larger than the pivot. D. You should always choose a pivot that divides the list evenly.

B. A pivot can be chosen arbitrarily. C. A pivot divides a list into two sublists, the elements in the first list are no larger

Each of its levels is full, except that the last level may not be full and all the leaves on the last level are placed leftmost.

Complete binary tree

Sort data stored in an external file.

External sort

Uses a binary heap. First adds all the elements to a heap and then removes the largest elements successively to obtain a sorted list.

Heap sort

Sorts a list of values by repeatedly inserting a new element into a sorted sublist until the whole list is sorted.

Insertion sort

The average-time complexity for merge sort is

O(n*n)

The worst-case complexity for a selection sort, insertion sort, bubble sort, and quick sort

O(n*n)

The worst-time complexity for bubble sort is

O(n*n)

The worst-time complexity for insertion sort is

O(n*n)

The worst-time complexity for quick sort is

O(n*n)

Best time complexity for heap sort

O(nlogn)


Kaugnay na mga set ng pag-aaral

Chapter 64 - Nursing Management: Musculoskeletal Problems

View Set

Integrated Business Policy and Strategy - Exam 2

View Set

REG - ESTIMATED TAXES - Individual and Corporations

View Set

Ethics and Social Responsibility

View Set

Algebra I - Unit 1: Foundations of Algebra Quiz 2: The Real Numbers

View Set

FL Computations and Closing of Transactions

View Set

Chapter 22) 12&13 Seminal Vesicle and Prostate Gland

View Set