Data Structures Final

Ace your homework & exams now with Quizwiz!

Sort the following sequence using insertion sort. Show the state of the sequence after each item is placed. 5 2 1 6 3

5 2 1 6 3 2 5 1 6 3 1 2 5 6 3 1 2 5 6 3 1 2 3 5 6

Would you use the adjacency list structure or adjacency matrix structure if your graph has 10,000 vertices and 20,000 edges and it is important to use as little space as possible.

Adjacency List

Would you use the adjacency list structure or adjacency matrix structure if you need to find out if two vertices are adjacent as quickly as possible, no matter how much space you use.

Adjacency Matrix

Checks every possible solution.

Brute Force

The only way to get the optimal solution for NP problems.

Brute Force Algorithms

Swaps neighboring items.

Bubble Sort

Solved using recursion.

Divide and Conquer Algorithms

Splits the problem into smaller parts then recursively solves the smaller versions.

Divide and Conquer Algorithms

Solves the problem in steps starting at the lowest step and building up.

Dynamic Programming

The following recurrence relation used to solve a problem is indicative of what type of algorithm? S(i, W) = max( S(i-1, W) , S(i-1, W-wi + vi)

Dynamic Programming

Uses a table.

Dynamic Programming

Solves the problem in steps and takes the optimum at each step.

Greedy Algorithms

Places items in a sorted region.

Insertion Sort

Splits the array into halves and sorts each half.

Merge Sort

What does NP stand for?

Non-deterministic Polynomial

What is the computational complexity of adding an item to a queue?

O(1)

What is the computational complexity of removing an item from a Stack?

O(1)

What is the computational complexity of the following code snippet result = 0 for (i=0; i<10; i++) { for (j=0; j<i; j++) { result += i*j; } }

O(1)

What is the computational complexity of adding an element to a min-heap?

O(log n)

What is the computational complexity of binary search?

O(log n)

What is the computational complexity of removing an item from a min-heap?

O(log n)

What is the computational complexity of sorting an array of items using quick sort in the average case?

O(n log n)

What is the computational complexity of the following code snippet: int sum = 0; for (int i=0; i<n ; i=i+1) { for (int j=1; j<n; j=j*2) { sum = sum+i*j } }

O(n log n)

What is the computational complexity of sorting an array of items using bubble sort in the best case?

O(n)

What is the computational complexity of sorting an array of items using insertion sort in the best case?

O(n)

What is the computational complexity of the following code snippet total = 0 for (i=0; i<10; i++) { for (m=0; m<n; m++) { total += m*5; } }

O(n)

What is the computational complexity of the recursive factorial method?

O(n)

What is the computational complexity of sorting an array of items using quick sort in the worst case?

O(n^2)

What is the computational complexity of sorting an array of numbers using bubble sort in the average case?

O(n^2)

What is the computational complexity of sorting an array of numbers using selection sort in the average case?

O(n^2)

What is the computational complexity of the following code snippet result = 0 for (i=0; i<n; i++) { for (j=0; j<i; j++) { result += i*j; } }

O(n^2)

Partitions the array around a pivot.

Quick Sort

This sort is a divide and conquer sort that is not guaranteed to be O(n log n).

Quick Sort

Sorts according to least significant digit, then second least, and so on.

Radix Sort

Finds smallest element and puts in lowest index, then puts second smallest in the second index, and so on.

Selection Sort

Sorts relative to a gap.

Shell Sort

This sort is an improvement on insertion sort that sorts relative to deceasing gap sizes.

Shell Sort

This array represents a min-heap. (The blank represents the empty spot at index 0). blank, 1, 10, 3, 11, 12, 4 What is the array representation after an item is removed from the heap?

blank, 3, 10, 4, 11, 12

O(1) indicates that an algorithm operates in ________ time.

constant


Related study sets

Give Me Liberty: Chapter 15 REVIEW QUIZ 1

View Set

Chapter 2: Livestock Safety and Restraint

View Set

Chapter 2- Legal and Ethical Aspects of Nursing

View Set