Data Structures Exam 2 - SR Study Questions

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

insertion sort

The __________________ algorithm sorts a list of values by repetitively inserting a particular value into a subset of the list that has already been sorted.

bubble sort

The ___________________ algorithm sorts values by repeatedly comparing neighboring elements in the list and swapping their position if the are not in order relative to each other.

growth function

The ___________________ of an algorithm shows the relationship between the size of the problem and the value we hope to optimize.

Tower of Hanoi

The _______________________ puzzle is a favorite of computer scientists because of its elegant recursive solution.

True

The average case run-time of the Quicksort algorithm is n * log(n) While the average run-time of the Bubblesort algorithm is n^2

Insertion Sort

The following algorithm denotes ...... function X (array A) for i from 1 to length[A]-1 do value := A[i] j := i-1 while j >= 0 and A[j] > value do A[j+1] := A[j] j := j-1 done A[j+1] = value done

two

The insertionSort method uses ________ loop(s) to sort an array of objects.

exponential

The recursive solution of the Towers of Hanoi problem has _______________ complexity.

True

The selection sort algorithm sorts a list of values by repeatedly putting a particular value into its final, sorted position.

False. The worst-case run-time of Quicksort algorithm is O(n^2) and the worst-case run-time of Bubblesort algorithm is O(n^2)

The worst-case run-time of Quicksort algorithm is O(n) and the worst-case run-time of Bubblesort algorithm is O(n^2)

2

There is(are) ____________ base case(s) in the recursive solution to finding a path through a maze.

it is assumed that the search pool is ordered.

it is assumed that the search pool is ordered.

True

All recursive methods must have a base case.

False. Explanation: There may be several different algorithms for a problem with the same efficiency, but there may be more efficient or less efficient solutions for the same problem.

Every algorithm for a problem has the same efficiency.

binary

A _______________ search is more efficient than a linear search.

linear

A __________________ search looks through the search pool one element at a time.

False. Explanation: If the element that is being searched for is the first element in the list, then a linear search would require less comparisons than a binary search.

A linear search always requires more comparisons than a binary search.

False. Explanation: A binary search is more efficient, but it requires that the search pool be ordered.

A linear search is more efficient than a binary search.

False. Explanation: A program with infinite recursion will run out of memory. This will cause the program to crash. A program with an infinite loop will appear to "hang."

A program with infinite recursion will act similarly to a program with an infinite loop.

increases

As the number of items in a search pool grows, the number of comparisons required to search _______________ .

True

Bubble sort is worst than quick sort.

False. Explanation: Bubble sort is not a recursive sort - the sort described is Merge sort.

Bubble sort works by separating a list into two lists, recursively sorting the two lists using bubble sort, and then combining the sorted sublists into a sorted list.

True

Determining whether or not there is a path through a maze has a recursive solution.

False. Explanation: In the Towers of Hanoi puzzle, the only valid moves move a disk to a peg that only contains smaller disks.

In the Towers of Hanoi puzzle, it is legal to move a larger disk to a peg that already contains a smaller disk.

True

Insertion and Selection sort algorithms are considered sequential sorts.

True

Insertion sort is of order n2

True

Quick sort works by separating a list into two lists, and recursively sorting the two lists using quick sort.

Explanation: Recursion is not necessary, since it is always possible to program a recursive solution iteratively.

Recursion is necessary.

False. Explanation: There are some cases where the iterative solution is much less complex and more straight forward to code. In these cases, recursion is not the best choice.

Recursive solutions to problems should be used whenever possible.

n2

Selection sort is of order

False. Explanation: Since it is possible to simulate recursion using an iterative program, any problem that can be solved recursively can also be solved iteratively.

Some problems can only be solved recursively.

O(1)

Suppose we have algorithms that solve a particular problem that have the following complexities. Which one is most efficient?

The program will run out of memory.

What is the result from infinite recursion in Java?

merge sort

Which algorithm has a worst case complexity of O(n log2n)?

quick sort

Which algorithm is most easily expressed recursively?

binary search

Which algorithms has a time complexity of O(log2 n)?

insertion, selection, and bubble sort

Which algorithms has a worst-case complexity of O(n^2)?

True

With each comparison, a binary search eliminates approximately half of the items remaining in the search pool.

Infinite

__________________ recursion results from the lack of a base case.

Sorting

____________________ is the process of arranging a group of items into a defined order.

direct, indirect

____________________ recursion occurs when a method calls itself, while _________________ recursion when a method calls another method that then calls the original method.

Searching

_____________________ is the process of finding a designated target element within a group of items.


Set pelajaran terkait

AP Human Geography Cumulative Review

View Set

WW1 Unit Test, WWI History Test Notes, Historical Concepts

View Set