CS161: Design and Analysis of Algorithms
Summer 2004
Problem Set #6 Solutions
General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an
CS161: Design and Analysis of Algorithms
Summer 2004
Problem Set #2 Solutions
General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an
CS161: Design and Analysis of Algorithms
Summer 2004
Problem Set #3 Solutions
General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem set, you may resubmit it for a regrade. If the error consists of more than an
CS161 Homework 4
Submit on Gradescope
Due: 13 May 2016
Handed out: 6 May 2016
Instructions: Please answer the following questions to the best of your ability. If you are asked to design
an algorithm, please describe it clearly and concisely, prove its cor
Problem Set 3: Greedy Algorithms, Minimum Spanning Trees
Due July 18th at noon.
Instructions:
Whenever we ask you to design an algorithm, we always want to see three things:
(1) Description of the algorithm; (2) an explanation/proof that the algorithm do
Recurrences, Divide and Conquer
October 7, 2014
Homework 2
Due Date: Tuesday, 14 October 2014 by end of lecture.
Whenever we ask you to design an algorithm, we always want to see three things: a description of the algorithm,
a run-time analysis, and an e
Problem Set 5: Randomized Algorithms and Hashing
Due August 1st at noon.
Instructions:
Same as before.
Problem 1. (6 points, 2 for each part) KT 13.7
7
In section 13.4, we designed an approximation algorithm to within a factor of 8 for the
MAX 3-SAT Prob
Problem Set 1: Big-oh Notation, Recurrences,
Divide-and-Conquer Algorithms
Due July 4th at noon.
Instructions:
Whenever we ask you to design an algorithm, we always want to see three things:
(1) Description of the algorithm; (2) an explanation/proof that
CS161: Design and Analysis of Algorithms
Summer 2004
Problem Set #5 Solutions
General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an
CS161: Algorithm Design and Analysis
Stanford University
Homework #4:
Due Date:
Handout # 5
Wednesday, 2 May 2012
Sorting models, hashing
Wednesday, 9 May 2012
Problem 1. Real Cost of Sorting. [40 points, 8 points per part]
As part of a homework assignmen
Problem Set 6: Dynamic Programming, Approximation
Algorithms
Due August 13th at midnight.
Instructions:
Same as before.
Problem 1. (5 points) KT 6.8
The residents of the underground city of Zion defend themselves through a combination
of kung fu, heavy a
CS161: Algorithm Design and Analysis
Stanford University
Homework #2:
Due Date:
Handout # 2
Wednesday, 18 April 2012
Divide-and-Conquer Algorithms, Recurrence Relations
Wednesday, 25 April 2012
Homework policies
For the complete set of homework policies i
CS161: Design and Analysis of Algorithms
Summer 2004
Problem Set #4 Solutions
General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an
Lecture 18, Dec 4 2014
Termination
We can terminate at phase k if, for all v, dk(v) = dk-1(v) ,
since no more changes will happen in dk(v) for larger values of k.
Terminates in n-1 phases if no negative cycles
(might terminate earlier)
Proof in the textb
Getting The Sample Executables
Before you start coding, you should make a local copy of my own solution, which is a set of
executables that comprise a fully operational MapReduce system. You can do so by typing in:
myth22:~> cp -r /usr/class/cs110/samples
CS161 Homework 0
Submit on Scoryst
Due: 10 April 2015, 12 noon
Handed out: 3 April 2015
Instructions: Please answer the following questions to the best of your ability. If you are asked to show
your work, please include relevant calculations for deriving
Greedy, DFS/BFS, MST
November 13, 2014
Homework 5
Due Date: Thursday, November 20, 2013, 12:15pm Pacic.
Whenever we ask you to design an algorithm, we always want to see three things: a description of the
algorithm, a run-time analysis, and an explanatio
Sorting, Hashing, Binary Search Trees
November 4, 2014
Homework 4
Due Date: Thursday, 6 November 2014 by end of lecture
Whenever we ask you to design an algorithm, we always want to see three things: a description of the
algorithm, a run-time analysis, a
CS161:
Design and Analysis of
Algorithms
Lecture 13
Leonidas Guibas
1
Outline
Last lecture: Augmenting data structures;
Amortized analysis
Today new topic: Graph algorithms
breadth-first search
two ways of traversing
depth-first search
topological sorting
CS161
Fall 2014
Homework Advice for Algorithms
Based on a handout by Tim Roughgarden, with edits by Keith Schwarz and Sophia Westwood
This handout contains information about the homework sets for CS161 how to approach them,
what we're looking for when gra
Selection, Heaps
October 16, 2014
Homework 3
Due Date: Thursday, 23 October 2014 by end of lecture
Whenever we ask you to design an algorithm, we always want to see three things: a description of the
algorithm, a run-time analysis, and an explanation/pro
MST, Shortest Paths, Dynamic Programming
November 21, 2014
Homework 6
Due Date: No due date, the assignment is optional and should not be submitted.
You are welcome to come to oce hours to discuss solutions.
Solutions will be distributed only at the last
CS161 Homework 0
Submit on Scoryst
Due: 10 April 2015, 12 noon
Handed out: 3 April 2015
Instructions: Please answer the following questions to the best of your ability. If you are asked to show
your work, please include relevant calculations for deriving
Congratulations! You passed!
1.
1/1
points
Next Item
3-way-Merge Sort : Suppose that instead of dividing in half
at each step of Merge Sort, you divide into thirds, sort each
third, and nally combine all of them using a three-way
merge subroutine. What is
#!/usr/bin/env python3
# -*- coding: utf-8 -*"
Created on Fri Jun 30 16:33:08 2017
@author: linglongwei
"
def is_odd(b):
return b % 2
def pow(a, b):
result = None
if b = 0:
return 1
elif b = 1:
return a
else:
result = pow(a * a, b / 2)
if is_odd(b):
retur
CS161 Homework 3
Submit on Scoryst
Due: 1 May 2015
Handed out: 24 April 2015
Instructions: Please answer the following questions to the best of your ability. If you are asked to show
your work, please include relevant calculations for deriving your answer
CS161 Homework 2
Submit on Scoryst
Due: 24 April 2015
Handed out: 17 April 2015
Instructions: Please answer the following questions to the best of your ability. If you are asked to show
your work, please include relevant calculations for deriving your ans
CS161 Lecture 13
Scribe by: Eric Huang
1
Dynamic Programming and Greedy Algorithms
Date: May 13, 2015
Dynamic Programming
Today, well continue our discussion of dynamic programming. Well show you another example problem,
and also how to take a dynamic pro
from math import *
x = int(input('x= ')
y = int(input('y= ')
def karatsuba(x,y):
# Set B = 10
B = 10
# Recursion base case
if x < 10 or y < 10:
return x*y
#
#
#
#
m
m set to be length of x or y, whichever is maximum
This can be done using logarithms with
#!/usr/bin/env python3
# -*- coding: utf-8 -*"
Created on Fri Jun 30 16:29:53 2017
@author: linglongwei
"
from math import *
x = int(input('x= ')
y = int(input('y= ')
def karatsuba(x,y):
# Set B = 10
B = 10
# Recursion base case
if x < 10 or y < 10:
retur