Week 5  Template Classes and Sequence Containers
1
TEMPLATE CLASSES AND
SEQUENCE CONTAINERS
Recall that we discussed template functions in the overview of the C+ language;
see (Week 1 and 2) Notes 6  Part 2 and Notes 7  Part 3.
As in the case of templa
Week 6  Linked Lists
1
LISTS
A list, is a sequence container that stores elements in a linear order. Lists are normally
implemented using a collection of linked nodes (objects).
The linked list consists of a series of nodes, which are not necessarily adj
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 5
Hashing I: Chaining, Hash Functions
6.006 Spring 2008
Lecture 5:
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 6
Hashing II: Table Doubling, KarpRabin
6.006 Spring 2008
Lecture
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 7
Hashing III: Open Addressing
6.006 Spring 2008
Lecture 7: Hashin
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 8
Sorting I: Heaps
6.006 Spring 2008
Lecture 8: Sorting I: Heaps
Le
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 9
Sorting II: Heaps
6.006 Spring 2008
Lecture 9: Sorting I I: Heap
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 11
Sorting IV: Stable Sorting, Radix Sort
6.006 Spring 2008
Lecture
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 12
Searching I: Graph Search & Representations
6.006 Spring 2008
Le
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 13
Searching II
6.006 Spring 2008
Lecture 13: Searching I I: Breadt
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 14
Searching III
6.006 Spring 2008
Lecture 14: Searching I II: Top
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 16
Shortest Paths II: BellmanFord
6.006 Spring 2008
Lecture 16: S
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 18
Shortest Paths III: Dijkstra
6.006 Spring 2008
Lecture 18: Short
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 19
Dynamic Programming I of IV
6.006 Spring 2008
Lecture 19: Dynam
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 20
Dynamic Programming II of IV
6.006 Spring 2008
Lecture 20: Dyna
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 4
Balanced Binary Search Trees
6.006 Spring 2008
Lecture 4: Balance
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 3 Ver 2.0
Scheduling and Binary Search Trees
6.006 Spring 2008
Lect
Week 7  Stacks and Queues
1
Stacks
Stack is a special kind of list in which all insertions and deletions occur at one end,
called the top. Thus the Stack ADT is a special case of the List ADT. A stack is also
known as a Lastinrstout (LIFO) list or a p
Linked List Problems
By Nick Parlante
Copyright 19982002, Nick Parlante
Abstract This document reviews basic linked list code techniques and then works through 18 linked list problems covering a wide range of difficulty. Most obviously, these problems ar
Notes 13: Recursive Functions
1
Recursion
All code examples of functions we have seen so far have involved one function f()
calling a dierent function g(). However, a function f() may also call itself. Such a
function is referred to as a recursive functio
1 DSA seminar March 10
1 DSA seminar March 10
Ex. 1.1. A linked list has exactly n nodes. The elements in these nodes are selected from the set cfw_0, 1, ., n. There are no
duplicates in the list. Design an O(n) worst case time algorithm to nd which one o
CS 590 Week 7 Home Work Solutions

1. a. traverse the linked list and get the sum of all nodes
b. the sum of the sequence of integers fro 1 to n = n(n+1)/2
c. get the difference of those two, the difference is the
missing one.
2.
Procedure Reverse
Week 3  The String Class Revisited
1
A String Class
We have seen that the C+ library contains a string class. However, in this lecture,
we build our own String class again. Our main intention in doing so is to illustrate
and rearm some of the fundamental
Week 5  Template Classes and Sequence Containers
1
TEMPLATE CLASSES AND
SEQUENCE CONTAINERS
As in the case of template functions, when a class depends on an underlying data
type, the class can be implemented as a template class.
A container is an object
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 2 Ver 2.0
More on Document Distance
6.006 Spring 2008
Lecture 2: Mo
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 10
Sorting III: Linear Bounds LinearTime Sorting
6.006 Spring 2008
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 15
Shortest Paths I: Intro
6.006 Spring 2008
Lecture 15: Shortest P
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 17
Shortest Paths III: Dijkstra
6.006 Spring 2008
Lecture 17: Short
The String Class
A String Class
We have seen that the C+ library contains a string class. However, in this lecture, we build our
own String class again. Our main intention in doing so is to illustrate and reaffirm some of the
fundamental features of the C
MIT OpenCourseWare http:/ocw.mit.edu
6.006 Introduction to Algorithms
Spring 2008
For information about citing these materials or our Terms of Use, visit: http:/ocw.mit.edu/terms.
Lecture 1
Introduction and Document Distance
6.006 Spring 2008
Lecture 1: