Searching Algorithms

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

Suppose you have an array containing the following elements: 4, 8, 2, 9, 10, 6, 7, 5, 1, 9, 4, 5, 10, 7. What is the position of the last occurrence of 5?

12th

How many comparison operations are required to possibly locate the number 10 in the following array when performing a sequential search?

13

Suppose you have an array containing the following elements: 4, 8, 2, 9, 10, 6, 7, 5, 1, 9, 4, 5, 10, 7. How many elements will you have to examine if you are looking for a 3 and doing a sequential search?

14

Suppose you have an array with the following data: Index 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Value 24 26 34 37 48 51 56 57 70 72 74 83 89 92 97 How many probes will you need to either find the value 37 or determine that it is not in the array using binary search?

2

How many comparison operations are required to possibly locate the number 10 in the following array when performing a binary search?

4

How many comparison operations are required to possibly locate the number 5 in the following array when performing a sequential search?

8

How do you initiate the variable location that contains the location of the particular value you are looking for at the beginning of the search?

Assign a number that is larger than the size of the array under consideration

What is the highest number of comparisons you can make in a sequential search to locate the desired value?

Entire size of the array

In which condition(s) do you not sort the array in ascending or descending order first before performing the binary search algorithm?

Entries that have already been assigned in ascending or descending order

Suppose you have an array containing the following elements: 4, 8, 2, 9, 10, 6, 7, 5, 1, 9, 4, 5, 10, 7. How many elements will you have to examine if you are looking for a 9 and doing a sequential search?

Four

Suppose you have an array with the following data: Index 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Value 24 26 34 37 48 51 56 57 70 72 74 83 89 92 97 What is the maximum number of probes you will need to either find a value or determine that it is not in the array using binary search?

Four

Suppose you are searching for the value V in the sorted array A of size N. The description of the binary search algorithm says look at the middle element, say it has index J, which has the value M = A [J]. What happens next?

If M > V and then if V is in the array, it is in the lower half.

Which part of the array do you start comparing the contents of the array against the desired number you are looking for in a binary search?

In the middle of the array

Which part of the array do you start comparing the contents of the array against the desired number you are looking for in a sequential search?

Index = 1

Suppose you have N data records, and you want to confirm that a record is not in your database. On average, how many records would a sequential search have to examine? Assume for this problem that it is unlikely that the record will be in the database.

N

Suppose you have N records with a value field V, which is some positive integer. Suppose you want to find all records with a specific value using a sequential search. On average, how many records must you search?

N

Which one of the following search algorithms is easier to program into a computer?

Sequential

What is the function of a search algorithm?

To find the location of a particular value within an array

Suppose you have N records with a value field V, which is some positive integer. Further suppose that the records are sorted in increasing order of field V and are stored in random access memory so that they can be accessed in any order. About how many records must you look at to find a record with a specific value in field V using binary search?

log_2 N


Set pelajaran terkait

Chapter 4: Health Education and Promotion

View Set