Docsity

Computer Science Homework: Time Complexity, Numerical Algorithms, Searching and Sorting, Assignments of Computer Science

Toggle sidebar
bg1
Homework 6
18th October
The homework is due in class (during the first 10 minutes) on Thursday, 25th October (or
before). The problems are from the book by Rosen, 6th edition (sections 3.2, 3.3). As mentioned
in the course syllabus, there are no electronic submissions and no late homeworks will be accepted
unless you have an illness spanning the full period from the time the homework was assigned until
it was due (and I shall need to see a medical practitioner’s certificate to that effect). Standard aca-
demic honesty rules apply. You can discuss problems with one another, but the solutions turned
in should be entirely your own. Cases of plagiarism will be dealt with strictly. Also, make sure
you write your name and section number on the first homework sheet and also staple
all the sheets together. UNSTAPLED OR UNNAMED HOMEWORKS WILL NOT
BE GRADED.
1 Time Complexity
1. Section 3.2: 2(a),(c),(d),(f ) [Give reasons for all your answers], 6
2. Section 3.2: 18 [Hint: This is very similar to the problem where we proved n! is O(nn)], 44
[Hint: First prove that f(x) is O(xn), as done in class. Then prove that f(x) is Ω(xn)].
3. Section 3.2: 40
2 Numerical Algorithms
Section (3.3): 4, 7, 8
3 Searching and Sorting
1. Ternary search is a method that locates a particular element qin a sorted list given as
{a1, a2, ..., an}by splitting the list into three sublists of equal size (or approximately equal
size). The list is split at two indices, which we call as s1and s2respectively. Based on a
comparison of the elements as1and as2with q, we decide in which of the three sublists, q
could possibly be found. We throw away the other two sublists and continue the same process
on the selected sublist until the element qis found, or the list is empty. Write this procedure
in pseudo-code. Analyze its worst case time complexity. Is this algorithm faster/slower than
binary search in terms of time complexity (ignoring constants)?
1
pf2

Partial preview of the text

Download Computer Science Homework: Time Complexity, Numerical Algorithms, Searching and Sorting and more Assignments Computer Science in PDF only on Docsity!

Homework 6

18th October

The homework is due in class (during the first 10 minutes) on Thursday, 25th October (or before). The problems are from the book by Rosen, 6th edition (sections 3.2, 3.3). As mentioned in the course syllabus, there are no electronic submissions and no late homeworks will be accepted unless you have an illness spanning the full period from the time the homework was assigned until it was due (and I shall need to see a medical practitioner’s certificate to that effect). Standard aca- demic honesty rules apply. You can discuss problems with one another, but the solutions turned in should be entirely your own. Cases of plagiarism will be dealt with strictly. Also, make sure you write your name and section number on the first homework sheet and also staple all the sheets together. UNSTAPLED OR UNNAMED HOMEWORKS WILL NOT BE GRADED.

1 Time Complexity

  1. Section 3.2: 2(a),(c),(d),(f) [Give reasons for all your answers], 6
  2. Section 3.2: 18 [Hint: This is very similar to the problem where we proved n! is O(nn)], 44 [Hint: First prove that f (x) is O(xn), as done in class. Then prove that f (x) is Ω(xn)].
  3. Section 3.2: 40

2 Numerical Algorithms

Section (3.3): 4, 7, 8

3 Searching and Sorting

  1. Ternary search is a method that locates a particular element q in a sorted list given as {a 1 , a 2 , ..., an} by splitting the list into three sublists of equal size (or approximately equal size). The list is split at two indices, which we call as s 1 and s 2 respectively. Based on a comparison of the elements as 1 and as 2 with q, we decide in which of the three sublists, q could possibly be found. We throw away the other two sublists and continue the same process on the selected sublist until the element q is found, or the list is empty. Write this procedure in pseudo-code. Analyze its worst case time complexity. Is this algorithm faster/slower than binary search in terms of time complexity (ignoring constants)?
  1. Insertion sort is a procedure which sorts an array of n numbers by successively maintaining smaller sorted arrays and adding new elements in such a way that the new array remains sorted after inclusion of the new element. Suppose {a 1 , a 2 , ..., an} is the array of numbers to be sorted. It starts off by building an array with just one element a 1. The next element a 2 is added either before or after a 1 such that this array with two elements is sorted in the correct order. The same procedure is applied to a 3 to produce a correctly sorted array with three elements. This whole procedure is repeated for n elements in total. Write a pseudo-code for insertion sort and analyse its time complexity. There are two aspects to this algorithm: firstly locating where to insert, and secondly re-arranging the array appropriately. Do not blindly copy the pseudo-code from the book, but work it out yourself and show the two aforementioned components clearly.

4 Optional Problems, which you should do, but do not need to

submit

  1. Supplementary exercise: 8 (page 259)
  2. Supplementary exercise: 16 (page 259) [Hint: Look at the table of standard summation in chapter 2]
  3. Let f (n) = n^0.^01 and g(n) = log(n). Can I say f (n) is O(g(n))? Can I say g(n) is O(f (n))? Why?