Worksheet Week 5
1)
Insert the following keys into BST: A S E R C H I
2)
Given two values k1 and k2 (where k1 < k2) and a root pointer to the
following Binary Search Tree, printBST() function prints all the keys of
tree in range k1 to k2. For example give
Lecture 4
Sequences and iterators
EECS-311
Memory structure
Ultimately, the computers memory
is one big array of bytes
Discrete chunks are allocated to
represent objects
And those objects are identified by
the location (address) within the
array
Memory ma
Lecture 3
Modularity
and abstract data types
EECS-311
software design
What makes a good design?
We want to
be able to
build our
programs
Easily
We also want our
programs to be
maintainable
Easy to find and fix bugs
we missed before
release
Easy to add new
Lecture 9
Red/black trees
EECS-311
Note
If youre like me, then red/black trees will
make you feel stupid
Youll think
Id never have thought of that, or
I understand every individual step and yet I
still dont feel like I understand the whole
thing
Youre not
Lecture 6
How does compilation and
interpretation really work?
EECS-311
Why study programming
languages?
You may want to implement a
scriptinglanguageor macrolanguagefor
an application youre working on
Word, Excel, Web browsers, etc.
You may be working on
Lecture 8
Binary search trees
EECS-311
Representing collections of
objects
Binary trees
Common case
Fixedbranching
factorof 2
Every node has
at most 2
children
Referred to as
the left child and
rightchild
Inorder traversal
Inorder(node) cfw_
1
Inorder(nod
Lecture 7
The HappyFunBlob code
EECS-311
Demo
Code overview
Built on
Microsoft XNA
platform
Platformer
Jump from orb
to orb
Soft-body
Main gameplay objects
HappyFu
Levels
nBlobGa
me
Level
Level
Items
Item
Item
Options
Components
Amoeba
(player)
Orb
Block
Lecture 11
Sorting 1
EECS-311
The 1900 US Census
Collect information
about every person
in the united states
Sex
Address
Race
Etc.
How many people
live in each state?
Age
Generate statistics
Name
How many elderly
are there in a given
neighborhood?
How do
Lecture 2
Introduction to the C#
language
EECS-311
What will this do?
void main() cfw_
printf(0 , test, 1);
What will this do?
void main() cfw_
printf(0 , test, 1);
C+ isnt type safe
What will this do?
int* test() cfw_
int x = 7;
return &x;
What will t
Lecture 16
Path finding using dynamic
programming
EECS-311
http:/xkcd.com/835/
All points shortest-path
Dijkstras algorithm is cool, but what
if you need to do alotof route finding
in the same graph?
Memoizing
One thing you
could do is to save
the shortes
Lecture 12
Sorting 2
EECS-311
Why is sorting hard?
Partitioning
Comparing one
element to all the
others lets us
divide the array
into the elements
less than,
greater than,
and equal to the
original element
pivot
9
3
less than pivot
(but not sorted)
7
4
8
1. Imagine a stack implemented using an array. When the array becomes full, its needs to
be grown by copying over elements into a new larger array. Say that inserting into the
array costs 1, taking an element out of the array costs 1, and the cost of resi
EECS-311 Spring 2013 Practice Quiz 1
Answer the following questions as best you can. When writing code, you may not use any built-in
sequence types other than arrays. In other words: if you need to use linked-list
Lecture 1
Mathematical preliminaries
EECS-311
Sets
Since the early
20th century, most
of mathematics
has been
described in terms
of set theory
Common
vocabulary for
describing a wide
Sets
Unordered
collections of
elements
Any objects you
might want to thi
ImplementingQueuesandDeques
Summary
For this assignment, you should implement the following classes
Array-based queues
Linked-list-based queues
Deques using a doubly-linked list
We have provided you with:
The skeletons of the classes. These include the de
Exercise2:Asimpleinterpreter
Out: Satuday, April 25
Due: Friday, May 1, 12 noon
Important:pleaseread
We would like to remind you that the following are considered cheating for this class:
Modifying the test cases so as to cause you program to pass the tes
Lecture 13
Graphs and graph search
EECS-311
Graphs
Informally, a graph
is a network of
objects connected
by lines or arrows
The objects are
called nodes or
vertices and the
lines are called
edges
Graphs
Note: you can also think of a digraph as a relation
Lecture 10
Hash tables
EECS-311
Dictionaries
A.k.a. associative
array, map,
mapping
Data structure that
holds associations
between pairs of
objects called keys
and values
Simplified interface
(well talk more about
dictionaries later):
dict.Store(key,
valu
Lecture 15
Applications of priority queues
EECS-311
http:/xkcd.com/835/
Priority queues
Like normal
queues
Objects wait in
line to be
processed
However, items
have an
associated
numeric priority
Priority specified
Priority queues
Like normal
queues
Object
Lecture 5
Tree walks
and tree representations
EECS-311
Remember trees?
Trees
A tree is a graph
in which any pair
of nodes has
exactly one path
between them
Trees
In computer
science, we
usually think of
trees as having a
distinguished
node call the root
R
EECS-311 Spring 2013 Practice Quiz 1
Answer the following questions as best you can. When writing code, you may not use any built-in
sequence types other than arrays. In other words: if you need to use linked-list
EECS 311 Practice Quiz 2 Solutions
Question 1
Consider the following sort algorithm:
Sort(array)
T = make an empty red/black tree
for each element e in array
add e to T
for i=0 to array.length-1
e = T.FindMinimum
T.Remove(e)
array[i] = e
What is the time
EECS 311 Practice Quiz 2
Question 1
Consider the following sort algorithm:
Sort(array)
T = make an empty red/black tree
for each element e in array
add e to T
for i=0 to array.length-1
e = T.FindMinimum
T.Remove(e)
array[i] = e
What is the time complexity
Introduction to
Data Structures and
Algorithms EECS
Ian Horswill,
Department
Introduction to
Data Structures and
Algorithms
What do we study
when we study
algorithms?
We find solutions to
computational problems
What do we study
when we study
algorithms?
P
Lecture 14
Heaps and priority queues
EECS-311
Queues
Simplified
sequence data
structure
Insertions only at
the end (tail)
Deletions only
from the
beginning
(head)
Priority queues
Like normal
queues
Objects wait in
line to be
processed
However, items
have
1. Say you have a complete tree, like the one below. Write an algorithm to convert
this into a min-heap (represented in its tree form).
You are free to use the following functions:
GetListOfNodesInLevel(int i) returns
Lecture 1
Mathematical preliminaries
EECS-311
Administrivia
Weve had a few drops, so if you are waiting to
register, contact permissions@eecs.northwestern.edu
and with luck we should be able to let you in
Office hours will be announced Friday
In the me
Lecture 17
Dynamic set partitions
and the union-find algorithm
EECS-214
Set partitions
Division of elements of a set
into disjoint groups
Formally, given a set , a
partition = cfw_ 1 , , is
i.e. for all ,
A set of non-empty subsets of S
Every elem
EECS 214
Fall 2016
HW4: Union-Find and MST
Due: Thursday, November 17, at 11:59 PM, via Canvas
You may work on your own or with one (1) partner.
For this assignment you will implement the union-nd data structure with
path compression and weighted union (W
EECS 214
Fall 2016
HW1: Three Dictionaries
Due: Thursday, October 13, at 11:59 PM, via Canvas
You may work on your own or with one (1) partner.
The dictionary is a common abstract data type for representing a table of
key-value pairs. For example, suppose
EECS 214
Fall 2016
HW2: Graphs
Due: Thursday, October 27, at 11:59 PM, via Canvas
You may work on your own or with one (1) partner.
For this assignment you will implement an API for weighted, undirected
graphs; then you will use this API to implement a si
EECS 214
Fall 2016
HW3: Binary Heaps
Due: Thursday, November 3, at 11:59 PM, on Canvas
You may work on your own or with one (1) partner.
In this assignment, you will implement a xed-size binary heap. The structure of the heap is already dened for you in b
#lang dssl
#|
HW3: Binary Heaps
EECS 214, Fall 2016
Due: Thursday, November 3, at 11:59 PM, on Canvas
* You may work on your own or with one (1) partner. *
|#
; An [Ord X] is a function [X X -> Boolean]
; Interpretation: a total order on X
; A [Heap-of X]