Fundamental Algorithms, Problem Set 2
Solutions
1. Illustrate the operation of PARTITION(A,1,12) on the array
A = (13, 19, 9, 5, 12, 8, 7, 4, 11, 2, 6, 10)
(You may use either the texts program or the version given in class,
but please specify which you a
Assigment 2
1. Exercise 5-5
A line will be visible if it is uppermost at any given x-coordinate where two line meet.
This algorythm take an array A with n lines as input.
function hiddenSurfaceRemoval (A[])
var visibleLines[] /array where all visible line
Introduction to Algorithms
6.046J/18.401J
Lecture 4
Prof. Piotr Indyk
Today
Randomized algorithms: algorithms that flip coins Matrix product checker: is AB=C ? Quicksort: Example of divide and conquer Fast and practical sorting algorithm Other applicatio
Introduction to Algorithms
6.046J/18.401J
Lecture 7
Prof. Piotr Indyk
Data Structures
Role of data structures:
Encapsulate data
Support certain operations (e.g., INSERT,
DELETE, SEARCH)
What data structures do we know already ?
Yes, heap:
INSERT(x)
Introduction to Algorithms
6.046J/18.401J
LECTURE 2
Asymptotic Notation
O-, -, and -notation
Recurrences
Substitution method
Iterating the recurrence
Recursion tree
Master method
Prof. Charles E. Leiserson
Asymptotic notation
O-notation (upper bounds
Introduction to Algorithms
6.046J/18.401J
Lecture 8
Prof. Piotr Indyk
Data structures
Previous lecture: hash tables
Insert, Delete, Search in (expected) constant time Works for integers from cfw_0.mr-1 This lecture: Binary Search Trees Insert, Delete, S
Introduction to Algorithms
6.046J/18.401J
Lecture 9
Prof. Piotr Indyk
Today
Balanced search trees,
or how to avoid this
even in the worst case
1
2
3
4
5
6
Piotr Indyk and Charles E. Leiserson
Introduction to Algorithms
October 13, 2004
L9.2
Balanced sea
Introduction to Algorithms
6.046J/18.401J/SMA5503
Lecture 10
Prof. Piotr Indyk
Today
A data structure for a new problem Amortized analysis
2004 by Erik Demaine and Piotr Indyk
Introduction to Algorithms
October 18, 2004
L10.2
2-3 Trees: Deletions
12
6 1
Introduction to Algorithms
6.046J/18.401J
LECTURE 11
Amortized analysis
Dynamic tables
Aggregate method
Accounting method
Potential method
Prof. Charles E. Leiserson
How large should a hash
table be?
Goal: Make the table as small as possible, but
larg
Jirou Xu(N11646112), Homework 1, Problem 1,Page 1/2
Consider the problem of implementing insertion sort using a doubly-linked list
instead of array. Namely, each element a of the linked list has fields a.previous, a.next and
a.value. You are giving a stat
Introduction to Algorithms
6.046J/18.401J
Lecture 6
Prof. Piotr Indyk
Today: sorting
Show that (n lg n) is the best possible
running time for a sorting algorithm.
Design an algorithm that sorts in O(n) time.
Hint: different models ?
Charles E. Leisers
Introduction to Algorithms
6.046J/18.401J
LECTURE 1
Analysis of Algorithms
Insertion sort
Merge sort
Prof. Charles E. Leiserson
Course information
1.
2.
3.
4.
5.
6.
Staff
Prerequisites
Lectures
Recitations
Handouts
Textbook (CLRS)
7. Extra help
8. Regis
Fundamental Algorithms, Problem Set 3
Due Thursday, February 26, in Recitation
Well, you see, Haresh Chacha, its like this. First you have ten,
thats just ten, that is, ten to the rst power. Then you have
a hundred, which is ten times ten, which makes it
6.006 Intro to Algorithms
QUIZ 2 REVIEW NOTES
April 12, 2011
Sorting
Counting Sort
Counting sort can sort n integers in the range 0 to k in O(n + k) time. Say the unsorted n integers
are stored in array A. Counting sort works as follows:
1. Initialize cou
MCS/CS 401: Lower Bounds for Sorting
Decision Tree Model for Sorting by Comparisons
Roy M. Lowman
Summer 2010
Roy M. Lowman
MCS/CS 401: Lower Bounds for Sorting
Decision Tree Model for Sorting by Comparison
Best Case
Fewest comparisons needed to sort list
Fundamental Algorithms, Problem Set 2
Due Thursday, February 12 in Recitation
He who learns but does not think is lost. He who thinks but
does not learn is in great danger. Confucius
1. Illustrate the operation of PARTITION(A,1,12) on the array
A = (13, 1
CS 3137 Class Notes
1
What is Hashing?
1. Problem: How do you implement a spell checker using a lookup in a dictionary le. For example, there are about
25,000 words in /usr/dict/words The basic operation is to see if a word is in the list of legal words o
Introduction to Algorithms
6.046J/18.401J
LECTURE 3
Divide and conquer
Binary search
Powering a number
Fibonacci numbers
Matrix multiplication
Strassens algorithm
VLSI tree layout
Prof. Charles E. Leiserson
The divide-and-conquer
design paradigm
1.
Jirou Xu(N11646112), Homework 1, Problem 2, page 1/2
You are given two n-bit binary integers a and b.
A[0,. ,n 1] and B[0,.,n 1] in reverse, so that
These integers are stored in two arrays
and
. For example, if n = 6 and a = 000111 (7 in decimal) and b =