WRITTEN ASSIGNMENT 1 ANSWER KEY

Size: px
Start display at page:

Download "WRITTEN ASSIGNMENT 1 ANSWER KEY"

Transcription

1 CISC 65 Itrodutio Desig ad Aalysis of Algorithms WRITTEN ASSIGNMENT ANSWER KEY. Problem -) I geeral, this problem requires f() = some time period be solve for a value. This a be doe for all ase expet lg ad!, whih will be evaluated umerially. For example, F() = lg mirose = se => lg = E6 => = E6 seod miute hour day moth year etury lg E6 6E7 3.6E9 8.64E0.59E 3.5E3 3.5E E 3.60E5.30E9 7.46E 6.7E4 9.95E6 9.95E30 E6 6E7 3.6E9 8.64E0.59E 3.5E3 3.5E5 lg E6.33E8.75E9 7.8E0 7.97E 6.86E3.00E E E04.94E05.6E06 5.6E06 5.6E ! I solvig for problems lie! ad lg, umerially solvig i Exel is a aeptable approah. For example, let ell A equal ad ell A equal =FACT(A) Next, we reogize seod equals x0 6 miroseods. So, irease ell A util ell A equals x0 6. Rather tha maually hagig ell A, you ould use Exel s Goal See futio.. Exerise.-) Cost Time legth[a] for j to - do smallest j 3 - for i j + to 4 ( + )! t j =! j = " do if A[i] < A[smallest] 5 ( t! ) = the smallest i 6 " " j! (! ) ( j! ) = " j = exhage A[j] A[smallest] 7 - " ( t j! )

2 CISC 65 Itrodutio Desig ad Aalysis of Algorithms The algorithm maitais the loop ivariat that at the start of eah iteratio of the outer for loop, the subarray A[,, j-] osists of the j- smallest elemets i the array A[,, ], ad this subarray is the sorted order. After the first - elemets, the subarray A[,, -] otais the smallest - elemets, sorted, ad therefore elemet A[] must be the largest elemet. Best Case) Best-ase will our whe the array is already sorted, thus 6 will ever be exeuted. Hee the ruig time is: T() = () + () + 3 (-) + 4 ( +-)/ + 5 ( -)/ + 7 (-) T() = ( 4 / + 5 /) + ( / 5 / + 7 ) + ( ) T() = a + b + T() = Θ( ) Worse Case) Worst-ase will our whe the array is usorted i reverse order (i.e. <5, 4, 3,, >), thus 6 will our (-)/ time. Hee the ruig time is: T() = () + () + 3 (-) + 4 ( +-)/ + 5 ( -)/ + 6 ( -)/ + 7 (-) T() = ( 4 / + 5 / + 6 /) + ( / 5 / - 6 / + 7 ) + ( ) T() = a + b + T() = Θ( ) The ruig time for the algorithm is Θ( ) for all ases. 3. Exerise.-4) Modify the algorithm so it tests whether the iput satisfies some speial-ase oditio ad, if it does, output a pre-omputed aswer. The best-ase ruig time is geerally ot a good measure of a algorithm. 4. Exerise.3-)

3 CISC 65 Itrodutio Desig ad Aalysis of Algorithms Exerise.3-3) Prove by idutio that # T ) = "! T ( / ) + is ( T ( ) = lg if = if =, for > To prove by idutio, we must ) show it is true for some base ase, ) hypothesize for some value of, ad 3) show that it holds for +. Base Case: whe = => = T() = lg = lg = x =. Hypothesis Step: T ( ) = ( )lg( ) T ( ) = ( )lg( Idutive Step +: T ( ) = T ( T ( T ( ) = ) = T ( ) = Q.E.D. ) [ lg ] 6. Exerise.3-5) + (lg lg / ) ) = T ( ) + = lg + 3

4 CISC 65 Itrodutio Desig ad Aalysis of Algorithms The biary searh proedures taes a sorted array A, a value v, ad a rage [low high] of the array A, i whih to searh for the value v. ITERATIVE-BINARY-SEARCH(A, v, low, high) while low high ( low + high) / do mid! " If v = A[mid] the retur mid if v > A[mid] the low mid + else high mid - retur NIL RECURSIVE-BINARY-SEARCH(A, v, low, high) if low > high the retur NIL ( low + high) / mid! " if v = A[mid] the retur mid if v > A[mid] the retur RECURSIVE-BINARY- SEARCH(A, v, mid+, high) else retur RECURSIVE-BINARY- SEARCH(A, v, low, mid-) Based o the ompariso of v to the middle elemet i the searh rage, the searh otiues with the rage halved. 4

5 CISC 65 Itrodutio Desig ad Aalysis of Algorithms =0 = = lg T(/) T(/) T(/4) lg... T() Total: lg The depth of the tree is omputed by otig that T() ours whe T(/ )=T(), or / j =. This meas = j, or j = lg. 7. Exerise 3.-4) (a) Is + = O( )? f() = O(g()) 0 f() g() where > 0 ad > 0 Hee, 0 + where > / where > 0 0 where > 0 ad > 0 Therefore, + = O( ) Q.E.D. (b) Is = O( )? f() = O(g()) 0 f() g() where > 0 5

6 CISC 65 Itrodutio Desig ad Aalysis of Algorithms Hee, 0 where > 0 0 / where > 0 0 where > 0 0 o Now, 0 o where > 0 0 +o where > for > 0 0 for > 0 Is a otraditio so, O( ) Q.E.D. 8. Show that (-)/ is O( ) f() = O(g()) 0 f() g() where > 0 ad > 0 Hee, 0 (-)/ where > 0 ad > 0 0 /-/ where > 0 ad > 0 0 /-/4 where = /4 Hee, 0 (-)/ /4 where Therefore, (-)/ = O( ) 9. Usig "big-o" otatio, give the worst ase ruig times of the followig proedures as a futio of. proedure mystery (: iteger); var i,j,: iteger; begi for i := to - do for j := i + to do 6

7 CISC 65 Itrodutio Desig ad Aalysis of Algorithms ed for := to j do... a statemet requirig O() time Lie Pseudo ode Cost Times for i := to - do for j := i + to do j = 3 for := to j do 3! + " ( + 5)( j = 6 + +! "" = 3 ) 4... a statemet requirig O() time 4 "" = j = ( + )(! ) 3 T() = + ( + )/ + 3 ()(+5)(-)/6 + 4 ()(+)(-)/3 T() = ( ) 3 /3 + ( + 3 ) / + ( + / 5 3 /6 4 /3) T() a 3 + b + + d T() = O( 3 ) 7

COMP26120: Introducing Complexity Analysis (2018/19) Lucas Cordeiro

COMP26120: Introducing Complexity Analysis (2018/19) Lucas Cordeiro COMP60: Itroduig Complexity Aalysis (08/9) Luas Cordeiro luas.ordeiro@mahester.a.uk Itroduig Complexity Aalysis Textbook: Algorithm Desig ad Appliatios, Goodrih, Mihael T. ad Roberto Tamassia (hapter )

More information

Algorithms. Elementary Sorting. Dong Kyue Kim Hanyang University

Algorithms. Elementary Sorting. Dong Kyue Kim Hanyang University Algorithms Elemetary Sortig Dog Kyue Kim Hayag Uiversity dqkim@hayag.a.kr Cotets Sortig problem Elemetary sortig algorithms Isertio sort Merge sort Seletio sort Bubble sort Sortig problem Iput A sequee

More information

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2 Geeral remarks Week 2 1 Divide ad First we cosider a importat tool for the aalysis of algorithms: Big-Oh. The we itroduce a importat algorithmic paradigm:. We coclude by presetig ad aalysig two examples.

More information

A recurrence equation is just a recursive function definition. It defines a function at one input in terms of its value on smaller inputs.

A recurrence equation is just a recursive function definition. It defines a function at one input in terms of its value on smaller inputs. CS23 Algorithms Hadout #6 Prof Ly Turbak September 8, 200 Wellesley College RECURRENCES This hadout summarizes highlights of CLRS Chapter 4 ad Appedix A (CLR Chapters 3 & 4) Two-Step Strategy for Aalyzig

More information

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides CS583 Lecture 02 Jaa Kosecka some materials here are based o E. Demaie, D. Luebke slides Previously Sample algorithms Exact ruig time, pseudo-code Approximate ruig time Worst case aalysis Best case aalysis

More information

Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone:

Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone: Departmet of Iformatics Prof. Dr. Michael Böhle Bizmühlestrasse 14 8050 Zurich Phoe: +41 44 635 4333 Email: boehle@ifi.uzh.ch Iformatik II Midterm1 Sprig 018 3.03.018 Advice You have 90 miutes to complete

More information

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU.

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU. Sortig Algorithms Algorithms Kyuseo Shim SoEECS, SNU. Desigig Algorithms Icremetal approaches Divide-ad-Coquer approaches Dyamic programmig approaches Greedy approaches Radomized approaches You are ot

More information

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply:

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply: Departmet of Iformatics Prof. Dr. Michael Böhle Bizmühlestrasse 14 8050 Zurich Phoe: +41 44 635 4333 Email: boehle@ifi.uzh.ch AlgoDat Midterm1 Sprig 016 08.04.016 Name: Matriculatio umber: Advice You have

More information

Recurrences: Methods and Examples

Recurrences: Methods and Examples Reurrees: Methods ad Examples CSE 30 Algorithms ad Data Strutures Alexadra Stefa Uiversity of exas at Arligto Updated: 308 Summatios Review Review slides o Summatios Reurrees Reursive algorithms It may

More information

COMP285 Midterm Exam Department of Mathematics

COMP285 Midterm Exam Department of Mathematics COMP85 Midterm Exam Departmet of Mathematics Fall 010/011 - November 8, 010 Name: Studet Number: Please fiish withi 90 miutes. All poits above 100 are cosidered as bous poit. You ca reach maximal 1 poits.

More information

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions CSE 09/09 Topics i ig Data Aalytics Sprig 2017; Homework 1 Solutios Note: Solutios to problems,, ad 6 are due to Marius Nicolae. 1. Cosider the followig algorithm: for i := 1 to α log e do Pick a radom

More information

CS161 Design and Analysis of Algorithms. Administrative

CS161 Design and Analysis of Algorithms. Administrative CS161 Desig ad Aalysis of Algorithms Da Boeh 1 Admiistrative Lecture 1, April 3, 1 Web page http://theory.staford.edu/~dabo/cs161» Hadouts» Aoucemets» Late breakig ews Gradig ad course requiremets» Midterm/fial/hw»

More information

CS 332: Algorithms. Quicksort

CS 332: Algorithms. Quicksort CS 33: Aorithms Quicsort David Luebe //03 Homewor Assiged today, due ext Wedesday Will be o web page shortly after class Go over ow David Luebe //03 Review: Quicsort Sorts i place Sorts O( ) i the average

More information

ITEC 360 Data Structures and Analysis of Algorithms Spring for n 1

ITEC 360 Data Structures and Analysis of Algorithms Spring for n 1 ITEC 360 Data Structures ad Aalysis of Algorithms Sprig 006 1. Prove that f () = 60 + 5 + 1 is Θ ( ). 60 + 5 + 1 60 + 5 + = 66 for 1 Take C 1 = 66 f () = 60 + 5 + 1 is O( ) Sice 60 + 5 + 1 60 for 1 If

More information

A Probabilistic Analysis of Quicksort

A Probabilistic Analysis of Quicksort A Probabilistic Aalysis of Quicsort You are assumed to be familiar with Quicsort. I each iteratio this sortig algorithm chooses a pivot ad the, by performig comparisios with the pivot, splits the remaider

More information

Data Structures and Algorithm. Xiaoqing Zheng

Data Structures and Algorithm. Xiaoqing Zheng Data Structures ad Algorithm Xiaoqig Zheg zhegxq@fudaeduc What are algorithms? A sequece of computatioal steps that trasform the iput ito the output Sortig problem: Iput: A sequece of umbers

More information

Design and Analysis of ALGORITHM (Topic 2)

Design and Analysis of ALGORITHM (Topic 2) DR. Gatot F. Hertoo, MSc. Desig ad Aalysis of ALGORITHM (Topic 2) Algorithms + Data Structures = Programs Lessos Leared 1 Our Machie Model: Assumptios Geeric Radom Access Machie (RAM) Executes operatios

More information

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2 This Lecture Divide-ad-coquer techique for algorithm desig. Example the merge sort. Writig ad solvig recurreces Divide ad Coquer Divide-ad-coquer method for algorithm desig: Divide: If the iput size is

More information

CS / MCS 401 Homework 3 grader solutions

CS / MCS 401 Homework 3 grader solutions CS / MCS 401 Homework 3 grader solutios assigmet due July 6, 016 writte by Jāis Lazovskis maximum poits: 33 Some questios from CLRS. Questios marked with a asterisk were ot graded. 1 Use the defiitio of

More information

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia)

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia) 1 CS 332: Algorithms Liear-Time Sortig. Order statistics. Slide credit: David Luebke (Virgiia) Quicksort: Partitio I Words Partitio(A, p, r): Select a elemet to act as the pivot (which?) Grow two regios,

More information

Ch3. Asymptotic Notation

Ch3. Asymptotic Notation Ch. Asymptotic Notatio copyright 006 Preview of Chapters Chapter How to aalyze the space ad time complexities of program Chapter Review asymptotic otatios such as O, Ω, Θ, o for simplifyig the aalysis

More information

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, February 4/Tuesday, February 5

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, February 4/Tuesday, February 5 CIS 11 Data Structures ad Algorithms with Java Sprig 019 Code Sippets ad Recurreces Moday, February 4/Tuesday, February 5 Learig Goals Practice provig asymptotic bouds with code sippets Practice solvig

More information

Test One (Answer Key)

Test One (Answer Key) CS395/Ma395 (Sprig 2005) Test Oe Name: Page 1 Test Oe (Aswer Key) CS395/Ma395: Aalysis of Algorithms This is a closed book, closed otes, 70 miute examiatio. It is worth 100 poits. There are twelve (12)

More information

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN CSI 5163 (95.5703) ALGORITHM ANALYSIS AND DESIGN (3 cr.) (T) Topics of curret iterest i the desig ad aalysis of computer algorithms for graphtheoretical

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Desig ad Aalysis of Algorithms CSE 53 Lecture 9 Media ad Order Statistics Juzhou Huag, Ph.D. Departmet of Computer Sciece ad Egieerig Dept. CSE, UT Arligto CSE53 Desig ad Aalysis of Algorithms Medias ad

More information

4.3 Growth Rates of Solutions to Recurrences

4.3 Growth Rates of Solutions to Recurrences 4.3. GROWTH RATES OF SOLUTIONS TO RECURRENCES 81 4.3 Growth Rates of Solutios to Recurreces 4.3.1 Divide ad Coquer Algorithms Oe of the most basic ad powerful algorithmic techiques is divide ad coquer.

More information

Average-Case Analysis of QuickSort

Average-Case Analysis of QuickSort Average-Case Aalysis of QuickSort Comp 363 Fall Semester 003 October 3, 003 The purpose of this documet is to itroduce the idea of usig recurrece relatios to do average-case aalysis. The average-case ruig

More information

Advanced Course of Algorithm Design and Analysis

Advanced Course of Algorithm Design and Analysis Differet complexity measures Advaced Course of Algorithm Desig ad Aalysis Asymptotic complexity Big-Oh otatio Properties of O otatio Aalysis of simple algorithms A algorithm may may have differet executio

More information

Algorithm Analysis. Algorithms that are equally correct can vary in their utilization of computational resources

Algorithm Analysis. Algorithms that are equally correct can vary in their utilization of computational resources Algorithm Aalysis Algorithms that are equally correct ca vary i their utilizatio of computatioal resources time ad memory a slow program it is likely ot to be used a program that demads too much memory

More information

Analysis of Algorithms. Introduction. Contents

Analysis of Algorithms. Introduction. Contents Itroductio The focus of this module is mathematical aspects of algorithms. Our mai focus is aalysis of algorithms, which meas evaluatig efficiecy of algorithms by aalytical ad mathematical methods. We

More information

Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication

Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication Itroductio to Algorithms 6.046J/8.40J LECTURE 3 Divide ad coquer Biary search Powerig a umber Fiboacci umbers Matrix multiplicatio Strasse s algorithm VLSI tree layout Prof. Charles E. Leiserso The divide-ad-coquer

More information

Data Structures Lecture 9

Data Structures Lecture 9 Fall 2017 Fag Yu Software Security Lab. Dept. Maagemet Iformatio Systems, Natioal Chegchi Uiversity Data Structures Lecture 9 Midterm o Dec. 7 (9:10-12:00am, 106) Lec 1-9, TextBook Ch1-8, 11,12 How to

More information

Merge and Quick Sort

Merge and Quick Sort Merge ad Quick Sort Merge Sort Merge Sort Tree Implemetatio Quick Sort Pivot Item Radomized Quick Sort Adapted from: Goodrich ad Tamassia, Data Structures ad Algorithms i Java, Joh Wiley & So (1998). Ruig

More information

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials.

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials. Divide-ad-coquer algorithms Divide & Coquer Strategy: Divide the problem ito smaller subproblems of the same type of problem Solve the subproblems recursively Combie the aswers to solve the origial problem

More information

Chapter 8 Hypothesis Testing

Chapter 8 Hypothesis Testing Chapter 8 for BST 695: Speial Topis i Statistial Theory Kui Zhag, Chapter 8 Hypothesis Testig Setio 8 Itrodutio Defiitio 8 A hypothesis is a statemet about a populatio parameter Defiitio 8 The two omplemetary

More information

Chapter 2. Asymptotic Notation

Chapter 2. Asymptotic Notation Asyptotic Notatio 3 Chapter Asyptotic Notatio Goal : To siplify the aalysis of ruig tie by gettig rid of details which ay be affected by specific ipleetatio ad hardware. [1] The Big Oh (O-Notatio) : It

More information

Mathematical Foundation. CSE 6331 Algorithms Steve Lai

Mathematical Foundation. CSE 6331 Algorithms Steve Lai Mathematical Foudatio CSE 6331 Algorithms Steve Lai Complexity of Algorithms Aalysis of algorithm: to predict the ruig time required by a algorithm. Elemetary operatios: arithmetic & boolea operatios:

More information

Chapter 22 Developing Efficient Algorithms

Chapter 22 Developing Efficient Algorithms Chapter Developig Efficiet Algorithms 1 Executig Time Suppose two algorithms perform the same task such as search (liear search vs. biary search). Which oe is better? Oe possible approach to aswer this

More information

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2 Shiyao Wag CS:3330 (Prof. Pemmaraju ): Assigmet #1 Solutios Problem 1 (a) Cosider iput with me m 1, m,..., m ad wome w 1, w,..., w with the followig prefereces: All me have the same prefereces for wome:

More information

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc)

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc) Classificatio of problem & problem solvig strategies classificatio of time complexities (liear, arithmic etc) Problem subdivisio Divide ad Coquer strategy. Asymptotic otatios, lower boud ad upper boud:

More information

ALG 2.2 Search Algorithms

ALG 2.2 Search Algorithms Algorithms Professor Joh Reif ALG 2.2 Search Algorithms (a Biary Search: average case (b Biary Search with Errors (homework (c Iterpolatio Search (d Ubouded Search Biary Search Trees (i sorted Table of

More information

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis Recursive Algorithms Recurreces Computer Sciece & Egieerig 35: Discrete Mathematics Christopher M Bourke cbourke@cseuledu A recursive algorithm is oe i which objects are defied i terms of other objects

More information

Lecture 3: Asymptotic Analysis + Recurrences

Lecture 3: Asymptotic Analysis + Recurrences Lecture 3: Asymptotic Aalysis + Recurreces Data Structures ad Algorithms CSE 373 SU 18 BEN JONES 1 Warmup Write a model ad fid Big-O for (it i = 0; i < ; i++) { for (it j = 0; j < i; j++) { System.out.pritl(

More information

Analysis of Algorithms -Quicksort-

Analysis of Algorithms -Quicksort- Aalysis of Algorithms -- Adreas Ermedahl MRTC (Mälardales Real-Time Research Ceter) adreas.ermedahl@mdh.se Autum 2004 Proposed by C.A.R. Hoare i 962 Worst- case ruig time: Θ( 2 ) Expected ruig time: Θ(

More information

Algorithms Design & Analysis. Divide & Conquer

Algorithms Design & Analysis. Divide & Conquer Algorithms Desig & Aalysis Divide & Coquer Recap Direct-accessible table Hash tables Hash fuctios Uiversal hashig Perfect Hashig Ope addressig 2 Today s topics The divide-ad-coquer desig paradigm Revised

More information

Algorithms and Data Structures Lecture IV

Algorithms and Data Structures Lecture IV Algorithms ad Data Structures Lecture IV Simoas Šalteis Aalborg Uiversity simas@cs.auc.dk September 5, 00 1 This Lecture Aalyzig the ruig time of recursive algorithms (such as divide-ad-coquer) Writig

More information

On generalized Simes critical constants

On generalized Simes critical constants Biometrial Joural 56 04 6, 035 054 DOI: 0.00/bimj.030058 035 O geeralized Simes ritial ostats Jiagtao Gou ad Ajit C. Tamhae, Departmet of Statistis, Northwester Uiversity, 006 Sherida Road, Evasto, IL

More information

Model of Computation and Runtime Analysis

Model of Computation and Runtime Analysis Model of Computatio ad Rutime Aalysis Model of Computatio Model of Computatio Specifies Set of operatios Cost of operatios (ot ecessarily time) Examples Turig Machie Radom Access Machie (RAM) PRAM Map

More information

Homework 9. (n + 1)! = 1 1

Homework 9. (n + 1)! = 1 1 . Chapter : Questio 8 If N, the Homewor 9 Proof. We will prove this by usig iductio o. 2! + 2 3! + 3 4! + + +! +!. Base step: Whe the left had side is. Whe the right had side is 2! 2 +! 2 which proves

More information

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10 Merge Sort 1 / 10 Outline 1 Merging 2 Merge Sort 3 Complexity of Sorting 4 Merge Sort and Other Sorts 2 / 10 Merging Merge sort is based on a simple operation known as merging: combining two ordered arrays

More information

Model of Computation and Runtime Analysis

Model of Computation and Runtime Analysis Model of Computatio ad Rutime Aalysis Model of Computatio Model of Computatio Specifies Set of operatios Cost of operatios (ot ecessarily time) Examples Turig Machie Radom Access Machie (RAM) PRAM Map

More information

COL106: Data Structures and Algorithms (IIT Delhi, Semester-II )

COL106: Data Structures and Algorithms (IIT Delhi, Semester-II ) 1 Solve the following recurrence relations giving a Θ bound for each of the cases 1 : (a) T (n) = 2T (n/3) + 1; T (1) = 1 (Assume n is a power of 3) (b) T (n) = 5T (n/4) + n; T (1) = 1 (Assume n is a power

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Desig ad Aalysis of Algorithms Probabilistic aalysis ad Radomized algorithms Referece: CLRS Chapter 5 Topics: Hirig problem Idicatio radom variables Radomized algorithms Huo Hogwei 1 The hirig problem

More information

Lecture 5: Loop Invariants and Insertion-sort

Lecture 5: Loop Invariants and Insertion-sort Lecture 5: Loop Invariants and Insertion-sort COMS10007 - Algorithms Dr. Christian Konrad 11.01.2019 Dr. Christian Konrad Lecture 5: Loop Invariants and Insertion-sort 1 / 12 Proofs by Induction Structure

More information

Quicksort (CLRS 7) We previously saw how the divide-and-conquer technique can be used to design sorting algorithm Merge-sort

Quicksort (CLRS 7) We previously saw how the divide-and-conquer technique can be used to design sorting algorithm Merge-sort Quicksort (CLRS 7) We previously saw how the divide-and-conquer technique can be used to design sorting algorithm Merge-sort Partition n elements array A into two subarrays of n/2 elements each Sort the

More information

Analyzing Control Structures

Analyzing Control Structures Aalyzg Cotrol Strutures sequeg P, P : two fragmets of a algo. t, t : the tme they tae the tme requred to ompute P ;P s t t Θmaxt,t For loops for to m do P t: the tme requred to ompute P total tme requred

More information

CSI 2101 Discrete Structures Winter Homework Assignment #4 (100 points, weight 5%) Due: Thursday, April 5, at 1:00pm (in lecture)

CSI 2101 Discrete Structures Winter Homework Assignment #4 (100 points, weight 5%) Due: Thursday, April 5, at 1:00pm (in lecture) CSI 101 Discrete Structures Witer 01 Prof. Lucia Moura Uiversity of Ottawa Homework Assigmet #4 (100 poits, weight %) Due: Thursday, April, at 1:00pm (i lecture) Program verificatio, Recurrece Relatios

More information

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES Peter M. Maurer Why Hashig is θ(). As i biary search, hashig assumes that keys are stored i a array which is idexed by a iteger. However, hashig attempts to bypass

More information

The beta density, Bayes, Laplace, and Pólya

The beta density, Bayes, Laplace, and Pólya The beta desity, Bayes, Laplae, ad Pólya Saad Meimeh The beta desity as a ojugate form Suppose that is a biomial radom variable with idex ad parameter p, i.e. ( ) P ( p) p ( p) Applyig Bayes s rule, we

More information

Algorithm Analysis. Chapter 3

Algorithm Analysis. Chapter 3 Data Structures Dr Ahmed Rafat Abas Computer Sciece Dept, Faculty of Computer ad Iformatio, Zagazig Uiversity arabas@zu.edu.eg http://www.arsaliem.faculty.zu.edu.eg/ Algorithm Aalysis Chapter 3 3. Itroductio

More information

20.2 Normal and Critical Slopes

20.2 Normal and Critical Slopes Hdraulis Prof. B.. Thadaveswara Rao. Normal ad Critial lopes Whe disharge ad roughess are give, the Maig formula a e used for determiig the slope of the prismati hael i whih the flow is uiform at a give

More information

Bernoulli Numbers. n(n+1) = n(n+1)(2n+1) = n(n 1) 2

Bernoulli Numbers. n(n+1) = n(n+1)(2n+1) = n(n 1) 2 Beroulli Numbers Beroulli umbers are amed after the great Swiss mathematiia Jaob Beroulli5-705 who used these umbers i the power-sum problem. The power-sum problem is to fid a formula for the sum of the

More information

2 DD2458 Popup HT Solution: Choose the activity which ends first and does not conflict with earlier chosen activities.

2 DD2458 Popup HT Solution: Choose the activity which ends first and does not conflict with earlier chosen activities. DD2458, Problem Solvig ad Programmig Uder Pressure Lecture 1: Greedy algorithms ad dyamic programmig Date: 2008-09-01 Scribe(s: Marti Wedi ad Nilas Wagre Lecturer: Douglas Wiström This lecture cotais basic

More information

Digital Signal Processing. Homework 2 Solution. Due Monday 4 October Following the method on page 38, the difference equation

Digital Signal Processing. Homework 2 Solution. Due Monday 4 October Following the method on page 38, the difference equation Digital Sigal Proessig Homework Solutio Due Moda 4 Otober 00. Problem.4 Followig the method o page, the differee equatio [] (/4[-] + (/[-] x[-] has oeffiiets a0, a -/4, a /, ad b. For these oeffiiets A(z

More information

Hand Out: Analysis of Algorithms. September 8, Bud Mishra. In general, there can be several algorithms to solve a problem; and one is faced

Hand Out: Analysis of Algorithms. September 8, Bud Mishra. In general, there can be several algorithms to solve a problem; and one is faced Had Out Aalysis of Algorithms September 8, 998 Bud Mishra c Mishra, February 9, 986 Itroductio I geeral, there ca be several algorithms to solve a problem; ad oe is faced with the problem of choosig a

More information

ε > 0 N N n N a n < ε. Now notice that a n = a n.

ε > 0 N N n N a n < ε. Now notice that a n = a n. 4 Sequees.5. Null sequees..5.. Defiitio. A ull sequee is a sequee (a ) N that overges to 0. Hee, by defiitio of (a ) N overges to 0, a sequee (a ) N is a ull sequee if ad oly if ( ) ε > 0 N N N a < ε..5..

More information

ANOTHER PROOF FOR FERMAT S LAST THEOREM 1. INTRODUCTION

ANOTHER PROOF FOR FERMAT S LAST THEOREM 1. INTRODUCTION ANOTHER PROOF FOR FERMAT S LAST THEOREM Mugur B. RĂUŢ Correspodig author: Mugur B. RĂUŢ, E-mail: m_b_raut@yahoo.om Abstrat I this paper we propose aother proof for Fermat s Last Theorem (FLT). We foud

More information

Divide and Conquer II

Divide and Conquer II Algorithms Divide ad Coquer II Divide ad Coquer II Desig ad Aalsis of Algorithms Adrei Bulatov Algorithms Divide ad Coquer II 6- Closest Pair: The Problem The Closest Pair Problem Istace: poits i the plae

More information

Summation Method for Some Special Series Exactly

Summation Method for Some Special Series Exactly The Iteratioal Joural of Mathematis, Siee, Tehology ad Maagemet (ISSN : 39-85) Vol. Issue Summatio Method for Some Speial Series Eatly D.A.Gismalla Deptt. Of Mathematis & omputer Studies Faulty of Siee

More information

CS 331 Design and Analysis of Algorithms. -- Divide and Conquer. Dr. Daisy Tang

CS 331 Design and Analysis of Algorithms. -- Divide and Conquer. Dr. Daisy Tang CS 33 Desig d Alysis of Algorithms -- Divide d Coquer Dr. Disy Tg Divide-Ad-Coquer Geerl ide: Divide problem ito subproblems of the sme id; solve subproblems usig the sme pproh, d ombie prtil solutios,

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures ad Algorithms Autum 2017-2018 Outlie 1 Sortig Algorithms (cotd) Outlie Sortig Algorithms (cotd) 1 Sortig Algorithms (cotd) Heapsort Sortig Algorithms (cotd) Have see that we ca build a

More information

2. ALGORITHM ANALYSIS

2. ALGORITHM ANALYSIS 2. ALGORITHM ANALYSIS computatioal tractability survey of commo ruig times 2. ALGORITHM ANALYSIS computatioal tractability survey of commo ruig times Lecture slides by Kevi Waye Copyright 2005 Pearso-Addiso

More information

ME260W Mid-Term Exam Instructor: Xinyu Huang Date: Mar

ME260W Mid-Term Exam Instructor: Xinyu Huang Date: Mar ME60W Mid-Term Exam Istrutor: Xiyu Huag Date: Mar-03-005 Name: Grade: /00 Problem. A atilever beam is to be used as a sale. The bedig momet M at the gage loatio is P*L ad the strais o the top ad the bottom

More information

Skip Lists. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 S 3 S S 1

Skip Lists. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 S 3 S S 1 Presetatio for use with the textbook, Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Skip Lists S 3 15 15 23 10 15 23 36 Skip Lists 1 What is a Skip List A skip list for

More information

Introduction to Algorithms

Introduction to Algorithms Itroductio to Algorithms 6.046J/8.40J/SMA5503 Lecture 9 Pro. Charles E. Leiserso Biary-search-tree sort T Create a empty BST or i to do TREE-INSERT(T, A[i]) Perorm a iorder tree wal o T. Eample: A [3 8

More information

COMP26120: More on the Complexity of Recursive Programs (2018/19) Lucas Cordeiro

COMP26120: More on the Complexity of Recursive Programs (2018/19) Lucas Cordeiro COMP26120: More o the Complexity of Recursive Programs (2018/19) Lucas Cordeiro lucas.cordeiro@machester.ac.uk Divide-ad-Coquer (Recurrece) Textbook: Algorithm Desig ad Applicatios, Goodrich, Michael T.

More information

CS 5150/6150: Assignment 1 Due: Sep 23, 2010

CS 5150/6150: Assignment 1 Due: Sep 23, 2010 CS 5150/6150: Assigmet 1 Due: Sep 23, 2010 Wei Liu September 24, 2010 Q1: (1) Usig master theorem: a = 7, b = 4, f() = O(). Because f() = log b a ε holds whe ε = log b a = log 4 7, we ca apply the first

More information

POWER SERIES METHODS CHAPTER 8 SECTION 8.1 INTRODUCTION AND REVIEW OF POWER SERIES

POWER SERIES METHODS CHAPTER 8 SECTION 8.1 INTRODUCTION AND REVIEW OF POWER SERIES CHAPTER 8 POWER SERIES METHODS SECTION 8. INTRODUCTION AND REVIEW OF POWER SERIES The power series method osists of substitutig a series y = ito a give differetial equatio i order to determie what the

More information

Lecture 7: Solving Recurrences

Lecture 7: Solving Recurrences Lecture 7: Solvig Recurreces CSE 7: Data Structures ad Algorithms CSE 7 19 WI KASEY CHAMPION 1 Warm Up Writig Recurreces CSE 7 19 WI KASEY CHAMPION 2 Admiistriva HW 2 Part 1 due Friday git ruers will get

More information

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016 CS161: Algorithm Desig ad Aalysis Hadout #10 Staford Uiversity Wedesday, 10 February 2016 Lecture #11: Wedesday, 10 February 2016 Topics: Example midterm problems ad solutios from a log time ago Sprig

More information

Sx [ ] = x must yield a

Sx [ ] = x must yield a Math -b Leture #5 Notes This wee we start with a remider about oordiates of a vetor relative to a basis for a subspae ad the importat speial ase where the subspae is all of R. This freedom to desribe vetors

More information

Recurrence Relations

Recurrence Relations Recurrece Relatios Aalysis of recursive algorithms, such as: it factorial (it ) { if (==0) retur ; else retur ( * factorial(-)); } Let t be the umber of multiplicatios eeded to calculate factorial(). The

More information

Solutions 3.2-Page 215

Solutions 3.2-Page 215 Solutios.-Page Problem Fid the geeral solutios i powers of of the differetial equatios. State the reurree relatios ad the guarateed radius of overgee i eah ase. ) Substitutig,, ad ito the differetial equatio

More information

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary Recursive Algorithm for Geeratig Partitios of a Iteger Sug-Hyuk Cha Computer Sciece Departmet, Pace Uiversity 1 Pace Plaza, New York, NY 10038 USA scha@pace.edu Abstract. This article first reviews the

More information

Cache-Efficient Algorithms II

Cache-Efficient Algorithms II 6.172 Performace Egieerig of Software Systems LECTURE 9 Cache-Efficiet Algorithms II Charles E. Leiserso October 7, 2010 2010 Charles E. Leiserso 1 Ideal-Cache Model Features Two-level hierarchy. Cache

More information

B. Maddah ENMG 622 ENMG /20/09

B. Maddah ENMG 622 ENMG /20/09 B. Maddah ENMG 6 ENMG 5 5//9 Queueig Theory () Distributio of waitig time i M/M/ Let T q be the waitig time i queue of a ustomer. The it a be show that, ( ) t { q > } =. T t e Let T be the total time of

More information

Observer Design with Reduced Measurement Information

Observer Design with Reduced Measurement Information Observer Desig with Redued Measuremet Iformatio I pratie all the states aot be measured so that SVF aot be used Istead oly a redued set of measuremets give by y = x + Du p is available where y( R We assume

More information

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: The maximum-subarray problem Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: Brute force algorithm: At best, θ(n 2 ) time complexity 129 Can we do divide

More information

Chapter 4: Angle Modulation

Chapter 4: Angle Modulation 57 Chapter 4: Agle Modulatio 4.1 Itrodutio to Agle Modulatio This hapter desribes frequey odulatio (FM) ad phase odulatio (PM), whih are both fors of agle odulatio. Agle odulatio has several advatages

More information

CS161 Handout 05 Summer 2013 July 10, 2013 Mathematical Terms and Identities

CS161 Handout 05 Summer 2013 July 10, 2013 Mathematical Terms and Identities CS161 Hadout 05 Summer 2013 July 10, 2013 Mathematical Terms ad Idetities Thaks to Ady Nguye ad Julie Tibshirai for their advice o this hadout. This hadout covers mathematical otatio ad idetities that

More information

Merge Sort. Outline and Reading. Divide-and-Conquer. Divide-and-conquer paradigm ( 4.1.1) Merge-sort ( 4.1.1)

Merge Sort. Outline and Reading. Divide-and-Conquer. Divide-and-conquer paradigm ( 4.1.1) Merge-sort ( 4.1.1) Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9 7 7 2 2 9 9 4 4 Merge Sort versio 1.3 1 Outlie d Redig Divide-d-coquer prdigm ( 4.1.1 Merge-sort ( 4.1.1 Algorithm Mergig two sorted sequeces Merge-sort tree

More information

Algorithms 演算法. Multi-threaded Algorithms

Algorithms 演算法. Multi-threaded Algorithms 演算法 Multi-threaded Professor Chie-Mo James Li 李建模 Graduate Istitute of Electroics Egieerig Natioal aiwa Uiversity Outlie Multithreaded, CH7 7. Basics 7. Matrix Multiplicatio 7.3 Merge sort Leoardo Fiboacci

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 10, 2018 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. 1 /

More information

CS 171 Lecture Outline October 09, 2008

CS 171 Lecture Outline October 09, 2008 CS 171 Lecture Outlie October 09, 2008 The followig theorem comes very hady whe calculatig the expectatio of a radom variable that takes o o-egative iteger values. Theorem: Let Y be a radom variable that

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 14, 2019 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. COMP

More information

Lecture 23 Rearrangement Inequality

Lecture 23 Rearrangement Inequality Lecture 23 Rearragemet Iequality Holde Lee 6/4/ The Iequalities We start with a example Suppose there are four boxes cotaiig $0, $20, $50 ad $00 bills, respectively You may take 2 bills from oe box, 3

More information

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016 COMPSCI 330: Desig ad Aalysis of Algorithms 1/19/2016 ad 1/21/2016 Lecturer: Debmalya Paigrahi Divide ad Coquer Scribe: Tiaqi Sog 1 Overview I this lecture, a importat algorithm desig techique called divide-ad-coquer

More information

5. Solving recurrences

5. Solving recurrences 5. Solvig recurreces Time Complexity Alysis of Merge Sort T( ) 0 if 1 2T ( / 2) otherwise sortig oth hlves mergig Q. How to prove tht the ru-time of merge sort is O( )? A. 2 Time Complexity Alysis of Merge

More information

Mergesort and Recurrences (CLRS 2.3, 4.4)

Mergesort and Recurrences (CLRS 2.3, 4.4) Mergesort and Recurrences (CLRS 2.3, 4.4) We saw a couple of O(n 2 ) algorithms for sorting. Today we ll see a different approach that runs in O(n lg n) and uses one of the most powerful techniques for

More information

Matrix Multiplication. Data Structures and Algorithms Andrei Bulatov

Matrix Multiplication. Data Structures and Algorithms Andrei Bulatov Matrix Multiplicatio Data Structures ad Algorithms Adrei Bulatov Algorithms Matrix Multiplicatio 7- Matrix Multiplicatio Matrix multiplicatio. Give two -by- matrices A ad B, compute A B. k kj ik ij b a

More information