Python Programming for Engineers
and Scientists, 1st Edition
Complete Chapter Solutions Manual
are included (Ch 1 to 13)
** Immediate Download
** Swift Response
** All Chapters included
** Python Programming Files
,Table of Contents are given below
1. Introduction.
2. Software Development, Data Types, and Expressions.
3. Loops and Selection Statements.
4. Strings and Text Files.
5. Lists and Dictionaries.
6. Design with Functions.
7. Design with Recursion.
8. Simple Graphics and Image Processing.
9. Graphical User Interfaces.
10. Design with Classes.
11. Data Analysis and Visualization.
12. Multithreading, Networks, and Client/Server
Programming.
13. Searching, Sorting, and Complexity Analysis.
,Solutions Manual organized in reverse order, with the last chapter displayed first, to ensure that all
chapters are included in this document. (Complete Chapters included Ch13-1)
Solution and Answer Guide
CENGAGE, PYTHON PROGRAMMING FOR SCIENTISTS AND ENGINEERS, 1E, ©2025, 9798214002446;
CHAPTER 13, SEARCHING, SORTING, AND COMPLEXITY ANALYSIS
TABLE OF CONTENTS
Exercise Solutions ....................................................................................................................................... 1
Exercise 13.1 ............................................................................................................................................. 1
Exercise 13.2 ............................................................................................................................................. 2
Exercise 13.3 ............................................................................................................................................. 3
Exercise 13.4 ............................................................................................................................................. 4
Exercise 13.5 ............................................................................................................................................. 4
Review Questions Answers......................................................................................................................... 5
Programming Exercises Solutions ........................................................................................................... 11
EXERCISE SOLUTIONS
EXERCISE 13.1
1. Write a tester program that counts and displays the number of iterations of the following loop:
while problemSize > 0:
problemSize = problemSize // 2
Solution:
problemSize = int(input("Enter the problem size: "))
count = 0
while problemSize > 0:
problemSize = problemSize // 2
count += 1
print(count)
2. Run the program you created in Exercise 13.1 using problem sizes of 1000, 2000, 4000, 10,000, and
100,000. As the problem size doubles or increases by a factor of 10, what happens to the number of
iterations?
Solution:
When the problem size doubles, the number of iterations increases by 1. When the problem increases by a
factor of 10, the number of iterations increases by 3.
1
, 3. The difference between the results of two calls of the time function time() is an elapsed time. Because
the operating system might use the CPU for part of this time, the elapsed time might not reflect the actual
time that a Python code segment uses the CPU. Browse the Python documentation for an alternative way of
recording the processing time and describe how this would be done.
Solution:
According to the Python documentation, the function time.process_time can be used to measure
the time that a process actually uses the CPU, without including the time that the process sleeps.
EXERCISE 13.2
1. Assume that each of the following expressions indicates the number of operations performed by an
algorithm for a problem size of n. Point out the dominant term of each algorithm and use big-O notation to
classify it.
a. 2n – 4n2 + 5n
b. 3n2 + 6
c. n3 + n2 – n
Solution:
a. 2n, O(n)
b. 3n2, O(n2)
c. n3, O(n3)
2. For problem size n, algorithms A and B perform n2 and ½ n2 + ½ n instructions, respectively. Which
algorithm does more work? Are there particular problem sizes for which one algorithm performs
significantly better than the other? Are there particular problem sizes for which both algorithms perform
approximately the same amount of work?
Solution:
Algorithm A does more work, on all problem sizes.
3. At what point does an n4 algorithm begin to perform better than a 2 n algorithm?
Solution:
When n is 16, then n4 and 2n are the same, 65536. When n is 17, n4 is 83521 and 2n is 131072.
EXERCISE 13.3
1. Suppose that a list contains the values
20 44 48 55 62 66 74 88 93 99
at index positions 0 through 9. Trace the values of the variables left, right, and midpoint in a binary search
of this list for the target value 90. Repeat for the target value 44.
Solution:
2