Using Templates to Introduce Time Efficiency Analysis in an Algorithms Course

Size: px
Start display at page:

Download "Using Templates to Introduce Time Efficiency Analysis in an Algorithms Course"

Transcription

1 Using Templates to Introduce Time Efficiency Analysis in an Algorithms Course Irena Pevac Department of Computer Science Central Connecticut State University, New Britain, CT, USA Abstract: We propose introducing algorithm time efficiency analysis by utilizing a set of template examples that illustrate the following seven basic time performance complexity categories: log n, n, n log n, n 2, n 3, a n, and n!. The complexity category of some function f(n) is the set of all functions that have the same asymptotic growth as f(n), which is denoted Ө(f(n)). The template examples are simple, their time efficiency analysis is not mathematically intensive, and they correspond to various algorithms. Both iterative and recursive algorithm templates are discussed. In addition, we provide template modifications that do not affect asymptotic growth. Modified templates remain in the same complexity category. Finally, we list several problems for which algorithm time performance belongs to a given complexity category. We argue that the approach of using templates and their transformations not only complements the introduction to time efficiency analysis, but also can improve understanding of this traditionally difficult topic in an Algorithms course. Its advantage is that it sheds some light as to which part or steps of the algorithm affect its run time the most. The template approach also provides flexibility for reaching the appropriate level of in depth discussion suitable for particular learner's background. Keywords: Algorithms, Time Performance Analysis, Teaching 1 Introduction Algorithm time efficiency is an important topic in an algorithms course. This paper discusses the mathematical approach to analyze time efficiency which is independent of the implementation and machine performance details and is used in algorithm course textbooks [1] to [8], [10], and [11]. Most textbooks introduce formal analysis with O, o, Ө, ω, and Ω, and illustrate growth rates functions: log n, n, n log n, n 2, n 3, a n, and n! by displaying their values for different values of n, and by displaying pictures of plotted functions together to provide comparison. The introduction is then typically followed by detailed time performance analysis of several algorithms. The students in an algorithms course often experience difficulty understanding formal analysis of mathematically involved advanced algorithms from various domains and design types. We believe that: 1) learning templates for each of the seven basic complexity categories; 2) learning which modifications of templates produce results that still remain in the same complexity category; and 3) practicing time efficiency analysis of simple algorithms for each complexity category should be done before starting with mathematically intensive analysis of algorithms that are difficult to grasp. This also smooths the transition into studying how to group algorithms by their design type and their domain. We strongly believe that this approach will improve learning the traditionally difficult topic of time efficiency analysis. 2 Templates for the seven basic complexity categories In the next subsections we discuss several templates used in many simple problems to analyze algorithms that belong to the following seven basic complexity categories: log n, n, n log n, n 2, n 3, a n, and n!. Both iterative and recursive algorithm templates are discussed.

2 Java based pseudo-code is used to write templates. Next, for each template, we list possible modifications that will not change its asymptotic time performance. We omit the illustration of each type of modification with concrete values and also omit proof that it does not change asymptotic growth. In the classroom, an instructor can provide the proof for one or two complexity categories and students can be divided into groups to prove the rest. At the end, for each of the seven complexity categories, we list several examples of problems that can be implemented by using one of the templates to produce an algorithm that belongs to that particular complexity category. More algorithm examples for various complexity categories can be found in [9]. In the classroom students could be asked to provide additional examples for each category. Again, work could be distributed among several student groups. 2.1 Templates for logarithmic run time Template 1 for (i=1; i<=n; i=i*2) Variations for template 1 include one or more of the following: 1) control variable i can be initialized to start at any nonnegative constant instead of starting at 1; 2) performing one basic operation in the loop can be replaced with performing any constant number of basic operations; and 3) control variable i can be multiplied by any other positive constant c in place of 2. Template 2 for (i=n; i>=1; i=i/2) Variations for template 2 include one or more of the following: 1) condition to stop looping can have control variable i greater than or equal to a nonnegative constant; 2) performing one basic operation in the loop can be replaced with performing any constant number of basic operations; and 3) control variable i can be divided by any positive constant c instead of 2. Template 3 LogRec(int n) if (n==1) { LogRec(n/2) } Variations for template 3 include one or more of variable n has one or more of given initial constant values; 2) performing one basic operation can be replaced with performing any constant number of basic operations either in the base case or in the recursive step part; and finally, 3) a recursive call can be made with variable n reduced by any positive constant factor c instead of 2. Obviously, it must be provided that base case is reached. The following simple algorithms with logarithmic time performance can be used to illustrate the above template examples: 1) determine the number of digits in binary representation of a given decimal number n; 2) determine the number of digits of a given integer number n; 3) convert base ten (decimal) number n into base 2 (or base 3, or base 8, or any other constant); 4) calculate a raised to the power of n based on formula a n = 1 if n=1, a n = a n/2 *a n/2 if n>1, and n is even, and a n = a * a n/2 *a n/2, otherwise; 5) print recursively letter "A" log b n times; 6) for given integer number n return the string of digits representing number n in base 3; 7) binary search for worst case (unsuccessful search); and 8) display the digits of a given positive integer n in reverse order.

3 2.2 Templates for linear run time Template 4 values; 2) performing one basic operation can be replaced with performing a constant number of basic operations in the base case or in the recursive step part; and finally, 3) recursive call can be made with variable n decreased by any positive constant c instead 1, provided that base case is reached.. Variations for template 4 include one or more of the following: 1) control variable i can be initialized to start at any nonnegative constant; 2) performing one basic operation in the loop can be replaced with performing any constant number of basic operations; and 3) control variable i can be increased by any positive constant c instead of 1. Template 5 for (i=n; i>=1; i=i-1) Variations for template 5 include one or more of the following: 1) the initial value for variable i can be n + constant (positive or negative) instead of n; 2) condition to stop looping can have control variable i greater than or eaqual to any positive constant; 3) performing one basic operation in the loop can be replaced with performing any constant number of basic operations; and 4) control variable i can be decreased by any positive constant c instead of 1. Template 6 LinearRec(int n) if n=1 { LinearRec(n-1) } Variations for template 6 include one or more of variable n has one or more of given constant Template 7 LinearRec(int n) if n>1 { LinearRec(n/2) LinearRec(n/2) } Variations for template 7 include one or more of variable n has one or more given constant values; 2) performing one basic operation can be replaced with performing any constant number of basic operations in the base case or in the recursive step part; 3) the order of performing one or more basic operations and making two recursive calls to sub-problems can be any permutation of those three steps; 4) several basic operations can be done before, in between, or after the two recursive calls; and finally, 5) recursive calls can be made with variable n reduced by another positive constant factor c instead of 2. Template 8 LinearRec(int n) if n>1 { LinearRec(n/3) LinearRec(n/3) LinearRec(n/3) } Variations for template 7 include one or more of variable n has one or more of given constant values; 2) performing one basic operation can be replaced with performing any constant number of basic operations in the base case or in the recursive step part before, after, or in

4 between any two of the three recursive calls to sub-problems; 3) a constant number k of recursive calls can be made instead of three calls, where each recursive sub-problem has variable n reduced by factor k. The following simple algorithms with linear time performance can be used to illustrate the above discussed template examples 4-7: 1) determine the sum of first n numbers; 2) determine the sum of first n squares; 3) determine the sum of first n cubes; 4) determine the sum of array components; 5) determine the harmonic sum; 6) determine the largest array component; 7) determine the index of the largest array component; 8) perform a linear search for a given key in the array with n components; 9) calculate a raised to the power of n based on the formula a n = 1 if n=1, and a n = a n/2 *a n/2 if n>1 and nis even, and a n = a * a n/2 *a n/2 otherwise, where two identical recursive calls to subproblems of size n/2 are made in the code; and 10) print letter "A" n times. 2.3 Templates for n - log n run time Template 9 for (j=1; j<=n; j=j*2) Variations for template 9 include one or more of the following: 1) control variable i of the outer loop can be initialized to start at any nonnegative constant instead of starting at 1; 2) performing one basic operation in the inner loop can be replaced with performing any constant number of basic operations; 3) control variable i can be increased by any positive constant instead of being increased by 1; 4) control variable j can be initialized to any positive constant; and 5) control variable j can be multiplied by another positive constant c instead of being multiplied by 2. Finally, since the two loops are not correlated they can be interchanged without affecting the time performance. Template 10 N_Log_N_Rec(int n) { N_Log_N_Rec( n/2 ) N_Log_N_Rec( n/2 ) Perform n basic operations } Variations for template 10 that do not affect asymptotic time performance include one or more of the following: base case might be one of more values for n that are constant. For such base case values any constant number of basic operations can be performed. During the recursive step the basic operation can be performed an+b times where a and b are constants. Those basic operations can be performed before, after or in between the two recursive calls of size n/2. Template 11 N_Log_N_Rec(int n) { N_Log_N_Rec( n/4 ) N_Log_N_Rec( n/4 ) N_Log_N_Rec( n/4 ) N_Log_N_Rec( n/4 ) Perform n basic operations } Variations for template 11 that do not affect asymptotic time performance include one or more of the following: 1) base case might be one of more values for n that are constant. For such base case values any constant number of basic operations can be performed; 2) during the recursive step the basic operation can be performed an+b times where a and b are constants. Those basic operations can be performed before, after or in between any two of the four recursive calls of size n/4. The following algorithms with n - log n time performance can be used to illustrate the above

5 discussed template examples 9-11: 1) draw letter "A" n log n times; 2) merge sort; 3) heap sort; and 4) draw the following squares using recursive algorithm. Base case is when side length is less than or equal to a given constant. No basic operation is performed in that case. At the highest level of recursion, one rectangle centered at x,y with side length equal to n is drawn. In addition, four recursive calls are made with center coordinates shifted 2n in each of the following four directions: 1) up, left, 2) up, right, 3) down, left, and 4) down, right. Each of the four recursive calls has size n reduced by factor Templates for quadratic run time Template 12 for (j=1; j<=n; j=j+1) Template 13 for (j=i; j<=n; j=j+1) Template 14 for (j=1; j<=i; j=j+1) All variations described for a single loop for linear time are applicable for each of the two nested loops in template examples Template 15 QuadraticRec(int n) if (n>0) { do n basic operations QuadraticRec( n-1) } Variations to template 15 that preserve quadratic run time include: 1) base case and/or recursive step where several constant number of basic operations is performed; 2) a recursive call to a sub-problem with size decreased by constant value instead of n-1; 3) the order of recursive call to a sub-problem, and performing one, or performing some constant number of basic operations, can be interchanged. Template 16 QuadraticRec(int n) { QuadraticRec( n/2 ) QuadraticRec( n/2 ) QuadraticRec( n/2 ) QuadraticRec( n/2 ) Do constant number of basic operations } The following simple algorithms with quadratic time performance can be used to illustrate the above discussed template examples 12-16: 1) add all components in a given n x n matrix; 2) determine average of all components in a two dimensional array of size n x n; 3) determine the largest of all components in a two dimensional array of size n x n; 4) selection sort; 5) insertion sort; 6) bubble sort; 7) draw given letter "A" n squared times; 8) draw the squares using the following recursive algorithm: base case is when side length is less than or equal to a given constant. No basic operation is performed for the base case. At highest level of recursion, one rectangle centered at x,y with side length equal to n is drawn. In addition, four recursive calls are made with the center coordinates shifted 2n in each of the following four directions: 1) up, left, 2) up, right, 3) down, left, and 4) down, right. Each of the four recursive calls has size n reduced by factor 2; 9) draw the squares using the following recursive algorithm. Base case is when side length is less than or equal to a given constant. One basic operation is performed in that case. At the highest level of recursion, one rectangle is drawn centered at x,y with side length equal to a given constant. In addition, four recursive calls are made with center coordinates shifted 2n in each of the following

6 four directions: 1) up, left, 2) up, right, 3) down, left, and 4) down, right. Each of the four recursive calls has size n reduced by factor 2. } 2.5 Templates for cubic run time Template 17 for (j=1; j<=n; j=j+1) for (k=1; k<=n; k=k+1) Template 18 for (j=1; j<=i; j=j+1) for (k=1; k<=n; k=k+1) Variations are analogous to the variations specified for iterative quadratic templates. Template 19 CubicRec(int n) { do n squared basic operations CubicRec(n-1)} Variations to template 20 include base case for n equal to a given constant or n less than given constant and performing up to n*n basic operations. In recursive step, performing one basic operation can be replaced by performing a linear or quadratic number of basic operations. The following simple algorithms with cubic time performance can be used to illustrate the above discussed template examples 17-19: 1) add all components in a given n x n x n matrix; 2) determine the average of all components in a three dimmensional array of size n x n x n; 3) determine the largest of all components in a three dimmensional array of size n x n x n; 4) determine the lengths of the shortest paths between all pairs of vertices in a graph represented with adacency matrix (use Floyd algorithm); 5) print letter the "A" n^3 times; 6) determine the product of two n x n matrices using a brute force algorithm; 7) determine if a given three sets of cardinality n are disjoint; 8) apply Gaussian elimination to transform n x n matrix into upper triangular form; and 9) use Floyd algorithm for shortest paths between all pairs of vertices in a graph represented with adjacency matrix. 2.6 Templates for exponential run time Variations are analogous to the variations for the LinerRec example. Template 20 CubRec(int n) { Template 21 IterativeExponential(int n) limit=1 for (i=1; i<=n; i++) { for(j=1; j<= limit; j++) limit = limit * 2} Variations include: 1) starting loop variables from given constants instead of 1; or 2) ending the outer loop at n const; 3) we can replace the statement limit= limit*2 with the statement

7 limit= limit*k where k is a constant that is greater than 2. The run time will be a faster growing class but it will still be exponential k^n. for recursive algorithms only. Such learning tool could be used as a supplemental course material for Algorithms courses using several textbooks. Template 22 ExponentialRec(int n) if (n=0) { ExponentialRec( n-1 ) ExponentialRec( n-1 )} Variations include base case at n equal to or less than a given constant and performing a constant number of basic operations at base case or anywhere during the recursive step. 2.7 Templates for n factorial run time Template 23 FactorialRec(int n) if (n=1) for (int i=1; i<=n; i++) FactorialRec(n-1) The following algorithms with n factorial time performance can be used to illustrate the template example 23: 1) print all permutations for given n; 2) print all paths for traveling salesman (exsaustive search brute force algorithm); and 3) print letter "A" n factorial times. 3 Future work The above described approach could be used to design a learning tool similar to ESRATEA (Pevac, 2010) intended for learning and practicing time performance analysis of all types of algorithms. Currently, ESRATEA is designed References [1] Aho, A. V., Ullman, J. D. (1995). Foundations of Computer Science (2nd ed.). Computer Science Press. [2] Baase, S., Van Gelder, A. (2000). Computer Algorithms (3rd ed.). Addison Wesley Longman. [3] Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Clifford, S. (2007). Introduction to Algorithms (2nd ed.). MIT Press; McGraw- Hill Book Company. [4] Goodrich M., Tamassia R. (2002). Algorithm Design: Foundations, Analysis, and Internet Examples John Wiley & Sons. [5] Johnsonbaugh, R., Schaefer, M. Algorithms (2004). Pearson. [6] Levitin, A. (2007). The Design & Analysis of Algorithms (2nd ed.). Pearson- Addison Wesley. [7] McConnell, J. J. (2008). Analysis of Algorithms (2nd ed.). Jones and Bartlett Publishers. [8] Neapolitan, R., Naimipour K. (2004). Foundations of Algorithms Using Java Pseudocode Jones and Bartlett. [9] Pevac, I. ESRATEA Educational Software for Recursive Algorithm Time Efficiency Analysis WORLDCOMP'10 Proc. of the 2010 Int. Conf. on Frontiers in Education: Computer Science & Computer Engineering, (Ed. Arabnia, Clincy), Las Vegas, NV, SCREA Press, 2010, pages [10] Sedgewick, R., Wayne, K. (2011) Algorithms (4th ed.). Addison Wesley. [11] Shaffer C. (1998) A Practical Introduction to Data Structures and Algorithm Analysis Prentice Hall.

Algorithm Analysis and Design

Algorithm Analysis and Design Algorithm Analysis and Design Dr. Truong Tuan Anh Faculty of Computer Science and Engineering Ho Chi Minh City University of Technology VNU- Ho Chi Minh City 1 References [1] Cormen, T. H., Leiserson,

More information

Algorithmic Analysis. Go go Big O(h)!

Algorithmic Analysis. Go go Big O(h)! Algorithmic Analysis Go go Big O(h)! 1 Corresponding Book Sections Pearson: Chapter 6, Sections 1-3 Data Structures: 4.1-4.2.5 2 What is an Algorithm? Informally, any well defined computational procedure

More information

arxiv: v3 [cs.ds] 18 Apr 2011

arxiv: v3 [cs.ds] 18 Apr 2011 A tight bound on the worst-case number of comparisons for Floyd s heap construction algorithm Ioannis K. Paparrizos School of Computer and Communication Sciences Ècole Polytechnique Fèdèrale de Lausanne

More information

PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS

PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS Lecture 03-04 PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS By: Dr. Zahoor Jan 1 ALGORITHM DEFINITION A finite set of statements that guarantees an optimal solution in finite interval of time 2 GOOD ALGORITHMS?

More information

The p-sized partitioning algorithm for fast computation of factorials of numbers

The p-sized partitioning algorithm for fast computation of factorials of numbers J Supercomput (2006) 38:73 82 DOI 10.1007/s11227-006-7285-5 The p-sized partitioning algorithm for fast computation of factorials of numbers Ahmet Ugur Henry Thompson C Science + Business Media, LLC 2006

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms About the course (objectives, outline, recommended reading) Problem solving Notions of Algorithmics (growth of functions, efficiency, programming model, example analysis)

More information

Lecture 1. Introduction

Lecture 1. Introduction Lecture 1 Introduction 1 Lecture Contents 1. What is an algorithm? 2. Fundamentals of Algorithmic Problem Solving 3. Important Problem Types 4. Fundamental Data Structures 2 1. What is an Algorithm? Algorithm

More information

Advanced Algorithms and Data Structures

Advanced Algorithms and Data Structures Advanced Algorithms and Data Structures Prof. Tapio Elomaa tapio.elomaa@tut.fi Course Prerequisites A seven credit unit course Replaced OHJ-2156 Analysis of Algorithms We take things a bit further than

More information

Plan of the lecture. Quick-Sort. Partition of lists (or using extra workspace) Quick-Sort ( 10.2) Quick-Sort Tree. Partitioning arrays

Plan of the lecture. Quick-Sort. Partition of lists (or using extra workspace) Quick-Sort ( 10.2) Quick-Sort Tree. Partitioning arrays Plan of the lecture Quick-sort Lower bounds on comparison sorting Correctness of programs (loop invariants) Quick-Sort 7 4 9 6 2 2 4 6 7 9 4 2 2 4 7 9 7 9 2 2 9 9 Lecture 16 1 Lecture 16 2 Quick-Sort (

More information

Advanced Algorithms and Data Structures

Advanced Algorithms and Data Structures Advanced Algorithms and Data Structures Prof. Tapio Elomaa Course Basics A new 7 credit unit course Replaces OHJ-2156 Analysis of Algorithms We take things a bit further than OHJ-2156 We will assume familiarity

More information

CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK

CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Page 1 UNIT I INTRODUCTION 2 marks 1. Why is the need of studying algorithms? From a practical standpoint, a standard set of algorithms from different

More information

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016 CSCE 321/3201 Analysis and Design of Algorithms Prof. Amr Goneid Fall 2016 CSCE 321/3201 Analysis and Design of Algorithms Prof. Amr Goneid Course Resources Instructor: Prof. Amr Goneid E-mail: goneid@aucegypt.edu

More information

Topic Analysis PART-A

Topic Analysis PART-A Govt. of Karnataka, Department of Technical Education Diploma in Information Science & Engineering Third Semester Subject: ANALYSIS AND DESIGN OF ALGORITHM Contact Hrs / week: Total hrs: 64 Topic Analysis

More information

SRI VENKATESWARA COLLEGE OF ENGINEERING. COURSE DELIVERY PLAN - THEORY Page 1 of 6

SRI VENKATESWARA COLLEGE OF ENGINEERING. COURSE DELIVERY PLAN - THEORY Page 1 of 6 COURSE DELIVERY PLAN - THEORY Page 1 of 6 Department of Computer Science and Engineering B.E/B.Tech/M.E/M.Tech : B.E(CSE) & B.Tech (IT) Regulation:2016 PG Specialisation : -- : I LP: CS16301 Rev. No: 00

More information

Analysis of Algorithms Part I: Analyzing a pseudo-code

Analysis of Algorithms Part I: Analyzing a pseudo-code Analysis of Algorithms Part I: Analyzing a pseudo-code Introduction Pseudo-code representation of an algorithm Analyzing algorithms Measuring the running time and memory size of an algorithm Calculating

More information

A Simplified Correctness Proof for a Well-Known Algorithm Computing Strongly Connected Components

A Simplified Correctness Proof for a Well-Known Algorithm Computing Strongly Connected Components A Simplified Correctness Proof for a Well-Known Algorithm Computing Strongly Connected Components Ingo Wegener FB Informatik, LS2, Univ. Dortmund, 44221 Dortmund, Germany wegener@ls2.cs.uni-dortmund.de

More information

DESIGN AND ANALYSIS OF ALGORITHMS

DESIGN AND ANALYSIS OF ALGORITHMS DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Module 1 OBJECTIVE: Algorithms play the central role in both the science and the practice of computing. There are compelling reasons to study algorithms.

More information

The Complexity of Algorithms (3A) Young Won Lim 4/3/18

The Complexity of Algorithms (3A) Young Won Lim 4/3/18 Copyright (c) 2015-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

More information

Outline and Reading. Analysis of Algorithms 1

Outline and Reading. Analysis of Algorithms 1 Outline and Reading Algorithms Running time ( 3.1) Pseudo-code ( 3.2) Counting primitive operations ( 3.4) Asymptotic notation ( 3.4.1) Asymptotic analysis ( 3.4.2) Case study ( 3.4.3) Analysis of Algorithms

More information

Lecture 15: Algorithms. AP Computer Science Principles

Lecture 15: Algorithms. AP Computer Science Principles Lecture 15: Algorithms AP Computer Science Principles Algorithm algorithm: precise sequence of instructions to solve a computational problem. Search for a name in a phone s contact list. Sort emails by

More information

CS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes

CS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes CS583 Lecture 01 Jana Kosecka some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes Course Info course webpage: - from the syllabus on http://cs.gmu.edu/

More information

Lecture Notes for Chapter 2: Getting Started

Lecture Notes for Chapter 2: Getting Started Instant download and all chapters Instructor's Manual Introduction To Algorithms 2nd Edition Thomas H. Cormen, Clara Lee, Erica Lin https://testbankdata.com/download/instructors-manual-introduction-algorithms-2ndedition-thomas-h-cormen-clara-lee-erica-lin/

More information

Design and Analysis of Computer Algorithm Lecture 1. Assoc. Prof.Pradondet Nilagupta Department of Computer Engineering

Design and Analysis of Computer Algorithm Lecture 1. Assoc. Prof.Pradondet Nilagupta Department of Computer Engineering Design and Analysis of Computer Algorithm Lecture 1 Assoc. Prof.Pradondet Nilagupta Department of Computer Engineering pom@ku.ac.th Acknowledgement This lecture note has been summarized from lecture note

More information

UNIT 3: ANALYSIS OF SIMPLE ALGORITHMS

UNIT 3: ANALYSIS OF SIMPLE ALGORITHMS UNIT 3: ANALYSIS OF SIMPLE ALGORITHMS Analysis of simple Algorithms Structure Page Nos. 3.0 Introduction 85 3.1 Objective 85 3.2 Euclid Algorithm for GCD 86 3.3 Horner s Rule for Polynomial Evaluation

More information

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid CSCE 20/220 Data Structures and Algorithms Prof. Amr Goneid Fall 208 / Spring 209 CSCE 20/220 DATA STRUCTURES AND ALGORITHMS Prof. Amr Goneid Instructor: Prof. Amr Goneid E-mail: goneid@aucegypt.edu Office:

More information

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018 CSCE 20/220 Data Structures and Algorithms Prof. Amr Goneid Fall 208 CSCE 20/220 DATA STRUCTURES AND ALGORITHMS Dr. Amr Goneid Course Goals To introduce concepts of Data Models, Data Abstraction and ADTs

More information

アルゴリズムの設計と解析 (W4022) 教授 : 黄潤和 広野史明 (A4/A10)

アルゴリズムの設計と解析 (W4022) 教授 : 黄潤和 広野史明 (A4/A10) アルゴリズムの設計と解析 教授 : 黄潤和 SA: (W4022) rhuang@hosei.ac.jp 広野史明 (A4/A10) fumiaki.hirono.5k@stu.hosei.ac.jp Goal 到達目標 : The objectives of this course are to make students firmly laying good foundation of data

More information

Introduction to Analysis of Algorithms

Introduction to Analysis of Algorithms Introduction to Analysis of Algorithms Analysis of Algorithms To determine how efficient an algorithm is we compute the amount of time that the algorithm needs to solve a problem. Given two algorithms

More information

6/12/2013. Introduction to Algorithms (2 nd edition) Overview. The Sorting Problem. Chapter 2: Getting Started. by Cormen, Leiserson, Rivest & Stein

6/12/2013. Introduction to Algorithms (2 nd edition) Overview. The Sorting Problem. Chapter 2: Getting Started. by Cormen, Leiserson, Rivest & Stein Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 2: Getting Started (slides enhanced by N. Adlai A. DePano) Overview Aims to familiarize us with framework used throughout

More information

Assignment 1 (concept): Solutions

Assignment 1 (concept): Solutions CS10b Data Structures and Algorithms Due: Thursday, January 0th Assignment 1 (concept): Solutions Note, throughout Exercises 1 to 4, n denotes the input size of a problem. 1. (10%) Rank the following functions

More information

CS2 Algorithms and Data Structures Note 1

CS2 Algorithms and Data Structures Note 1 CS2 Algorithms and Data Structures Note 1 Analysing Algorithms This thread of the course is concerned with the design and analysis of good algorithms and data structures. Intuitively speaking, an algorithm

More information

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency

More information

Pseudo code of algorithms are to be read by.

Pseudo code of algorithms are to be read by. Cs502 Quiz No1 Complete Solved File Pseudo code of algorithms are to be read by. People RAM Computer Compiler Approach of solving geometric problems by sweeping a line across the plane is called sweep.

More information

International Journal of Scientific & Engineering Research, Volume 4, Issue 7, July ISSN

International Journal of Scientific & Engineering Research, Volume 4, Issue 7, July ISSN International Journal of Scientific & Engineering Research, Volume 4, Issue 7, July-201 971 Comparative Performance Analysis Of Sorting Algorithms Abhinav Yadav, Dr. Sanjeev Bansal Abstract Sorting Algorithms

More information

COMP6700/2140 Recursive Operations

COMP6700/2140 Recursive Operations COMP6700/2140 Recursive Operations Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU May 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Recursive Operations

More information

Introduction to Algorithms Third Edition

Introduction to Algorithms Third Edition Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Introduction to Algorithms Third Edition The MIT Press Cambridge, Massachusetts London, England Preface xiü I Foundations Introduction

More information

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment Class: V - CE Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology Sub: Design and Analysis of Algorithms Analysis of Algorithm: Assignment

More information

PAijpam.eu A NOTE ON KNUTH S IMPLEMENTATION OF EXTENDED EUCLIDEAN GREATEST COMMON DIVISOR ALGORITHM Anton Iliev 1, Nikolay Kyurkchiev 2, Angel Golev 3

PAijpam.eu A NOTE ON KNUTH S IMPLEMENTATION OF EXTENDED EUCLIDEAN GREATEST COMMON DIVISOR ALGORITHM Anton Iliev 1, Nikolay Kyurkchiev 2, Angel Golev 3 International Journal of Pure and Applied Mathematics Volume 118 No. 1 2018, 31-37 ISSN: 1311-8080 (printed version); ISSN: 1314-3395 (on-line version) url: http://www.ijpam.eu doi: 10.12732/ijpam.v118i1.3

More information

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion Review from Lectures 5 & 6 Arrays and pointers, Pointer arithmetic and dereferencing, Types of memory ( automatic, static,

More information

Algorithm Analysis. CENG 707 Data Structures and Algorithms

Algorithm Analysis. CENG 707 Data Structures and Algorithms Algorithm Analysis CENG 707 Data Structures and Algorithms 1 Algorithm An algorithm is a set of instructions to be followed to solve a problem. There can be more than one solution (more than one algorithm)

More information

The Running Time of Programs

The Running Time of Programs The Running Time of Programs The 90 10 Rule Many programs exhibit the property that most of their running time is spent in a small fraction of the source code. There is an informal rule that states 90%

More information

CS/COE 1501

CS/COE 1501 CS/COE 1501 www.cs.pitt.edu/~nlf4/cs1501/ Introduction Meta-notes These notes are intended for use by students in CS1501 at the University of Pittsburgh. They are provided free of charge and may not be

More information

CS/COE 1501 cs.pitt.edu/~bill/1501/ Introduction

CS/COE 1501 cs.pitt.edu/~bill/1501/ Introduction CS/COE 1501 cs.pitt.edu/~bill/1501/ Introduction Meta-notes These notes are intended for use by students in CS1501 at the University of Pittsburgh. They are provided free of charge and may not be sold

More information

Position Sort. Anuj Kumar Developer PINGA Solution Pvt. Ltd. Noida, India ABSTRACT. Keywords 1. INTRODUCTION 2. METHODS AND MATERIALS

Position Sort. Anuj Kumar Developer PINGA Solution Pvt. Ltd. Noida, India ABSTRACT. Keywords 1. INTRODUCTION 2. METHODS AND MATERIALS Position Sort International Journal of Computer Applications (0975 8887) Anuj Kumar Developer PINGA Solution Pvt. Ltd. Noida, India Mamta Former IT Faculty Ghaziabad, India ABSTRACT Computer science has

More information

Organisation. Assessment

Organisation. Assessment Week 1 s s Getting Started 1 3 4 5 - - Lecturer Dr Lectures Tuesday 1-13 Fulton House Lecture room Tuesday 15-16 Fulton House Lecture room Thursday 11-1 Fulton House Lecture room Friday 10-11 Glyndwr C

More information

AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 2014

AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 2014 AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 214 Q.2 a. Design an algorithm for computing gcd (m,n) using Euclid s algorithm. Apply the algorithm to find gcd (31415, 14142). ALGORITHM Euclid(m, n) //Computes

More information

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Introduction to Algorithms Preface xiii 1 Introduction 1 1.1 Algorithms 1 1.2 Analyzing algorithms 6 1.3 Designing algorithms 1 1 1.4 Summary 1 6

More information

Algorithms and Data Structures, or

Algorithms and Data Structures, or Algorithms and Data Structures, or... Classical Algorithms of the 50s, 60s and 70s Mary Cryan A&DS Lecture 1 1 Mary Cryan Our focus Emphasis is Algorithms ( Data Structures less important). Most of the

More information

Choice of C++ as Language

Choice of C++ as Language EECS 281: Data Structures and Algorithms Principles of Algorithm Analysis Choice of C++ as Language All algorithms implemented in this book are in C++, but principles are language independent That is,

More information

Ph.D. Comprehensive Examination Design and Analysis of Algorithms

Ph.D. Comprehensive Examination Design and Analysis of Algorithms Ph.D. Comprehensive Examination Design and Analysis of Algorithms Main Books 1. Cormen, Leiserton, Rivest, Introduction to Algorithms, MIT Press, 2001. Additional Books 1. Kenneth H. Rosen, Discrete mathematics

More information

Review for Midterm Exam

Review for Midterm Exam Review for Midterm Exam 1 Policies and Overview midterm exam policies overview of problems, algorithms, data structures overview of discrete mathematics 2 Sample Questions on the cost functions of algorithms

More information

Computer Algorithms. Introduction to Algorithm

Computer Algorithms. Introduction to Algorithm Computer Algorithms Introduction to Algorithm CISC 4080 Yanjun Li 1 What is Algorithm? An Algorithm is a sequence of well-defined computational steps that transform the input into the output. These steps

More information

CS 157: Assignment 5

CS 157: Assignment 5 Problem : Printing Neatly CS 157: Assignment 5 Douglas R. Lanman 4 April 006 In a word processor or in L A TEX, one routinely encounters the pretty printing problem. That is, how does one transform text

More information

Department of Information Technology

Department of Information Technology COURSE DELIVERY PLAN - THEORY Page 1 of 6 Department of Information Technology B.Tech : Information Technology Regulation : 2013 Sub. Code / Sub. Name : CS6301 / Programming and Data Structures II Unit

More information

arxiv: v1 [cs.dm] 1 Jul 2016

arxiv: v1 [cs.dm] 1 Jul 2016 1 A Note on Extended Euclid s Algorithm arxiv:1607.00106v1 [cs.dm] 1 Jul 2016 Hing Leung Department of Computer Science New Mexico State University Las Cruces, NM 88003, USA Abstract Starting with the

More information

CSC 8301 Design and Analysis of Algorithms: Exhaustive Search

CSC 8301 Design and Analysis of Algorithms: Exhaustive Search CSC 8301 Design and Analysis of Algorithms: Exhaustive Search Professor Henry Carter Fall 2016 Recap Brute force is the use of iterative checking or solving a problem by its definition The straightforward

More information

Computer Science 210 Data Structures Siena College Fall Topic Notes: Complexity and Asymptotic Analysis

Computer Science 210 Data Structures Siena College Fall Topic Notes: Complexity and Asymptotic Analysis Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Complexity and Asymptotic Analysis Consider the abstract data type, the Vector or ArrayList. This structure affords us the opportunity

More information

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18 CS 124 Quiz 2 Review 3/25/18 1 Format You will have 83 minutes to complete the exam. The exam may have true/false questions, multiple choice, example/counterexample problems, run-this-algorithm problems,

More information

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough. Midterm Review CSE 2011 Winter 2011 17 February 2011 1 Algorithm Analysis Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough. Given

More information

Module 2: Classical Algorithm Design Techniques

Module 2: Classical Algorithm Design Techniques Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module

More information

Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang

Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Last class Review some algorithms learned in previous classes idea => pseudocode => implementation Correctness? Three sorting algorithms:

More information

Loops / Repetition Statements

Loops / Repetition Statements Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for

More information

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc.

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc. Algorithms Analysis Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc. Algorithms analysis tends to focus on time: Techniques for measuring

More information

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION 1. What is performance measurement? 2. What is an algorithm? 3. How the algorithm is good? 4. What are the

More information

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 1. O(logn) 2. O(n) 3. O(nlogn) 4. O(n 2 ) 5. O(2 n ) 2. [1 pt] What is the solution

More information

asymptotic growth rate or order compare two functions, but ignore constant factors, small inputs

asymptotic growth rate or order compare two functions, but ignore constant factors, small inputs Big-Oh 1 asymptotic growth rate or order 2 compare two functions, but ignore constant factors, small inputs asymptotic growth rate or order 2 compare two functions, but ignore constant factors, small inputs

More information

COURSEBOOK for COMPSCI.220FT Algorithms and Data Structures

COURSEBOOK for COMPSCI.220FT Algorithms and Data Structures COURSEBOOK for COMPSCI.220FT Algorithms and Data Structures A/Prof. Georgy Gimel farb Dr. Mark Wilson Mr. Andrew MacGibbon Department of Computer Science Tamaki Campus University of Auckland 2001 Contents

More information

MA/CSSE 473 Day 17. Divide-and-conquer Convex Hull. Strassen's Algorithm: Matrix Multiplication. (if time, Shell's Sort)

MA/CSSE 473 Day 17. Divide-and-conquer Convex Hull. Strassen's Algorithm: Matrix Multiplication. (if time, Shell's Sort) MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull Strassen's Algorithm: Matrix Multiplication (if time, Shell's Sort) MA/CSSE 473 Day 17 Student Questions Exam 2 specification Levitin 3 rd Edition Closest

More information

AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS JUN 2015

AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS JUN 2015 Q.2 a. Write down Euclid s algorithm for computing GCD of two nonnegative integer numbers. What does this algorithm do for a pair of numbers in which the first number is smaller than the second one? Execute

More information

You should know the first sum above. The rest will be given if you ever need them. However, you should remember that,, and.

You should know the first sum above. The rest will be given if you ever need them. However, you should remember that,, and. Big-Oh Notation Formal Definitions A function is in (upper bound) iff there exist positive constants k and n 0 such that for all. A function is in (lower bound) iff there exist positive constants k and

More information

Data Structures and Algorithms. Part 2

Data Structures and Algorithms. Part 2 1 Data Structures and Algorithms Part 2 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples displayed

More information

END-TERM EXAMINATION

END-TERM EXAMINATION (Please Write your Exam Roll No. immediately) Exam. Roll No... END-TERM EXAMINATION Paper Code : MCA-205 DECEMBER 2006 Subject: Design and analysis of algorithm Time: 3 Hours Maximum Marks: 60 Note: Attempt

More information

WYSE Academic Challenge State Finals Computer Science 2007 Solution Set

WYSE Academic Challenge State Finals Computer Science 2007 Solution Set WYSE Academic Challenge State Finals Computer Science 2007 Solution Set 1. Correct answer: C. a) PGP is for encrypting documents, traditionally used for email. b) SSH is used to gain secure access to a

More information

Sorting. There exist sorting algorithms which have shown to be more efficient in practice.

Sorting. There exist sorting algorithms which have shown to be more efficient in practice. Sorting Next to storing and retrieving data, sorting of data is one of the more common algorithmic tasks, with many different ways to perform it. Whenever we perform a web search and/or view statistics

More information

Data Structures Lecture 3 Order Notation and Recursion

Data Structures Lecture 3 Order Notation and Recursion Data Structures Lecture 3 Order Notation and Recursion 1 Overview The median grade.cpp program from Lecture 2 and background on constructing and using vectors. Algorithm analysis; order notation Recursion

More information

Data Structures and Algorithms Chapter 2

Data Structures and Algorithms Chapter 2 1 Data Structures and Algorithms Chapter 2 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples

More information

Algorithm Analysis. Gunnar Gotshalks. AlgAnalysis 1

Algorithm Analysis. Gunnar Gotshalks. AlgAnalysis 1 Algorithm Analysis AlgAnalysis 1 How Fast is an Algorithm? 1 Measure the running time» Run the program for many data types > Use System.currentTimeMillis to record the time Worst Time Average Best» Usually

More information

Outline. Computer Science 331. Desirable Properties of Hash Functions. What is a Hash Function? Hash Functions. Mike Jacobson.

Outline. Computer Science 331. Desirable Properties of Hash Functions. What is a Hash Function? Hash Functions. Mike Jacobson. Outline Computer Science 331 Mike Jacobson Department of Computer Science University of Calgary Lecture #20 1 Definition Desirable Property: Easily Computed 2 3 Universal Hashing 4 References Mike Jacobson

More information

Algorithm Analysis. Performance Factors

Algorithm Analysis. Performance Factors Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases Every algorithm has certain inputs that allow it

More information

UNIT 1 ANALYSIS OF ALGORITHMS

UNIT 1 ANALYSIS OF ALGORITHMS UNIT 1 ANALYSIS OF ALGORITHMS Analysis of Algorithms Structure Page Nos. 1.0 Introduction 7 1.1 Objectives 7 1.2 Mathematical Background 8 1.3 Process of Analysis 12 1.4 Calculation of Storage Complexity

More information

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI & Introduction to TllG DCSISFI & mmmmm Analysis of Algorithms 3RD EDITION Anany Levitin Villa nova University International Edition contributions by Soumen Mukherjee RCC Institute of Information Technology

More information

CS 3410 Ch 5 (DS*), 23 (IJP^)

CS 3410 Ch 5 (DS*), 23 (IJP^) CS 3410 Ch 5 (DS*), 23 (IJP^) *CS 1301 & 1302 text, Introduction to Java Programming, Liang, 7 th ed. ^CS 3410 text, Data Structures and Problem Solving Using Java, Weiss, 4 th edition Sections Pages Review

More information

Geometric Data Structures

Geometric Data Structures Geometric Data Structures 1 Data Structure 2 Definition: A data structure is a particular way of organizing and storing data in a computer for efficient search and retrieval, including associated algorithms

More information

Subject: Computer Science

Subject: Computer Science Subject: Computer Science Topic: Data Types, Variables & Operators 1 Write a program to print HELLO WORLD on screen. 2 Write a program to display output using a single cout statement. 3 Write a program

More information

Lecture 3. Brute Force

Lecture 3. Brute Force Lecture 3 Brute Force 1 Lecture Contents 1. Selection Sort and Bubble Sort 2. Sequential Search and Brute-Force String Matching 3. Closest-Pair and Convex-Hull Problems by Brute Force 4. Exhaustive Search

More information

Lecture 2: Getting Started

Lecture 2: Getting Started Lecture 2: Getting Started Insertion Sort Our first algorithm is Insertion Sort Solves the sorting problem Input: A sequence of n numbers a 1, a 2,..., a n. Output: A permutation (reordering) a 1, a 2,...,

More information

CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis. Aaron Bauer Winter 2014

CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis. Aaron Bauer Winter 2014 CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Aaron Bauer Winter 2014 Previously, on CSE 373 We want to analyze algorithms for efficiency (in time and space) And do so generally

More information

Elementary maths for GMT. Algorithm analysis Part II

Elementary maths for GMT. Algorithm analysis Part II Elementary maths for GMT Algorithm analysis Part II Algorithms, Big-Oh and Big-Omega An algorithm has a O( ) and Ω( ) running time By default, we mean the worst case running time A worst case O running

More information

VISUALIZING NP-COMPLETENESS THROUGH CIRCUIT-BASED WIDGETS

VISUALIZING NP-COMPLETENESS THROUGH CIRCUIT-BASED WIDGETS University of Portland Pilot Scholars Engineering Faculty Publications and Presentations Shiley School of Engineering 2016 VISUALIZING NP-COMPLETENESS THROUGH CIRCUIT-BASED WIDGETS Steven R. Vegdahl University

More information

JPROFILE102: A System for Experimental Analysis of Algorithms

JPROFILE102: A System for Experimental Analysis of Algorithms JPROFILE102: A System for Experimental Analysis of Algorithms Tanin Krajangthong and Somchai Prasitjutrakul Department of Computer Engineering Chulalongkorn University Bangkok, Thailand Abstract This paper

More information

Algorithms and Programming

Algorithms and Programming Algorithms and Programming Lecture 8 Recursion. Computational complexity Camelia Chira Course content Programming in the large Programming in the small Introduction in the software development process

More information

CS 261 Data Structures. Big-Oh Analysis: A Review

CS 261 Data Structures. Big-Oh Analysis: A Review CS 261 Data Structures Big-Oh Analysis: A Review Big-Oh: Purpose How can we characterize the runtime or space usage of an algorithm? We want a method that: doesn t depend upon hardware used (e.g., PC,

More information

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. CMSC 341 Fall 2013 Data Structures Final Exam B Name: Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. /12 TOTAL: /100 Instructions 1. This is a closed-book, closed-notes exam. 2. You

More information

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 2. O(n) 2. [1 pt] What is the solution to the recurrence T(n) = T(n/2) + n, T(1)

More information

9/10/2018 Algorithms & Data Structures Analysis of Algorithms. Siyuan Jiang, Sept

9/10/2018 Algorithms & Data Structures Analysis of Algorithms. Siyuan Jiang, Sept 9/10/2018 Algorithms & Data Structures Analysis of Algorithms Siyuan Jiang, Sept. 2018 1 Email me if the office door is closed Siyuan Jiang, Sept. 2018 2 Grades have been emailed github.com/cosc311/assignment01-userid

More information

arxiv: v1 [cs.ds] 3 Oct 2017

arxiv: v1 [cs.ds] 3 Oct 2017 ORDERED DAGS: HYPERCUBESORT MIKHAIL GUDIM arxiv:70.00v [cs.ds] Oct 07 Abstract. We generalize the insertion into a binary heap to any directed acyclic graph (DAG) with one source vertex. This lets us formulate

More information

Midterm CSE 21 Spring 2012

Midterm CSE 21 Spring 2012 Signature Name Student ID Midterm CSE 21 Spring 2012 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 _ (20 points) _ (15 points) _ (13 points) _ (23 points) _ (10 points) _ (8 points) Total _ (89 points) (84

More information

Quadratic: the time that it takes to sort an array is proportional to the. square of the number of elements.

Quadratic: the time that it takes to sort an array is proportional to the. square of the number of elements. ITEC 136 Business Programming Concepts Week 12, Part 01 Overview 1 Week 12 Overview Week 11 review Associative Arrays Common Array Operations Inserting shifting elements right Removing shifting elements

More information

Run Times. Efficiency Issues. Run Times cont d. More on O( ) notation

Run Times. Efficiency Issues. Run Times cont d. More on O( ) notation Comp2711 S1 2006 Correctness Oheads 1 Efficiency Issues Comp2711 S1 2006 Correctness Oheads 2 Run Times An implementation may be correct with respect to the Specification Pre- and Post-condition, but nevertheless

More information

Sorting Pearson Education, Inc. All rights reserved.

Sorting Pearson Education, Inc. All rights reserved. 1 19 Sorting 2 19.1 Introduction (Cont.) Sorting data Place data in order Typically ascending or descending Based on one or more sort keys Algorithms Insertion sort Selection sort Merge sort More efficient,

More information