Test #1 Review 3.3#4

:-$ 20160306_234055_HDR 1457325753882459656418

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.
 

IMG_1175

IMG_1176

Posted in Discussion, Quizzes | Leave a comment

Test #1 Review

3.3 #3020160306_231639

Posted in Test #1 Review | 1 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 3.3 #1– Mark Evertson

section 3.3 #1

Posted in Uncategorized | 1 Comment

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(T : binary search tree, x: item)
v:= root of T
{a vertex not present in T has the value null }
while v\neq null and label(v) \neq x
   if x < label(v) then
    if left child of v\neq null then v:= left child of v
    else add new vertex as a left child of v and set v := null
  else
    if right child of v\neq null then v:= right child of v
    else add new vertex as a right child of v and set v := null
if root of T =null then add a vertex v to the tree and label it with x
else if v is null or label(v) \neq  x then label new vertex with x and let v be this new vertex
return v {v = location of x}

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 f(x)=x^2+x+1 is O(x^2). Remember that the definition says that there must exist a pair of positive constants (C,k) so that whenever x>k, the inequality |f(x)| \leq C|g(x)| 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 C and k. Your goal is to find a pair (C,k) so that whenever a point is in the green region, the red graph is below the blue graph. (In this case, since all y-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 (C,k). If you were proving that f(x)=x^2+x+1 is O(x^2) 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 (C,k) that works.

Hope this helps!

Posted in Discussion | Leave a comment

Jose nunez problem 20 from chapter 3.1

image

Posted in Uncategorized | Leave a comment