CIS 223 Chapter 9

Ace your homework & exams now with Quizwiz!

To search the names array for the name "Janey" using a binary search, what should the initial value of low be? var low = 0; var N = 200; var high = 0; var key = "Janey"; var index = 0; var found = 0;

0

The toStringArray() method converts each element in an array to a string.

False

Which line must be changed to sort the other way? function bubbleIt(A, B) { var flag = 0; var temp = 0; while (flag == 0) { flag = 1; for (var count = 0; count <= (A - 2); count++) { if(myArray[count] < myArray[count + 1]) { temp = myArray[count]; myArray[count] = myArray[count + 1]; myArray[count + 1} = temp; flag = 0; } } } }

7

A serial search can be compared to the way a person might look through a dictionary to find a specific word.

False

Elements in an array must be sorted in order to use the serial search.

False

The bubble sort can only sort in ascending order.

False

The sort() method is valuable because it keeps elements of parallel arrays In the correct order.

False

The type of sort routine that, if sorting from smallest to largest, will end up with the smallest item in the first place after the first pass is the bubble sort.

False

Which of the following will sort an array of strings named rainfall?

rainfall.sort();

Which of the following will sort an array of integers named rainfall? function sortNum(A, B) { return (B - A); }

rainfall.sort(sortNum);

To exchange the values in two variables, you must use a:

temporary value

Given the following array, which will return the index value of the element "tennis" and store it in a variable named tennis? var sports = new Array("football", "baseball", "soccer", "tennis", "basketball", "wrestling");

tennis = sports.indexOf("tennis");

In a selection sort that sorts in ascending order, which element will be the first element after the first pass?

the largest

In a binary search of the given array, the variable index represents which of the following:

the middle part of the array being looked at in any given pass

The method that will return all the values of a given array stored in a single variable as a string, with each value separated by a comma, is the:

toString() method

Which of the following lines of code will convert the elements of an array named sports to a single string which is stored in a variable named compete?

var compete.toString(sports);

When JavaScript arrays are passed to a function, they are passed by reference.

True

The JavaScript Array object supports functions that use sorting __________ to sort arrays.

algorithms

The method best suited to sorting a small number of items (fewer than 100) is the:

bubble sort

Does the function sort ascending or descending? function sortNum(A, B) { return (B - A); }

descending

Does this function sort ascending or descending? function bubbleIt(A, B) { var flag = 0; var temp = 0; while (flag == 0) { flag = 1; for (var count = 0; count <= (A - 2); count++) { if(myArray[count] < myArray[count + 1]) { temp = myArray[count]; myArray[count] = myArray[count + 1]; myArray[count + 1} = temp; flag = 0; } } } }

descending

To search the names array for the name "Janey" using a binary search, what should the initial value of index be? var low = 0; var N = 200; var high = 0; var key = "Janey"; var index = 0; var found = 0;

Math.round((N+1)/2)

To search the names array for the name "Janey" using a binary search, what should the initial value of high be? var low = 0; var N = 200; var high = 0; var key = "Janey"; var index = 0; var found = 0;

N

If the highest index value in an array is N, to complete a selection sort, N - 1 passes must be made.

True

The method that will search an array for a specified item and return the item's position in the array is the indexOf() method.

True

The type of search that compares each element in order, from first to last, to the element that is being searched for is the serial search.

True


Related study sets

Prep Quiz #8 - Antibiotic & Immune

View Set

VT Chapter 1, VT Quiz 12, VT Quiz 11, VT Quiz 10, VT Quiz 9, VT Quiz 8, VT Quiz 7, VT Quiz 6, VT Chapter 4, VT Chapter 3, VT Chapter 2, VT Chapter 5

View Set

environmental chapter 13 test questio

View Set

SOC 100 - Chapter 16: Education Quiz

View Set

trauma & burns practice questions (ch 20 & 21)

View Set

Intro Midterm: Professional Socialization & Communication

View Set

Government Health Insurance Plans

View Set

MGT 3100 Management & Behavioral Sciences- Module 1

View Set