0% found this document useful (0 votes)
1K views1 page

Sec A

The document discusses algorithms and their complexity. It states that while computational power has increased, algorithms with exponential or factorial complexity remain difficult to solve. Problems considered impossible to solve years ago can now be routinely solved due to faster computers, more memory, and parallel processing, and this trend will continue. The document then provides examples of algorithm segments and asks for Big-O estimates of operations like additions, comparisons, and multiplications.

Uploaded by

roufix
Copyright
© Attribution Non-Commercial (BY-NC)
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)
1K views1 page

Sec A

The document discusses algorithms and their complexity. It states that while computational power has increased, algorithms with exponential or factorial complexity remain difficult to solve. Problems considered impossible to solve years ago can now be routinely solved due to faster computers, more memory, and parallel processing, and this trend will continue. The document then provides examples of algorithm segments and asks for Big-O estimates of operations like additions, comparisons, and multiplications.

Uploaded by

roufix
Copyright
© Attribution Non-Commercial (BY-NC)
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

3.

3 Complexity of Algorithms 229


offer little help in overcoming the complexity of algorithms of exponential or factorial time
complexity. Because ofthe increased speed of computation, increases in computer memory, and
the use of algorithms that take advantage of parallel processing, many problems that were con-
sidered impossible to solve five years ago are now routinely solved, and certainly five years from
now this statement will still be true. This is even true when the algorithms used are intractable.
Exercises
1. Give a big-O estimate for the number of operations
(where an operation is an addition or a multiplication)
used in this segment of an algorithm.
t:= 0
for i := 1 to 3
for j := 1 to 4
t := t + ij
2. Give a big-O estimate for the number additions used in
this segment of an algorithm.
t:= 0
for i := 1 to n
for j := 1 to n
t:= t + i + j
3. Give a big-O estimate for the number of operations,
where an operation is a comparison or a multiplication,
used in this segment of an algorithm (ignoring compar-
isons used to test the conditions in the for loops, where
ai, a2, ... , an are positiye real numbers).
m :=0
for i := 1 to n
for j := i + 1 to n
m := max(aiaj, m)
4. Give a big-O estimate for the number of operations,
where an operation is an addition or a multiplication, used
in this segment of an algorithm (ignoring comparisons
used to test the conditions in the while loop).
i := 1
t := 0
while i ::: n
t := t + i
i := 2i
s. How many comparisons are used by the algorithm given
in Exercise 16 of Section 3.1 to find the smallest natural
umber in a sequence of n natural numbers?
a ) Lse pseudocode to describe the algorithm that puts the
first four terms of a list of real numbers of arbitrary
length in increasing order using the insertion sort.
h Show that this algorithm has time complexity 0 (1) in
-crms of the number of comparisons used.
. that an element is known to be among the first
=- - in a list of 32 elements. Would a lin-
::=:: or a binary search locate this element more
.. ?
'-7-=-.... a real number x and a positive integer k, determine
--: ::::mber of multiplications used to find x2k starting
with x and successively squaring (to find x
2
, x4, and so
on). Is this a more efficient way to find x2k than by mul-
tiplying x by itself the appropriate number of times?
9. Give a big- O estimate for the number of comparisons
used by the algorithm that determines the number of Is
in a bit string by examining each bit of the string to deter-
mine whether it is a 1 bit (see Exercise 25 of Section 3.1).
* 10. a) Show that this algorithm determines the number of 1
bits in the bit string S:
count(S: bit string)
count:= 0
while S =f=. 0
count := count + 1
S := S /\ (S - 1)
return count {count is the number of 1 s in S}
Here S - 1 is the bit string obtained by changing the
rightmost 1 bit of S to a 0 and all the 0 bits to the right
of this to Is. [Recall that S /\ (S - 1) is the bitwise
AND of Sand S - l.]
b) How many bitwise AND operations are needed to find
the number of I bits in a string S using the algorithm
in part (a)?
11. a) Suppose we have n subsets S[, S2, ... , Sn of the set
{I, 2, ... , n}. Express a brute-force algorithm that de-
termines whether there is a disjoint pair of these sub-
sets. [Hint: The algorithm should loop through the
subsets; for each subset Si, it should then loop through
all other subsets; and for each of these other subsets
S j, it should loop through all elements k in Si to de-
termine whether k also belongs to Sj .]
b) Give a big-O estimate for the number of times the
algorithm needs to determine whether an integer is in
one of the subsets.
12. Consider the following algorithm, which takes as input a
sequenceofn integers aI, a2, ... , an and produces as out-
put a matrix M = {mij} where mij is the minimum term
in the sequence of integers ai, ai + I, ... , a j for j 2': i and
mij = 0 otherwise.
initialize M so that mij = ai if j 2': i and mij = 0
otherwise
for i := I to n
for j := i + 1 to n
for k := i + 1 to j
mij := min(mij, ak)
return M= {mij} {mij is the minimum term of
ai, ai+l, .. , aj}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy