0% found this document useful (0 votes)
57 views

Chap03 Problems

This document contains 7 problems related to data structures and algorithms. Problem 1 asks to calculate comparison operations for sequential and binary search on an array and comment on results. Problem 2 asks which elements are compared during a binary search of a sorted array. Problem 3 asks about modifying sequential search by first sorting the array. Problem 4 asks to outline an algorithm to cut a stick into pieces with minimum cuts. Problem 5 asks if binary search efficiency depends on array or linked list implementation. Problem 6 asks about an efficient algorithm for a picture guessing game. Problem 7 asks to design an efficient algorithm to find a missing integer in a sorted range.

Uploaded by

HoiAnh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Chap03 Problems

This document contains 7 problems related to data structures and algorithms. Problem 1 asks to calculate comparison operations for sequential and binary search on an array and comment on results. Problem 2 asks which elements are compared during a binary search of a sorted array. Problem 3 asks about modifying sequential search by first sorting the array. Problem 4 asks to outline an algorithm to cut a stick into pieces with minimum cuts. Problem 5 asks if binary search efficiency depends on array or linked list implementation. Problem 6 asks about an efficient algorithm for a picture guessing game. Problem 7 asks to design an efficient algorithm to find a missing integer in a sorted range.

Uploaded by

HoiAnh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Course: Data Structures & Algorithms

Class: 22CLC01/22CLC07

CHAPTER 3 – PROBLEMS
Problem 1. Given an array A as follow:
𝐴 =< −9, −9, −5, −2, 0, 3, 7, 7, 10, 15 >
a. Calculate the number of comparison operations to find 𝑥 = −9 using two
algorithms: sequential search and binary search (only count the comparison
between the search key and array’s elements). Give your comments about the
results.
b. In case of using binary search, which value is returned (0 or 1)?

Problem 2. During a binary search, which elements in the array 𝐴 =<


4, 8, 12, 14, 20, 24 > are compared to the key when the key is:
a. 2
b. 8
c. 15

Problem 3. Given an array A of n integers. Write a search algorithm as follow:


o Step 1: Sort A using any sort algorithm that you like
o Step 2: Search for an integer x in A using sequential search, return i if A[i] == x
and returns -1 if A[i] > x.
a. Is this algorithm better the original sequential search algorithm which do not sort
the array A beforehand? (Hint: observe the case that there exists x in A and the
case that x does not appear in A)
b. Is this algorithm faster than a binary search algorithm?

Problem 4. Cutting sticks. A stick n meters long needs to be cut into n 1-m pieces.
Outline an algorithm that performs this task with the minimum number of cuts if several
pieces of the stick can be cut at the same time. Also give a formula for the minimum
number of cuts.

Problem 5. The time efficiency of sequential search does not depend on whether a list
is implemented as an array or as a linked list. Is it also true for searching a sorted list by
binary search?

Problem 6. Picture guessing. A version of the popular problem-solving task involves


presenting people with an array of 42 pictures—seven rows of six pictures each— and
asking them to identify the target picture by asking questions that can be answered yes
or no. Further, people are then required to identify the picture with as few questions as
possible. Suggest the most efficient algorithm for this problem and indicate the largest
number of questions that may be necessary.

Problem 7. An array A[0..n − 2] contains n − 1 integers from 1 to n in increasing order.


(Thus one integer in this range is missing.) Design the most efficient algorithm you can to
find the missing integer and indicate its time efficiency.

Lecturer: Nguyễn Hải Minh – University of Science HCM city – [email protected]


1

You might also like