Csci 5454 Hw

© All Rights Reserved

29 views

Csci 5454 Hw

© All Rights Reserved

- CSE565-F08-Lec-11
- Big-O Algorithm Complexity Cheat Sheet
- DSA Assignment # 2
- Art of Programming Contest
- L01
- algorithm making
- Daniel Lemire, A Better Alternative to Piecewise Linear Time Series Segmentation, SIAM Data Mining 2007, 2007.
- Lec-2,3 Time Complexity
- Departmental It Manager
- Lab 10
- Haskell Notes for Professionals ElSaber21.Com
- Amortized Analysis
- Applied Data Structures Chapter 1 Algorithm
- Contention Resolution with Heterogeneous Job Sizes
- Google Guide
- Algorithms - Chapter 3 Bruteforce
- pset3
- wipro1
- Lecture 2 & 3 Unit Commitment and ELD
- Primary Research Report

You are on page 1of 10

Problem Set #1

Due: Wed, Feb 4th

(in which case f = (g)).

(a) f(n) = n1.01, g(n) = n

(b) f(n) = lg n, g(n) = ln n

(c) f(n) = 2n, g(n) = 3n

2. The text spends a lot of time talking about fib(200). Compute this number exactly

using Python. Submit your code listing along with the value of fib(200), on paper.

3. Consider the following Python function:

def find(a, target):

x = 0

y = len(a)

while x < y:

m = (x+y)/2

if a[m] < target:

x = m+1

elif a[m] > target:

y = m

else:

return m

return -1

Suppose list a has n elements and is sorted. Using () notation, what is the best case

running time as function of n? Using () notation, what is the worst case running

time as function of n?

4. Modify the find function from problem 4 by changing the 5th line from m =

(x+y)/2 to m = (2*x+y)/3; now answer the same questions given in problem 3.

5. Consider this sorting algorithm, written in Python:

def bsort(a):

swapped = True

while swapped:

swapped = False

if a[i] > a[i+1]:

a[i], a[i+1] = a[i+1], a[i]

swapped = True

(b) What is the shape of the best-case input?

(c) Using notation, what is the best-case running time of this program?

(d) What is the shape of the worst-case input?

(e) Using notation, what is the worst-case running time of this program?

6. Consider this sorting algorithm, written in Python:

import random

def luckysort(a):

sorted = False

while not sorted:

random.shuffle(a)

sorted = True

for i in range(0, len(a)-1):

if a[i] > a[i+1]:

sorted = False

(a) Is this sort randomized or deterministic?

(b) What is the shape of the best-case input?

(c) Using notation, what is the best-case running time of this program?

(d) What is the shape of the worst-case input?

(e) Using notation, what is the worst-case running running time of this program?

(f) Using notation, what is the expected running time of this program?

Problem Set #2

Due: 1pm, Feb 18th, 2015

quick method for doing this. (Hint: convert the number to base-100 by grouping pairs

of digits together.) Justify your answer.

2. Text problem 1.12. Use only paper. Show your work.

3. Text problem 1.13. Use only paper. Show your work.

4. One of the largest naturally-occurring integer constants we know of

is M=808017424794512875886459904961710757005754368000000000. This is the

size of an object of mathematics that is just there (humans didn't invent it).

Just for fun, compute MMmod22015. Use a computer for this one; include source code

with your solution.

5. Text problem 1.18. Show your work.

6. Suppose I have an n-bit positive integer N stored in memory in binary, and I want

to print it. What is the running time to print N if

(a) I output N in hexadecimal?

(b) I output N in binary?

(c) I output N in unary?

Problem Set #3

Due: 1pm, Feb 25th, 2015

3. Write a python function nextprime(i) to find the next prime i. What

is nextprime(2015**50)? Include the answer along with your source code.

4. Using your code from above, write a python program that computes the average

distance from a random 100-digit integer to the nextprime after it. Use 1 thousand

samples to obtain your average. In other words, define a function getrand100() that

generates random 100-digit random positive integers and let s=getrand100(); then

compute the average value of nextprime(s)-s using 1000 samples. Include source

code with your answer.

CSCI 5454 - Algorithms - Spring 2015

Problem Set #4

2. Text problem 2.12. Justify your answer.

3. Text problem 2.17. Justify your answer.

4. Let A and B be arrays of integers. Each array contains n elements, and each array is

in sorted order (ascending). A and B do not share any elements in common. Give a

O(lg n)-time algorithm which finds the median of A union B. In other words, find the

median of the 2n elements given by putting A and B together into one array.

(Note: Remember the definition from our book (section 2.4) for the median of a list

with an even number of elements.)

5. The text doesn't implement their algorithm for Selection. Please do so. Then,

compute the median of the list of words given here using your algorithm. (Note: Use

the standard comparison for strings (just like strcmp() in C). All words in this list are

distinct.)

What is the median of the list? Run your program and show the

output.

Run your program 1000 times on the word list and compute

statistics on the number of recursive calls you make for each

run: what is the min, the max, and the average number of

calls?

Problem Set #5

1. Text problem 3.8. (If using on-line book, ignore part (c))

2. Suppose you are trying to buy a digraph from a salesman Joe. You tell Joe that your

graph cannot have any odd-length cycles, and must be strongly-connected. Joe says he

has just the thing, and he shows you just three edges of it: (a, b), (b, c) and (a, c).

Explain why Joe must be lying. (Note: there might be a LOT more edges and a LOT

more vertices, but you have to base your answer on just the three edges you can see.)

3. Text problem 3.21.

4. Text problem 3.24. Justify the correctness and running time of your algorithm.

(Note that it says dag and not digraph. If we ask the same problem about a digraph,

there is no known polynomial-time algorithm!)

5. A chain of words is a list of words where the i-th word is the (i-1)st word with one

extra character and some mixing of letters. For example, AN, TAN, RANT, TRAIN,

RETINA, NASTIER is a chain of length 6. Find the longest chain you can in

our wordlist.

In order to do this, first build a dag. The dag will consist of a node for each word (you

might want to collapse words into a single node when it makes sense to), and an edge

from word x to word y if y can follow x in a chain. Then run DFS from each source

node in the dag and keep track of the maximum depth you reach. Print out an example

chain that has maximum length (there will be a TON... just give one chain).

Please hand in your source code along with the longest chain your code found.

CSCI 5454 - Algorithms - Spring 2015

Problem Set #6

2. Text problem 4.4.

3. Text problem 4.8.

4. Text problem 4.9. (Assume that the graph has no negative-weight cycles.)

5. Text problem 4.18.

6. Text problem 4.19.

7. Consider the digraph given by this graph where each line of the file indicates an

edge. There are 77,360 nodes and 905,468 directed edges. What is the number of

nodes in the largest SCC? What is the number of edges in the largest SCC? Include

your code with your answer.

By the way, here's a rendering of the graph from above. You can see that it's fairly

tightly clustered (in other words, the shortest paths are not very long). The graph was

constructed from 77,360 users of the popular SlashDot website; each user named

Problem Set #7

2. Text problem 5.9. (omit (j))

3. Text problem 5.14.

4. Text problem 5.34

5. Text problem 6.1.

6. Text problem 6.4.

7. Text problem 6.8.

CSCI 3104 - Algorithms - Fall 2011

Problem Set #8

Due: Never

2. Text problem 6.22.

3. Text problem 6.25.

4. Text problem 6.26.

5. Text Problem 8.4 (For part d, your algorithm should run in O(|V|) not O(|V| 4) as the

pdf book says.)

7. Text Problem 8.11

8. Text Problem 8.12

- CSE565-F08-Lec-11Uploaded byRaj Kumar
- Big-O Algorithm Complexity Cheat SheetUploaded byNilesh
- DSA Assignment # 2Uploaded byMusab Hussain
- Art of Programming ContestUploaded byshilswapan
- L01Uploaded byRonak Chaudhary
- algorithm makingUploaded bypurijatin
- Daniel Lemire, A Better Alternative to Piecewise Linear Time Series Segmentation, SIAM Data Mining 2007, 2007.Uploaded byDaniel Lemire
- Lec-2,3 Time ComplexityUploaded byTaqi Shah
- Departmental It ManagerUploaded byadnansensitive5057
- Lab 10Uploaded byAndreea Luca
- Haskell Notes for Professionals ElSaber21.ComUploaded byVictor Maturana Castillo
- Amortized AnalysisUploaded byNemi C Rathore
- Applied Data Structures Chapter 1 AlgorithmUploaded byshaneshane
- Contention Resolution with Heterogeneous Job SizesUploaded byneuraltic
- Google GuideUploaded byJacky Liang
- Algorithms - Chapter 3 BruteforceUploaded byKata Vizi
- pset3Uploaded bysanketsdive
- wipro1Uploaded byakhilrs
- Lecture 2 & 3 Unit Commitment and ELDUploaded bySantosh Thapa
- Primary Research ReportUploaded byMike Smith
- Lecture 3 ComplexityUploaded byuploadingperson
- MIT6_851S12_ps5solUploaded bydjoseph_1
- MIT15_082JF10_lec01.pptUploaded byeviroyer
- Bab 3 Perancangan Sistem Tgs KlmpkUploaded bySuhendra Hadi
- 07 Sorting AlgorithmsUploaded byits4krishna3776
- SortingUploaded byTanmay sahoo
- BCA detailsUploaded byNip Chen
- data structure questionsUploaded byMayank Baiswar
- Ds ExercisesUploaded byRoy Vesey
- t09Uploaded byUmang Shukla

- Exercise #1 Report.docxUploaded byRamnarayan Shreyas
- keycat2005q.pdfUploaded byRamnarayan Shreyas
- Resume 1 Page RamUploaded byRamnarayan Shreyas
- Ram_coverUploaded byRamnarayan Shreyas
- Cover LetterUploaded byRamnarayan Shreyas
- PaperUploaded byRamnarayan Shreyas
- Internet of thingsUploaded byRamnarayan Shreyas
- Arm ReportUploaded byRamnarayan Shreyas
- USBUploaded byRamnarayan Shreyas
- WordGames - Origins 2013: SolutionsUploaded byashwinkrishnan181995
- PS_Sec1-8Uploaded byRamnarayan Shreyas
- Analitical ReasoningUploaded byapi-19621192
- aptiUploaded byRamnarayan Shreyas
- 501 Quantitative Comparison QuestionsUploaded byjnanmol007
- RDBMSUploaded byKimberly Reyes Catalonia
- Viterbi ApplicationUploaded byMohit Arora
- Rescued DocumentUploaded byRamnarayan Shreyas

- Alien Genetic Engineering -Uploaded bybasharfan
- 7plus unit 1 lesson 1 opposite quantities combine to make zeroUploaded byapi-261894355
- COBIT_1.pptUploaded bypj8714
- ScannellUploaded bywitzthum
- الحروقUploaded byHussam Majeed
- Outline of the Book of JamesUploaded bysammyborde
- Indigenous Peoples – Creating New “Borderlines“Uploaded byTimothy Gabriel
- Excel 2007 Data Analysis and Business Modelling PDFUploaded byJessi
- California Mathematics Grade 2Uploaded byZapus Le
- Roman Theatre Webquest - Use for StudentsUploaded byAmy Taipale Canfield
- 2011_y_Practitioner ReviewClinical Applications OfUploaded byAna Charfén-Norma
- Full Publication Myths and Realities 5th Ed 2013Uploaded bypilogger
- Geologic TimeUploaded byAnar Aliyev
- Barriers-in-Execution-of-Triage.docxUploaded byEldwinCauilan
- 0060.pdfUploaded byNOXPLC
- Nath yogisUploaded byB V Diwakar
- 05.05-Pangan v. RamosUploaded byOdette Jumaoas
- Bhagavad Gita Based Comparative ChartUploaded byHema Rawindran
- 15 Ways of Earning Rewards From AllahUploaded byazmshohel01
- জনলোকপাল বিল Jan Lokpal Bill DraftUploaded byHimjyoti Talukdar
- People v. LimUploaded byMark Devoma
- uaqafh.pdfUploaded byprotecciones
- Visual Anthropology Review of Through These EyesUploaded byJason Underwood
- NBRK0200 Installation Configuration ManualUploaded byGoran Jovanovic
- Anti AliasingUploaded byrahaf33
- Projectile Motion MCQS physicsUploaded byZamaan Haidri
- Six Sigma Template KitUploaded bytrikjoh
- Tiempos Verbales JaponesesUploaded byIgnacio Alvarez Sánchez
- sfmUploaded byPiyush Patel
- Muslim Mirror » BMP Says It Won’t Accept Election Results, Plans to File PIL in Apex Court Against ‘Misuse’ of EVMsUploaded byDada Sorde