TOPOLOGICAL SORT
Ayman Hajja, PhD
TOPOLOGICAL SORT
Topological sort/ordering is an
ordering of a graph such that
before visiting any given node v,
all nodes pointed to that node v
have to be visited.
For example, before we visit B, we
must visit A and C;

MERGE SORT
Ayman Hajja, PhD
MERGE SORT
Merge Sort is a sorting algorithms that uses the Divide-and-conquer
algorithm design paradigm.
Divide-and-conquer algorithms work as follows:
1. Problem is divided into several subproblems of the same type,
ideally a

SOLUTION TO FAKE COIN
PUZZLE
Ayman Hajja, PhD
FAKE COIN PROBLEM
Fake coin problem. Say you have x number of coins (or marbles), one of
which is fake. The fake coin is assumed to be lighter than the real ones.
You also have a scale. How would you go about

BINARY SEARCH & THE FAKE
COIN PUZZLE
Ayman Hajja, PhD
1
BINARY SEARCH PROBLEM
Given a list of *sorted* items, what is the best algorithm to find a
particular element?
Say I ask you to find element 12
1
2
4
6
8
9
12
30
41
44
45
2
BINARY SEARCH PROBLEM
Bina

Topic Outline Complexity Analysis & Searching
1. The Analysis Framework how we analyze the efficiency of algorithms.
a. There are two kinds of efficiency
i. Time Efficiency (Complexity) How fast an algorithm runs
ii. Space Efficiency (Complexity) How much

B-TREES PART 1
Ayman Hajja, PhD
B-TREES
Few notes about B-Trees:
1. B-Trees are self-balancing trees, they make sure that when you
add keys to it, it doesnt grow deep and stringy
2. B-Trees are not binary trees
3. B-Trees must be defined by a term called

HEAP SORT (COMPLETE)
Ayman Hajja, PhD
HEAP
Heap is a, clever, partially ordered data structure (or list)
Heap is a binary tree that exhibits the two following properties:
1. Shape property: must be complete (or essentially
complete)
2. Parental dominance:

BINARY (SEARCH) TREES,
TRAVERSAL ORDER
Ayman Hajja, PhD
BINARY TREES
Each node has at most two children
Example of binary trees is binary heaps
Many kinds of trees:
1. Perfect/Full binary tree
2. (Essentially) Complete binary tree (e.g. heap)
2
EXAMPLE OF

ORDER OF GROWTH
Ayman Hajja, PhD
1
ORDER OF GROWTH
Difference in running times on small inputs is not what really
matters
How fast the function grows, for large inputs
To calculate/compare orders of growth for functions:
1. If f(x) is a sum of several ter

B-TREES PART 2
Ayman Hajja, PhD
DELETING FROM A B-TREE
Deletion from a B-tree is more complicated than insertion, this is
because we can delete a key from any node and not just a
leaf.
DELETING FROM A B-TREE
In this set of slides, we will study all differ

QUICK SORT
Ayman Hajja, PhD
QUICK SORT
Similar to Merge Sort, Quick Sort is a sorting algorithms that uses the
divide-and-conquer algorithm design paradigm.
Recall that divide-and-conquer algorithms work as follows:
1. Problem is divided into several subp

HEAP SORT (COMPLETE)
Ayman Hajja, PhD
HEAP
Heap is a, clever, partially ordered data structure (or list)
Heap is a binary tree that exhibits the two following properties:
1. Shape property: must be complete (or essentially
complete)
2. Parental dominance:

Homework 4 Due 11:55PM 05/05/2016
Submit to moodle
Question (1) Use Binary Search to find 5 in a list: 1, 3, 5, 7, 9, 11, 13, 20, 70, 140,290
A list of numbers: 6, 2, 4, 5, 3, 1, 7 will be used in the follow questions (2-7).
Question (2) Bubble Sort
Quest

A-Star Notes
Open List- Available moves. Nodes weve discovered but not yet visited. Min Heap.
Closed List- Nodes weve visited and wont return to. Hash Table/dictionary.
For each node, maintain the following pieces of information:
F- The total score for a

Midterm Study Guide
ITCS 2215 Design and Analysis of Algorithms
Your midterm is essentially divided into three (3) sections. Each section tests your knowledge of the material in a
different and increasingly difficult way. The first section is basic knowle

ITCS 2215 Design and Analysis of Algorithms
Homework #1
Lena Vawter
1. Answer the two questions below. Show you work where applicable:
a. Imagine that after washing 5 distinct pairs of socks, you discover that two socks are
missing! Of course, you would l

Design and Analysis of Algorithms ITCS 2215
Recursion Practice Problems
Instructions
For the following questions, determine the value returned as a result of the given method call.
1. public static int quest (int x, int y)
cfw_
if (x < y)
return x;
else
r

ITCS-2215 (2015 Fall) Course Project Description
A group project will require students to apply the skills developed in the earlier sessions of the course to
the development of a proposal. Teams will be made up of 1-3 students. Each team will be required

SELECTION SORT & BUBBLE
SORT
Ayman Hajja, PhD
SORTING PROBLEM
Given a list of items, what is the best algorithm to sort the list in a
particular order (ascending or descending)? The best algorithm
is hard to guess, so lets start with a basic one!
Unsorted

BUCKET SORT I
Ayman Hajja, PhD
BUCKET SORT
What if we know, beforehand, that our 20-element list/array
contains numbers between 0 and 30?
Example:
20 22 24 1 12 19 18 14 15 5
5
3
0
6
7 23 11 9 10 9
Can we use this information to come up with a *clever* so

INSERTION SORT
Ayman Hajja, PhD
INSERTION SORT
Insertion Sort: builds the final sorted array/list one item at a time.
Example:
The first element (3) is the sorted array (so far)
3
7
4
9
5
2
6
1
INSERTION SORT
Next we add 7 to the array and ask:
Is 7 > 3?

B-TREES PART 3
Ayman Hajja, PhD
DELETING FROM A B-TREE
In this set of slides, well study the cases that occur when
deleting from a non-leaf node
DELETING FROM A B-TREE
In this set of slides, well study the cases that occur when
deleting from a non-leaf no

PROBLEM WITH BINARY SEARCH
TREES
Ayman Hajja, PhD
PROBLEM WITH BINARY SEARCH
TREES
Searching (or adding and deleting) from a Binary Search Tree is only
efficient when the tree is balanced
Example of a perfectly balanced binary tree:
PROBLEM WITH BINARY SE

PLANAR GRAPHS AND OTHER APPLICATIONS/
PROBLEMS FROM GRAPH THEORY
Ayman Hajja, PhD
GRAPH APPLICATIONS: DETECT A
CYCLE. WILL SOLVE NEXT WEEK
Given a graph, does it contain cycles (path that goes back to
the same node/vertex). Example:
D
A
C
B
E
Cycle exists

Week 5 Topic Outline - Searching Algorithms
1
Homework #4 Solution:
2
Exhaustive Search
a Many problems require finding an element with a special property in a given domain which grows
exponentially with each increase in size.
b These problems typically a

Final Exam Study Guide
ITCS 2215 Design and Analysis of Algorithms
Your final is essentially divided into three (3) sections. Each section tests your knowledge of the material in a different
and increasingly difficult way. The first section is basic knowl

Design and Analysis of Algorithms ITCS 2215
Program Assignment #2
Instructions
Write a program that correctly implements both the Quicksort and Mergesort algorithms. The program
should generate an array of 500 random numbers in the 1-100 range. The progra

Week 4 Topic Outline - Sorting Algorithms
1
Problem given a list of n orderable items, rearrange them in ascending order.
a Forget everything that you know about sorting algorithms and think for a moment about the most
straightforward method for solving t

INTRODUCTION TO GRAPHS
Ayman Hajja, PhD
INTRODUCTION TO GRAPHS
Points with connections!
Two categories: directed graphs & undirected graphs
2
GRAPHS REPRESENTATION
Complete graph is a graph with every edge connected to every
other edge. TSP could be depic

Notes about arrays and linked-lists
Page 1! of 3!
We know by now that arrays are stored contiguously in the RAM,
and linked-lists are not. As a result of having dierent data
structures, some operations are easier (or rather faster)
implemented than others

Students,
In this coding assignment, you will be asked to write Java code to read a text file (input.txt) of a
graph represented as an adjacency list. Example:
A, 7, B, 9, C
B, 1, C
C, 8, E, 2, F
D, 1, E, 3, G
E, 3, G
F, 3, D, -3, H
H, 6, G
K, 3, H, -1, F