Header Image
Creative Commons image courtesy of Flickr user StormPetrel1-
Recent Posts
Recent Comments
- In the Spotlight: MAT2540 – Discrete Structures and Algorithms II – The Open Road on Links
- OpenLab Workshop for Opening Gateways Fellows | 2018-2019 Opening Gateways Faculty Seminar on Final Exam Review
- Eric on Eric’s Final Review
- Kate Poirier on Hints/reminders from today’s class
- Kate Poirier on Final Exam Review
Archives
Categories
Meta
Test #1 Review 3.3#4
Posted in Test #1 Review
1 Comment
Quiz #4 Results
Below you’ll see photos of your graded group quizzes from last week. It was a fun exercise, but perhaps not the most successful one in the whole world. Both groups lost out by not explaining their steps, though both groups seemed to be on the right track. Check out my comments and let me know if you have any questions.
Posted in Discussion, Quizzes
Leave a comment
Test #1 Review
Devise an algorithm that finds the sum of all the integers in a list
procedure sum (a1, a2,…,an:integers)
sum = an
for i to an -1
sum= sum + an
return sum;
Posted in Test #1 Review
2 Comments
Test # 1 Review – Francisco Tamay
Section 3.1 # 6
Describe an algorithm that takes as input a list of n integers and finds the number of negative integers in the list
list Number Of Negative (a1, a2,…an)
i = 1 to n
N = number of negative numbers = 0
if ai < 0
N = N + 1
Return N
Posted in Test #1 Review
1 Comment
Test #1 Review – Rivka Ligier Section 3.1 Ex: 24
Question: Describe an algorithm that determines whether a function from a finite set to another finite set is one-to-one
Code/Algorithm:
Procedure one-to-one([A=(a1,a2,a3, …], [B= b1, b2, b3 …] : integers)
for i = 1 to m
k = 0 (counter variable)
for j = 1 to n
if Aj = Bi then k = k+1
if k ==! (doesn’t equal) 1 then return false
if k = 1 then return true
Posted in Uncategorized
Leave a comment
Binary Search Tree Algorithm
procedure insertion( : binary search tree,
: item)
root of
{a vertex not present in has the value null }
while and
if then
if left child of then
left child of
else add new vertex as a left child of and set
else
if right child of then
right child of
else add new vertex as a right child of and set
if root of then add a vertex
to the tree and label it with
else if is null or
then label new vertex with
and let
be this new vertex
return {
= location of
}
Posted in Uncategorized
Leave a comment
Big O Example – Graph
Hi everyone. I see that many of you have submitted your Test #1 review exercises and are making corrections already…that’s great! I’ll take a look at them tomorrow after class. Don’t forget to tag your post with the category “Test #1 Review” on the right side of the screen.
In the meantime…some of you are still having trouble understanding Big O notation. I can’t stress enough how important the definition on page 205 is. It’ll be impossible to understand what calculations to perform without at least an understanding of the definition. We discussed the way to think about it graphically in class and during office hours, and I just wanted to share an example here.
You can use this graph to see why is
. Remember that the definition says that there must exist a pair of positive constants
so that whenever
, the inequality
is satisfied. On the graph in the link, you get to play with the slider tools on the left side of the screen to change the values of
and
. Your goal is to find a pair
so that whenever a point is in the green region, the red graph is below the blue graph. (In this case, since all
-values are non-negative, you can add the absolute value bars without changing anything.)
You’ll see that there will be very many possible choices for . If you were proving that
is
by hand, you might find one particular choice is easiest to work with. Because the definition involves an existence statement, you just need to find one pair
that works.
Hope this helps!
Posted in Discussion
Leave a comment