Previous Lecture Lecture 6 Next Lecture

Lecture 6, Mon 01/28

Midterm 1 Review, Quadratic-Time Sorting cont., Hashing

Logistics
- Bring studentID and writing utensil
- No electronic devices
- No notes, no books

Format
- Will be a mix of questions based on lectures, homeworks, readings, and labs.
- Short Answer
	- Briefly define, describe, state, ...
- Write code (includes makefiles)
- Fill in the blank / complete the table
- Given code, write the output
- Given a statement, tell me if it's true / false
	- if false, briefly state why
- Expect it to take ~ one hour (maybe sooner)
	- but we have the entire class period
- Will cover a broad range of topics, but probably not everything

Topics
- Will cover everything up to Wednesday's lecture (1/23)

Makefiles
- Know how to create one when multiple files are linked to form an
executable
- Know the build process
	- Proprocessing, Compiling, Linking
- Know what the default rules are, flags, special symbols (as discussed in lecture)

Standard Template Library
- Reviewed some details about vectors
	- Operations like [], at, front, back, pop_back, push_back, size, constructors, ...
- STL container iterators
	- begin(), end(), ++, <, *, erase

Class Design
- Abstract Data Types
- How to design an interface (.h file) and its implementation (.cpp)
- Public vs. Private
- Accessors (getters) vs Mutators (setters)
- Constructors (default, overloaded, copy)
- Header guards
- Scope Resolution operator (::) and .cpp method definitions
- Shallow vs. Deep Copy
- Big Three (Rule of Three): copy constructor, destructor, assignment operator

Structs and Classes
- What are the difference(s)?
- Memory Padding (how they are stored in memory)

Namespaces
- Avoid naming collisions
- How to create namespaces in your code
- Global namespace (how to specifiy using "::")

Binary Search
- Recursive (and iterative (non-recursive)) implementation
- Performance (running time), O-notation

Quadratic Sorting Algorithms
- bubbleSort
	- Optimized version
- selectionSort

Insertion Sort

Example

void insertionSort(int a[], size_t size) {

	int item;
	int shiftIndex;
	for (int i = 1; i < size; i++) {
		item = a[i];
		shiftIndex = i - 1;

		while (shiftIndex >= 0 && a[shiftIndex] > item) {
			a[shiftIndex + 1] = a[shiftIndex];
			shiftIndex -= 1;
		}
		a[shiftIndex + 1] = item;
	}	
}

int main() {
	int a[] = {1,2,3,4,5,6,7,8,9,10};
	int b[] = {1,10,2,9,3,8,4,7,5,6};
	int c[] = {2,9,4,7,6,5,8,3,10,1};
	int d[] = {10,9,8,7,6,5,4,3,2,1};
	int e[] = {1};

	insertionSort(a, 10);
	printArray(a,10);
	cout << "---" << endl;
	insertionSort(b, 10);
	printArray(b,10);
	cout << "---" << endl;
	insertionSort(c,10);
	printArray(c,10);
	cout << "---" << endl;
	insertionSort(d,10);
	printArray(d,10);
	cout << "---" << endl;
	insertionSort(e,1);
	printArray(e,1);

Hashing

Hash Table

Collisions

Open-address Hashing

Open Address

Double Hashing

Double Hashing

Chained Hashing

Chaining