Chapter 8: Algorithmic Analysis, Sorting & Searching__DNS_Copy

Ace your homework & exams now with Quizwiz!

When it comes to an insertion sort, what does the following really mean? 1. The processing time for an algorithm is constant 2. The processing time for an algorithm is linear 3. The processing time for an algorithm is proportional to system resources 4. The processing time for an algorithm is proportional to the square of the data set

0(N^2) The processing time for an algorithm is proportional to the square of the data set

When we declare a two-dimensional array 10 by 5 of data type 4 bytes long, how much memory will be allocated? a. 200 bytes b. 616 bytes c. 336 bytes d. 216 bytes

336 bytes

If we declare an array of 12 elects and data type of 2 bytes each, how much memory will be allocated? a. 40 bytes b. 36 bytes c. 24 bytes d. 12 bytes

40 bytes

Consider the array [12, 23, 29, 34, 45, 55, 56, 67, 89]. What will be the index of the target value 56 using binary search algorithm?

6

What is missing from the following recursive binary search method? public static int recursiveBinarySearch(int sortedArray, int start, int end, int key) { int mid = start + (start - end) / 2; if(key < sortedArray[mid]) { return recursiveBinarySearch(sortedArray, start, mid, key); } else if (key > sortedArray[mid]) { return recursiveBinarySearch(sortedArray, mid+1, end, key); } else { return mid; } return - (start = 1); }

A check to see if the whole array has been searched.

Bubble sort compares _____ elements of an array at a time.

Two

A binary search algorithm works on the principle of _______?

divide and conquer

Bubble sort uses a ________ for- loop structure?

double

In a linear function, the time taken is _____ if the size of the input is doubled. 1. O log n 2. constant 3. doubled 4. nn

doubled

What type of sort is Quick sort?

exchange

What is Range sorting?

It's used when you only need some part of an array sorted.

How many times will the outer for loop be exe turned? int mySimpleArray [] ={1,4,7,5,19,3,11,4,22,8,2,21}; int temp = 0; int n = mySimpleArray.length; for (int i = 0; i < n-1; i++) { for (int j = 0; j < n-i-1; j++) { if (mySimpleArray[j] > mySimpleArray[j+1]) { int temp = mySimpleArray[j]; mySimpleArray[j] = mySimpleArray[j+1]; mySimpleArray[j+1] = temp; } } }

11

If we declare a two-dimensional array of size 5 by 5 and the data type stored is 4 byes long, how much memory will be allocated? a. 100 bytes b. 120 bytes c. 192 bytes d. 128 bytes

192 bytes

For a given array [32.44.12.15], the number of iterations performed using selection sort algorithm are?

3

What is space complexity?

Amount of storage an algorithm needs to work

Given the following array, what step is required first before calling the binary search function? Int[] scores = {15, 10, 9, 30, 105} ;

Arrays.sort(scores);

If f(n) is the function then O(f(n)) = { g(n) : there exists c> 0 and n0 such that f(n) <= c.g(n) for all n> n0. } is true for which of the following symbiotic notions? 1. Theta 2. Big Q 3. Big Oh 4. Omega

Big Oh 1. Measures the upper bound (worst case or maximum time) 2. For an algorithm represented by f(n) where n is the input size, O(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all n > n0. }, where g(n) is the upper bound calculated.

A merge sort?

Dives an unsorted array into 2 subarrays of equal size.

What is merge sort based on?

Divide and conquer paradigm

What is the requirement for an internal sort?

Enough memory to hold all the data.

A two-dimensional java array is allocated all as a single block of memory?

False

What does the binarySearch method allow us to do?

Find the position of the item we're looking for in the array

How does insertion-Sort work?

Finding if each item is in the right position of the array according to the criteria.

What is one major drawback of experimental analysis? 1. Lacks practicality, as it is theoretical 2. Implementation of programs 3. Calculation based 4. Too many outcomes

Implementation of programs

Which of the following is a benefit of a binary search?

Increased performance

All the operations on the array have good performance expect? 1. Declaring an array 2. Increasing array size 3. Assigning a value to an element 4. Accessing array

Increasing array size

Why is the Quick Sort considered one of the most efficient sorting algorithms?

It has an average performance of O(n log n)

What is the advanced of selection sort?

It requires no additional memory for operation.

Which is the java library that will help you accesss more tools to manipulate and sort arrays?

Java.until.Arrays

An algorithm tests the air pressure on a slope at different altitudes. Given that the pressure depends on the altitude, what is the optimal algorithmic function to use? 1. Linear 2. Exponential 3. N-log-N 4. f(n) = log n

Linear This is a linear function because you are studying the relationship between pressure and height where the function is a straight line and there is a relationship between pressure and height, and the slope changes in a linear way in relation to the height or distance.

Kara's code includes a binary search operation. Which of the following functions would be optimal to test the execution time of this function 1. Linear 2. Exponential 3. Log n 4. Quadratic

Log n Logarithmic Function f(n) = log n, or O log (n) function is used for binary search algorithms where the input n is divided into 2 and and the search process continued till the element is found. The time to run the algorithm is equal to the log of the input size n.

Out of a random bunch of last years' holiday greeting cards, Clara wants to find the one her mother sent her. The optimal algorithm to use will be _____. 1. Linear 2. Exponential 3. N-log-N 4. f(n) = log n

N-log-N The ideal algorithmic function for this would be N-log-N where Clara has n number of greeting cards, and so n choices for the initial selection. Based on that selection she can move forward or backward to continue the search.

If you use sorting methods contained in the Java library, do you have to code the sorting algorithm?

No, the library does all the sorting according to the set criteria

What are asymptotic notations? 1. Results are calculated after the graphs are plotted after the program is executed. 2. Experiments conducted to understand the running time of an algorithm to understand how it is affected by the input size. 3. Notations that allow us to analyze an algorithm's running time by identifying its behavior as the input size for the algorithm increases. 4. Notations that are used to evaluate the data points of experiments.

Notations allow us to analyze an algorithms running time by identifying its behavior as the input size for the algorithm increases

IF one for loop runs with size N and the other with size M and the loops follow a linear function, what is the expected time complexity?

O(M+N)

For a linear function, what would be its time complexity?

O(N)

i=0; while(i<n) { j=i; while(j<n && j<i+5) { /* code */ j++; } i=j; }

O(N) In this case i goes from 0 to N, but j never goes back to starting from 0, as it always starts from i. This means that the loop always moves forward and doesn't form a quadratic function. The function formed is linear and the time complexity is linear, hence O(N).

If an algorithm runs in quadratic time, what is its time complexity using Big-O?

O(N2)

The performance of a binary search in terms of Big O Notation is __________ where n is the number of elects in the array.

O(log n)

The average case performance of selection sort is?

O(n2)

What is Bubble sort performance?

O(n2)

In a Java merge sort, the unsorted array is recursively divided into sub arrays until the sub array size is _________

One

When computer scientists refer to the Big-O Notation, what are they talking about? 1. Performance measure of an algorithm 2. Operating System throughput 3. Efficiency of threaded processes 4. Security levels in an algorithm

Performance measure of an algorithm

What is the best case complexity of merge sort?

Ω(n log n)

Consider a situation where the minimum number of swap operation is required. Which sorting algorithm is best for this use-case?

Selection Sort

What is the operation called that is performed by selection sort to move numbers from the unsorted section to the sorted section of an array?

Swapping

When do you know that you have completed a binary search?

The key equals the candidate key.

What is NOT an asymptotic notation? a. θ b. Ω c. Big Oh (O) d. β

β

Why does an insertion sort take additional systems resourced to process? 1. Usually, insertion sorts are fast only when they have limited elements 2. The repeated loops through the array increase processing time 3. The repeated loops through the array actually reduce processing time 4. The Java compiler is limited in its ability

The repeated loop through the array increased processing time.

In the nested loop for the insertion sort, why do we decrement? This is an error; sorting should increment To get to the last element in the array The sort needs to go past the last element The sort orders from end to beginning

The sort orders from end to beginning

The first step to perform a binary search for a target value in a sorted array is ________?

To identify the middle elements of the array

A two-dimensional Java array is: 1. allocated as a single block of memory 2. a way to access any element by using an index value relative to the front of the array, which is referenced by the array name 3. an array with a header of size 8 bytes and another 4 bytes for storing the size of the array 4. an array of arrays

an array of arrays

When performing a binary search, the search element is compared against a _____.

candidate key

Brian has an algorithm to read through an array that contains numbers 1 through 26 and convert each number to an English alphabet. He runs the algorithm a number of times with no changes to the size of the array and no changes to the task done. The function to use is: _____ 1. f(n) = c 2. N-log-N 3. Linear 4. Quadratic

f(n) c The constant function f(n) = c or O(1) will help determine how much time it will take to complete a task when the size n is known and the task is the same. Here the size n is 26. The task is the same (converting numbers to alphabets) and does not change, irrespective of the number of times the task is performed.

Which of the following Java code blocks correctly performs an insertion sort on an array named arr? for(int i = 1; i < arr.length; i++) { for(int j = i; (j > 0 && arr[j-1] > arr[j]); j--) { int temp = arr[j]; arr[j] = arr[j-1]; arr[j-1] = temp; } }

for(int i = 1; i < arr.length; i++) { for(int j = i; (j > 0 && arr[j-1] > arr[j]); j--) { int temp = arr[j]; arr[j] = arr[j-1]; arr[j-1] = temp; } }

What is the test for the end condition in the following recursive piece of code? public void quicksort( int left, int right ) { int i, last; if (left >= right ) return; swap( left, (left + right)/2 ); last = left; for ( i = left+1; i <= right; i++ ) if ( data[i] < data[left] ) swap( ++last, i ); swap( left, last ); quicksort( left, last-1 ); quicksort( last+1, right ); } // quicksort

if (left >= right )

An experimental analysis depends on the______ results, so an algorithm cannon be ensured unless an ________ is implemented? 1. output; equivalent program 2. input; equivalent program 3. output; opposite program 4. input; opposite program

output; equivalent program

Binary search works only on _______arrays.

sorted

Given the following , int mySimpleArray[] ={7,4,6,1,2}; int temp = 0; int n = mySimpleArray.length; for (int i = 0; i < n-1; i++) { for (int j = 0; j < n-i-1; j++) { if (mySimpleArray[j] > mySimpleArray[j+1]) { int temp = mySimpleArray[j]; mySimpleArray[j] = mySimpleArray[j+1]; mySimpleArray[j+1] = temp; } } } What would the array look like after the first pass of the inner for loop of the Bubble Sort algorithm?

{4,6,1,2,7}

Which one of the following answers is possible output for this program? (suggestion: run the code in your local Java environment or at: https://repl.it)

unsorted list. 24, 2, 45, 20, 56, 75, 16, 56, 99, 53, 12. sorted list. 2, 12, 16, 20, 24, 45, 53, 56, 56, 75, 99.

Given an unsorted array {28, 32, 4, 15, 12, 45, 25, 33, 22, 56, 47, 11, 6}, what is the correct subarray after 3 recursive calls to merge sort?

{28,32}


Related study sets

HRM w/ Cragun Final Exam Pt. 1 (Ch 1-4)

View Set

Ch. 9: Introductions and Conclusions, Speech: ch. 9, Quiz 6, Ch 12 Quiz, Ch 13 Quiz, Ch 16 Quiz, Ch 15 quiz, Ch 7 Quiz, Ch 5 Quiz, Chapter 10 Quiz, Chapter 6 Quiz, Chapter 4 Quiz, Chapter 9 quiz, Chapter 8 quiz, Communications Chapter 1, College Spee...

View Set

HITT 1253 Legal and Ethics Final Test study guide ( Mcway, Chapters:1-15)

View Set

NUR 326 adult health prep u for test 2

View Set

Chapter 12: Assessing Control Risk and Reporting on Internal Controls

View Set

Criminal Procedure, 6th amendment

View Set