Upcoming important dates

  1. This Wednesday, May 4: Homework #9 due/Quiz #9
  2. This Friday, May 6: Test #3 Review OpenLab Assignment due by 11:59pm (same instructions as for Test #1 Review)
  3. Next Monday, May 9: Test #3 on Sections 8.1, 8.2, 8.3, and 8.4
  4. The following Monday, May 16: Project due by 11:59pm
Posted in Homework, Project, Quizzes, Test #3 Review | Leave a comment

Project due May 16

You may work alone or in groups of at most 2. The project has 3 parts.

Part 1 (30%): Run an algorithm on an input set
You are given a fragment of pseudocode below which describes an algorithm.
(a) The pseudocode below may or may not contain an error. If there is an error, rewrite the algorithm in pseudocode with the error corrected. This may involve some judgement on your part. Highlight your change. If there is no error, skip Part 1(a).
(b) Choose an appropriate input set for the (corrected) algorithm. Show what the algorithm does with this input set. Show each step.
(c) Determine a big-O estimate for the time complexity of the (corrected) algorithm. Explain your answer.

Part 2 (50%): Translate into English
It is up to you to determine what task the (corrected) algorithm from Part 1 is performing, as well as how it accomplishes this task. Write a short essay providing a detailed description of what task the algorithm is performing, as well as a line-by-line description of how it accomplishes this task. You may quote lines directly from the pseudocode in your essay. If there was an error in the original pseudocode, include a detailed description of the error, why it causes a problem, and how your correction solves the problem. Write your essay in plain English so that it is readable by a non-expert–someone who has never taken a programming or algorithms class and who is not familiar with pseudocode.

Part 3 (20%): Translate into a programming language
Write a program that implements the (corrected) algorithm for the set of inputs you chose in Part 1 and prints the output. Include comments throughout; in particular, include a comment that shows where you have included your input set. Your program must be written in C++ or Java.

Submission instructions (note: these will be updated)
Email the following to kpoirier@citytech.cuny.edu by 11:59pm on Monday, May 16. Be sure to include your name in every file.

  1. Part 1 may be completed by hand or using a computer; attach it to your email as a jpg or a pdf.
  2. Part 2 must be typed using a word-processor and attached as a pdf.
  3. If you are writing Part 3 in C++, save your program on cpp.sh. Create a short URL and include the link in the body of your email. If you are writing Part 3 in Java, DETAILS TBA.

The algorithm

procedure mystery algorithm 1(L= a_1, \dots a_n: real numbers)
if n>1 then
m1:= \lfloor\frac{n}{3} \rfloor
m2:= 2\lfloor \frac{n}{3} \rfloor
L_1:= a_1, \dots, a_{m1}
L_2:= a_{m1+1}, \dots, a_{m2}
L_3:= a_{m2+1}, \dots, a_{n}
L= mystery algorithm 2(mystery algorithm 1(L_1), mystery algorithm 1(L_2), mystery algorithm 1(L_3)
return L

procedure mystery algorithm 2(L_1, L_2 : sorted lists)
L := empty list
while L_1 and L_2 are both nonempty
  remove smaller of first elements of L_1 and L_2 from its list; put it at the right end of L
if this removal makes one list empty then remove all elements from the other list and
 append them to L
return L

Edit: Mystery algorithm 1 and/or 2 may look similar to algorithms we’ve seen in class. For the project you will have to use your judgement if you are making corrections. However, if your corrected algorithm looks like one from class, then you will not receive credit for the correction. However, you may wish to use algorithms from class as a guide. Let me know if you have any questions.

Edit 2: This is not a class project. You may ask clarifying questions in the comments below, but you must work either completely independently or with your partner if you have one. (This is just a friendly reminder not to spoil it for anyone by spilling too much information about how to complete the project in the comments!)

Posted in Project | 4 Comments

Homework due and quiz #9 – Wednesday, May 4

8.3 #14, 15, 16

8.4 #2, 4, 8, 10, 12

It might not be immediately obvious because the wording is a little different, but the exercises from 8.4 are similar to the examples we saw in class today. If it’s not clear what a “closed form” means, you can check the answers in the back of the book for the corresponding odd-numbered problems to see what form the answers are in. You’ll probably find the table on page 542 will be useful. We discussed the entries in rows 4 and 5 of that table in detail today; the entries in the next few rows are modifications of those.

Just a reminder: while formal power series are not polynomials, you can manipulate them in much the same way you would polynomials. For example, to add two power series, you add like terms; to multiply power series, you distribute terms. This is all that Theorem 1 on page 538 is saying.

Posted in Homework, Quizzes | 2 Comments

Merge and mergesort

Head’s up: after Wednesday’s quiz, we’ll use the master theorem to determine a big-O estimate for the complexity of the mergesort algorithm. Today you and your partner implemented the merge algorithm on the ordered sets of numbers that you chose. Merge is a component of mergesort, both described below, so the number of comparisons needed for merge will be part of the function you set up for the master theorem.

procedure merge(L_1, L_2 : sorted lists)
L := empty list
while L_1 and L_2 are both nonempty
  remove smaller of first elements of L_1 and L_2 from its list; put it at the right end of L
if this removal makes one list empty then remove all elements from the other list and
 append them to L
return L
{L is the merged list with elements in increasing order}

procedure mergesort(L = a_1,\dots, a_n)
if n > 1 then
m := \lfloor \frac{n}{2} \rfloor
L_1 := a_1,a_2,\dots,a_m
L_2 := a_{m+1},a_{m+2},\dots,a_n
L := merge(mergesort(L_1), mergesort(L_2))
{L is now sorted into elements in nondecreasing order}

Posted in Uncategorized | Leave a comment

Two equivalent formulations of the binary search algorithm

First version:
procedure binary search (x: integer, a_1, a_2,\dots, a_n: increasing integers)
i:= 1
j:= n
while i <j
m:= \lfloor \frac{i + j}{2}\rfloor
if x>a_m then i:=m+1
else j:=m
if x = a_i then location :=i
else location :=0
return location

Second version:
procedure binary search (i, j, x: i, j, x: integers, 1 \leq i \leq j \leq n, a_1, a_2,\dots, a_n: increasing integers)
if x = a_m then
return m
else if (x <a_m and i <m) then
return binary search(i, m-1, x)
else if (x > a_m and j > m) then
return binary search(m + 1, j, x)
else return 0
{output is location of x in a_1, a_2, \dots, a_n if it appears; otherwise it is 0}

Posted in Discussion | Leave a comment

Homework due and quiz #8 – Wednesday, April 20

Section 8.2 #11

Section 8.3 #8, 10, 11, 12, 13

Posted in Homework, Quizzes | Leave a comment

Homework due and quiz #7 – Wednesday, April 13

Section 8.1 #2a, 8, 14, 28, 30

Section 8.2 #4, 8

Posted in Homework, Quizzes | Leave a comment

Test # 2 Review Carlos.P section 11.4 question 2-6

Section 11.4 q 2-6

Section 11.4 q 2-6

Posted in Test #2 Review | Leave a comment

Rivka Ligier Test #2 Review: 11.4 #15

Use the depth-first search to produce a spanning tree the given sample graph. Choose a as the root of this spanning tree and assume the vertices are ordered alphabetically.

Excuse my horrible drawing 🙂

 

IMG_0190

Posted in Uncategorized | 1 Comment

Test #2 Review – Kamil Sachryn

Chapter 11.2 #13
2016-4-1_93218_1

Posted in Test #2 Review | 1 Comment