×
×

# Suppose that an element is known to be among the first ISBN: 9780073383095 37

## Solution for problem 7E Chapter 3.3

Discrete Mathematics and Its Applications | 7th Edition

• Textbook Solutions
• 2901 Step-by-step solutions solved by professors and subject experts
• Get 24/7 help from StudySoup virtual teaching assistants Discrete Mathematics and Its Applications | 7th Edition

4 5 0 426 Reviews
12
2
Problem 7E

Suppose that an element is known to be among the first four elements in a list of 32 elements. Would a linear search or a binary search locate this element more rapidly?

Step-by-Step Solution:

SolutionStep 1In this problem, we have to show that which algorithm is better linear search or binary search.Step 2PseudoCode of Linear Searchlinear_search_item(num1, num2, num3, ……… set of integers )Now start the loop For (index_1 = 0 ; index _1 < size ; index_1++) if(element at ith position = = number that to be search)then Return true Else Return false End of the loopEnd of the procedureStep 3PseudoCode of Binary searchbinary_search_item(num1, num2, num3, ……….. Set of integers)Assign the lower index as right_index = 1Assign the upper index as left_index = size of the list while (left_index <= right_index) Assign the middle variable as middle_index = (low_index + high_index)/2 If (element at middle_index position...

Step 2 of 3

Step 3 of 3

##### ISBN: 9780073383095

Unlock Textbook Solution