formatted to Github Markdown syntax by Ryan Peters
http://courses.washington.edu/css343/pisan/
About me
Order them based on your level of comfort
https://pollev.com/pisan
Somebody forgot to write comments!
int foo(int n)
{
if (n 0)
return 1;
else
return n * foo(n - 1);
}
What is its complexity? Why?
int mystery(const int anArray[], int first, int last, int target)
{
int index;
if (first > last)
index = -1;
else
{
int mid = first + (last - first) / 2;
if (target anArray[mid])
index = mid;
else if (target < anArray[mid])
index = mystery(anArray, first, mid - 1, target);
else
index = mystery(anArray, mid + 1, last, target);
}
return index;
}
What is its complexity? Why?
template<class ItemType>
bool Grouch<ItemType>::mumble(const ItemType& newEntry)
{
Node<ItemType>* nextNodePtr = new Node<ItemType>();
nextNodePtr->setItem(newEntry);
nextNodePtr->setNext(headPtr);
headPtr = nextNodePtr;
itemCount++;
return true;
} // end add
What is its complexity? Why?
SomeInterface, but what?
template<class ItemType>
class SomeInterface
{
public:
virtual bool isEmpty() const = 0;
virtual bool push(const ItemType& newEntry) = 0;
virtual bool pop() = 0;
virtual ItemType peek() const = 0;
virtual ~SomeInterface() { }
};
template<class ItemType>
void someSort(ItemType theArray[], int n)
{
bool sorted = false;
int pass = 1;
while (!sorted && (pass < n))
{
sorted = true;
for (int index = 0; index < n - pass; index++)
{
int nextIndex = index + 1;
if (theArray[index] > theArray[nextIndex])
{
std::swap(theArray[index], theArray[nextIndex]);
sorted = false; // Signal exchange
} // end if
} // end for
pass++;
} // end while
} // end someSort
What is its complexity? Why?
Representing (a - b) x c
Let’s try different traversals.
Group Exercise: ((a + b) * (c + d)) / (e * f) - g
search(BST, target)
if (BST is empy)
item not found
else if target data in BST
item found
else if target < data
search(left subtree, target)
else
search(right subtree, target)
What is the worst case complexity for a badly constructed tree?
Create a balanced BST for A, B, C, D, E, F
Explore the Resources on course pages
Read/Review Binary Search Trees
Read Math (Rosen) 11.1-3 (available under Resources)
Logon to #slack https://css-uwb.slack.com/ join #343 and give an example of a programming error that you tend to make
Assignment 1: TurtleProgram
Start programming