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
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
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
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
Reci
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
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 conque
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
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.
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.m
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
Introd
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 Algori
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
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 field
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 operat
Fundamental Algorithms
Courant, Fall 2017
Homework 13
Instructor: Amir Shpilka
Due Date: not for submission
A problem is NP-hard if a polynomial time algorithm for it implies that NP is in P. A proble
10
Example 1:
A
0A1|
Language where it produces equal number of 0s followed by equal number
of 1s.
Why cannot this be represented by regular expression?
Example 2:
Give CFG for strings containing o
10/27/2017
Regex Cheat Sheet
Fundamentals
Black Belt Program
Regex in Action
Humor & More
Ask Rex
Quick-Start: Regex Cheat Sheet
The tables below are a reference to basic regex. While reading the rest
Fundamental Algorithms
Courant, Fall 2017
Homework 12
Instructor: Amir Shpilka
Due Date: Wed Dec 13, 11:55pm
1. (5 points) In a directed graph G = (V, E), each edge (u, v) E has an associated independ
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
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 arr
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 Comp
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
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 e