Homework1: Algorithm analysis (due on Wednesday, 1/25/17) Answers

Size: px
Start display at page:

Download "Homework1: Algorithm analysis (due on Wednesday, 1/25/17) Answers"

Transcription

1 Homework1: Algorithm analysis (due on Wednesday, 1/5/17) Answers 1. Give the growth rate of the following functions using big-theta notation. f() = + log = Θ( 3 ) f() = log + 5 = Θ( ) f() = 3 + log = Θ( ) f() = 55 = Θ(1) f() = + 100log + 5 = Θ() f() = 5log = Θ() f() =! + = Θ( ) f() = = Θ() f() = 7log + 5 = Θ(log ) f() = = Θ( 4 ) f() =! = Θ(!) f() = = Θ( ). The following functions represent running times of different algorithms:,!, log, 3,, 1, log 4,,, log, a) Sort these functions from the slowest growing function (representing the fastest algorithm) to the fastest growing function (representing the slowest algorithm). 1, log, log 4,,, log,, 3,,!, b) Are there any functions that are growing at the same rate (yes/no)? If yes, list them. Yes: log and log 4 grow at the same rate since log 4 =4log = Θ(log) 3. Here is the pseudocode for bubble sort algorithm to sort a given A list of numbers (indexing is natural, i.e. starts with 1; =A.lenght). ote: maximum number of passes (while-loop iterations) through the list is. BubbleSort(A) frequencies(worst case) frequencies(best case) frequencies( avg case) 1 done = false while done == false /+1 3 done = true 1 / 4 for i = 1 to A.length-1 (-1+1) 1 (-1+1) / (-1+1) 5 if A[i] > A[i+1] (-1) 1 (-1) / (-1) swap A[i] and A[i+1] (-1) 0 / / 7 done = false (-1) 0 / / Analyze this algorithm: ote: This algorithm has two loops where one of them, the while-loop, executes different number of iterations depending on the data values in the given list. This means that for the algorithm s execution we have best, worst, and average scenarios. 1) Find out the time function of this algorithm and its growth rate, showing detailed calculations, as done in class: (i) figure out frequencies of all lines of the pseudocode, (ii) compute the total number of steps executed by the algorithm, and obtain a formula for the running time, i.e. T() function, (iii) get the growth rate of T() function. To get the time function of the algorithm, we need to analyze the worst case, i.e. when the algorithm executes maximum number of steps. For this algorithm the worst case is when the while-loop executes max number of iterations, which is, doing max number of steps per iteration. The worst case happens when the list is sorted backward the while loop makes -1 iterations (and each iteration every check causes element-swap), and then one more iteration where no wrong pairs are detected and no swaps occur. In the worst case the frequencies of all lines will be as stated above, in the first column next to the pseudocode. T() will be obtained by adding all values in that first column: T() = 1 + (+1) (-1) = 4 + T() = O( ) 1

2 ) Analyze the bes t case scenario of this algorithm the same way you ve done analysis in bullet 1). Obtain the formula for T() function and then get its growth rate. For this algorithm the best case is when the while-loop executes min number of iterations, which is 1 (during this iteration the if-condition will never be true because otherwise it would lead to another iteration of the while-loop). The best case happens when the list is already sorted the while loop executes once where it does not detect any wrong pairs. In the best case the frequencies of all lines will be as stated above, in the second column next to pseudocode. T() will be obtained by adding all values in that second column: T() = (-1) = + 3 T() = O() 3) Analyze the average case scenario of this algorithm the same way you ve done analysis in bullet 1). Obtain the formula for T() function and then get its growth rate. For this algorithm the average case can be computed by taking the average number of iterations that the while-loop executes, doing the average number of steps per iteration. The average number of iterations of the while loop is computed as the average of all possible numbers of iterations (1 iteration, iterations,, iterations): = i=1 i (+1) = = +1 //for simplicity, it s fine to approximate Although it is not going to make a difference in the end, but to be proper, let s also consider the average number of steps executed per iteration of the nested for-loop, i.e. compute the average frequencies of lines,7 (they can execute min 0, max -1 times): ( 1) = 1 i=0 i = ( 1) = 1 //for simplicity, it s fine to approximate In average case, the frequencies of all lines will be as stated above, in the third column next to pseudocode. T() will be obtained by adding all values in that third column: T() = 1 + (/+1) + / + / + / (-1) + / / = = + 1 / + 3 / = T() = O( ) 4) Indicate whether or not you can use big-theta to represent the growth rate of the running time if you are showing the time for: a) the best case, b) the worst case, c) the average case, d) the algorithm in general. a) yes b) yes c) yes d) no ote: for the algorithm in general (the d-option) we can t use big-theta since the growth rate of the time function in the best case has lower order than in the worst case. 4. Here is the pseudocode for insertion sort algorithm to sort a given A list of numbers (indexing is natural, i.e. starts with 1; =A.lenght). InsertionSort(A) frequencies(worst case) frequencies(best case) frequencies( avg case) 1 for i= to A.length temp = A[i] j = i while j>1 and A[j-1]>temp i= ( i 1 + 1) (-1) 1 i= ( i/ + 1) 5 A[j] = A[j-1] i= ( i 1) 0 //(-1) 0 i= ( i/) j = j 1 i= ( i 1) 0 //(-1) 0 i= ( i/) 7 A[j] = temp ote: instead of i-1 inside the sum, we can write i j= 1 (this sum equals to i-1)

3 Analyze the insertion sort algorithm: ote: This algorithm has two loops where one of them, the while-loop, executes different number of iterations depending on the data values in the given list. This means that for the algorithm s execution we have best, worst, and average scenarios. 1) Find out the time function of this algorithm and its growth rate, showing detailed calculations, as done in class: (i) figure out frequencies of all lines of the pseudocode, (ii) compute the total number of steps executed by the algorithm, and obtain a formula for the running time, i.e. T() function, (iii) get the growth rate of T() function. To get the time function of the algorithm, we need to analyze the worst case, i.e.when the algorithm executes maximum number of steps. For this algorithm the worst case is when the while-loop executes max number of iterations, i.e does i-1 iterations in each for-loop iteration (for each i-value). The worst case happens when the list is sorted backward in each for-loop iteration the A[i] element ends up being sent to the front of the list after all i-1 of its left neighbors are checked and shifted one cell to the right (the second condition of the while loop is always true). In the worst case the frequencies of all lines will be as stated above, in the first column next to the pseudocode. T() will be obtained by adding values in first column: T() = + (-1) + i= ( i 1 + 1) + i= ( i 1) + (-1) = = i= i= ( i 1) = i=1 i = //ote that the sum i= ( i 1) is the same as the sum 1 i=1 i = ( 1) = T() = O( ) ) Analyze the best case scenario of this algorithm the same way you ve done analysis in bullet 1). Obtain the formula for T() function and then get its growth rate. For this algorithm the best case is when the while-loop executes min number of iterations, which is 0 iterations in each for-loop iteration (for each i-value). The best case happens when the list is already sorted in each for-loop iteration the A[i] element stays put (the second condition of the while-loop is false right away so the loop never iterates). In the best case the frequencies of all lines will be as stated above, in the second column next to the pseudocode. T() will be obtained by adding all values of that second column: T() = + 4 (-1) = 5-4 T() = O() 3) Analyze the average case scenario of this algorithm the same way you ve done analysis in bullet 1). Obtain the formula for T() function and then get its growth rate. For this algorithm the average case can be computed by taking the average number of iterations of the while-loop in each for-loop iteration (for each i-value). This number is computed as the average of all possible numbers of while-loop iterations for a given i (0 iterations, 1 iteration, iterations, i-1 iterations): (i 1) = i 1 k=0 k i (i 1)i = i //for simplicity, it s fine to approximate i i In the average case, the frequencies of all lines will be as stated above, in the third column next to pseudocode. T() will be obtained by adding values in third column: = i 1 T() = + (-1) + i= (i/ + 1) + i= ( i/) + -1 = i= ( i/) 3 = i= i = ((+1) 1) = T() = O( ) //ote that i i= = i= 1 i - 1 i= = 3

4 4) Indicate whether or not you can use big-theta to represent the growth rate of the running time if you are showing the time for: a) the best case, b) the worst case, c) the average case, d) the algorithm in general. a) yes b) yes c) yes d) no ote: for the algorithm in general (d-option) we can t use big-theta since the growth rate of time function in the best case has lower order than in the worst case. 5. Here is an efficient (logarithmic) recursive algorithm for computing a n. Power(a, n) 1 if n ==0 return 1 3 else 4 if n==1 5 return a else 7 if n% ==0 8 return Power (a*a, n/) //if n is an even number, then a n = (a ) n/ 9 else 10 return Power (a*a, n/ )*a //if n is an odd number, then a n = a (a ) n/ Give the recurrence equation representing the time function of this algorithm (the time function of this algorithm depends only on n). T(n) = T(n/) + Θ(1) T(1) = Θ(1); T(0) = Θ(1) //two base cases. Here is a recursive algorithm for computing n-th Fibonacci number (VERY slow exponential algorithm; it is used as an example for educational purposes). Fibonacci(n) 1 if n ==1 or n == return 1 3 else 4 return Fibonacci(n-1) + Fibonacci(n-) Give the recurrence equation representing the time function of this algorithm. T(n) = T(n-1) + T(n-) + Θ(1) T() = Θ(1); T(1) = Θ(1) //two base cases 7. Solve the following recurrence equations using the recursion tree method: draw the recursion tree, do the math as done in class (show level-sums, as well as the detailed math when obtaining their sum) and give an asymptotic upper bound on the recurrence (via big-theta notation). a) T(n) = T(n-1) + n At each level of the recursion tree argument s value level-sums n n n (n-1) n-1 (n-1) (n-) n- (n-) : : :

5 To get the total number of steps, add all level-sums (numbers in the last column): T(n) = (n-) + (n-1) + n = n i=1 i = n(n+1)(n+1). Thus T(n) = O(n 3 ) ote: we used k i=0 i formula here. = k(k+1)(k+1) b) T(n) = T(n-1) + 1 At each level of the recursion tree argument s value #nodes level-sums 1 n 1= n-1 = n- 4= n 1 1 n-3 8= 3 3 : : : : : : : : : : : : = n-(n-1) n-1 n-1 ote: number of levels in the tree is n. To get the total number of steps, add all level-sums (numbers in the last column): T(n) = n- + n-1 = n 1 i=0 i = n 1. Thus T(n) = O( n ) ote: we used k i=0 i = k+1 1 formula here. c) T(n) = 4T(n/4) + 1 At each level of the recursion tree argument s value #nodes level-sums 1 n=n/4 0 1= n/4=n/4 1 4= n/1=n/4 1= n/4=n/4 3 4= : : : : : : : : : : : : = n 4 log 4 n 4log 4 n 4 log 4 n ote: the height of the tree is log 4 n and the number of levels is log 4 n +1. To get the total number of steps, add all level-sums (numbers in the last column): T(n) = n log 4 n log = 4 n i=0 4 i = (4 log 4 n + 1 1)/3 = (4 4 log 4 n 1)/3 = 4 n Thus T(n) = O(n). ote: we used k i=0 x i = xk+1 1, for x > 1 formula here. x 1 5

6 d) T(n) = 3T(n/) + n At each level of the recursion tree arugment s value #nodes level-sums n n = n 0 1=30 n //i.e. 3 0 n 0 n/ n/ n/ n/= n 1 3=31 3 n n/4 n/4 n/4 n/4 n/4 n/4 n/4 n/4 n/4 n/4= n 9=3 3 n //i.e. 9 n 4 ::: ::: ::: ::: ::: ::: ::: n/8 n/8 n/8 n/8 n n/8 n/8 n/8= n 3 7= n //i.e. 7 n 3 8 : : : : : : : : : : : : : : : = n logn 3logn 3 logn n logn ote: the height of the tree is log n and the number of levels is log n +1. The get the total number of steps we need to add up all level-sums (numbers in the last column). We will get: T(n) = 3 0 n n n + 33 n logn n = n logn logn i=0 (3 )i = n ( = n( 3 3logn 3 3logn logn 1) = n n = 3 3 logn n = 3 n log3 n. n 3 )logn = 1 Thus T(n) = O(n log3 ) = O(n 1.59 ) //note that log ote: formulas used here are: k i=0 x i = xk+1 1, for x>1 and x 1 xlog a y = y log a x ote: some useful formulas for your reference: k i = k(k+1) i=0 k i=0 i k i=0 = k+1 1 x i i k i=0 = k(k+1)(k+1) = xk+1 1 x 1, for x>1 xlog a y = y log a x

Data Structures. Algorithm Performance and Big O Analysis

Data Structures. Algorithm Performance and Big O Analysis Data Structures Algorithm Performance and Big O Analysis What s an Algorithm? a clearly specified set of instructions to be followed to solve a problem. In essence: A computer program. In detail: Defined

More information

Algorithms. Margaret M. Fleck. 18 October 2010

Algorithms. Margaret M. Fleck. 18 October 2010 Algorithms Margaret M. Fleck 18 October 2010 These notes cover how to analyze the running time of algorithms (sections 3.1, 3.3, 4.4, and 7.1 of Rosen). 1 Introduction The main reason for studying big-o

More information

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Why? A central concept in Computer Science. Algorithms are ubiquitous. Analysis of Algorithms: A Brief Introduction Why? A central concept in Computer Science. Algorithms are ubiquitous. Using the Internet (sending email, transferring files, use of search engines, online

More information

Computer Science 210: Data Structures. Searching

Computer Science 210: Data Structures. Searching Computer Science 210: Data Structures Searching Searching Given a sequence of elements, and a target element, find whether the target occurs in the sequence Variations: find first occurence; find all occurences

More information

6. Standard Algorithms

6. Standard Algorithms 6. Standard Algorithms The algorithms we will examine perform Searching and Sorting. 6.1 Searching Algorithms Two algorithms will be studied. These are: 6.1.1. inear Search The inear Search The Binary

More information

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015 CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Today Registration should be done. Homework 1 due 11:59 pm next Wednesday, January 14 Review math essential

More information

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction Class Overview CSE 326: Data Structures Introduction Introduction to many of the basic data structures used in computer software Understand the data structures Analyze the algorithms that use them Know

More information

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1 Recursion Slides by Christopher M Bourke Instructor: Berthe Y Choueiry Fall 007 Computer Science & Engineering 35 Introduction to Discrete Mathematics Sections 71-7 of Rosen cse35@cseunledu Recursive Algorithms

More information

Math 55: Discrete Mathematics

Math 55: Discrete Mathematics Math 55: Discrete Mathematics UC Berkeley, Fall 2011 Homework # 5, due Wednesday, February 22 5.1.4 Let P (n) be the statement that 1 3 + 2 3 + + n 3 = (n(n + 1)/2) 2 for the positive integer n. a) What

More information

Analysis of Binary Search algorithm and Selection Sort algorithm

Analysis of Binary Search algorithm and Selection Sort algorithm Analysis of Binary Search algorithm and Selection Sort algorithm In this section we shall take up two representative problems in computer science, work out the algorithms based on the best strategy to

More information

Symbol Tables. Introduction

Symbol Tables. Introduction Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

More information

What Is Recursion? Recursion. Binary search example postponed to end of lecture

What Is Recursion? Recursion. Binary search example postponed to end of lecture Recursion Binary search example postponed to end of lecture What Is Recursion? Recursive call A method call in which the method being called is the same as the one making the call Direct recursion Recursion

More information

Algorithm Analysis [2]: if-else statements, recursive algorithms. COSC 2011, Winter 2004, Section N Instructor: N. Vlajic

Algorithm Analysis [2]: if-else statements, recursive algorithms. COSC 2011, Winter 2004, Section N Instructor: N. Vlajic 1 Algorithm Analysis []: if-else statements, recursive algorithms COSC 011, Winter 004, Section N Instructor: N. Vlajic Algorithm Analysis for-loop Running Time The running time of a simple loop for (int

More information

Data Structures and Algorithms Written Examination

Data Structures and Algorithms Written Examination Data Structures and Algorithms Written Examination 22 February 2013 FIRST NAME STUDENT NUMBER LAST NAME SIGNATURE Instructions for students: Write First Name, Last Name, Student Number and Signature where

More information

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)! The Tower of Hanoi Recursion Solution recursion recursion recursion Recursive Thinking: ignore everything but the bottom disk. 1 2 Recursive Function Time Complexity Hanoi (n, src, dest, temp): If (n >

More information

Sorting Algorithms. Nelson Padua-Perez Bill Pugh. Department of Computer Science University of Maryland, College Park

Sorting Algorithms. Nelson Padua-Perez Bill Pugh. Department of Computer Science University of Maryland, College Park Sorting Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park Overview Comparison sort Bubble sort Selection sort Tree sort Heap sort Quick sort Merge

More information

CSC148 Lecture 8. Algorithm Analysis Binary Search Sorting

CSC148 Lecture 8. Algorithm Analysis Binary Search Sorting CSC148 Lecture 8 Algorithm Analysis Binary Search Sorting Algorithm Analysis Recall definition of Big Oh: We say a function f(n) is O(g(n)) if there exists positive constants c,b such that f(n)

More information

Chapter 13: Query Processing. Basic Steps in Query Processing

Chapter 13: Query Processing. Basic Steps in Query Processing Chapter 13: Query Processing! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions 13.1 Basic Steps in Query Processing 1. Parsing

More information

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * * Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest

More information

Sample Questions Csci 1112 A. Bellaachia

Sample Questions Csci 1112 A. Bellaachia Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k

More information

Dynamic Programming Problem Set Partial Solution CMPSC 465

Dynamic Programming Problem Set Partial Solution CMPSC 465 Dynamic Programming Problem Set Partial Solution CMPSC 465 I ve annotated this document with partial solutions to problems written more like a test solution. (I remind you again, though, that a formal

More information

Pseudo code Tutorial and Exercises Teacher s Version

Pseudo code Tutorial and Exercises Teacher s Version Pseudo code Tutorial and Exercises Teacher s Version Pseudo-code is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy

More information

Section IV.1: Recursive Algorithms and Recursion Trees

Section IV.1: Recursive Algorithms and Recursion Trees Section IV.1: Recursive Algorithms and Recursion Trees Definition IV.1.1: A recursive algorithm is an algorithm that solves a problem by (1) reducing it to an instance of the same problem with smaller

More information

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 9 Sorting in Linear Time View in slide-show mode 1 How Fast Can We Sort? The algorithms we have seen so far: Based on comparison of elements We only care about the relative

More information

APP INVENTOR. Test Review

APP INVENTOR. Test Review APP INVENTOR Test Review Main Concepts App Inventor Lists Creating Random Numbers Variables Searching and Sorting Data Linear Search Binary Search Selection Sort Quick Sort Abstraction Modulus Division

More information

Sample Induction Proofs

Sample Induction Proofs Math 3 Worksheet: Induction Proofs III, Sample Proofs A.J. Hildebrand Sample Induction Proofs Below are model solutions to some of the practice problems on the induction worksheets. The solutions given

More information

Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction

Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction Lecture 11 Dynamic Programming 11.1 Overview Dynamic Programming is a powerful technique that allows one to solve many different types of problems in time O(n 2 ) or O(n 3 ) for which a naive approach

More information

Closest Pair of Points. Kleinberg and Tardos Section 5.4

Closest Pair of Points. Kleinberg and Tardos Section 5.4 Closest Pair of Points Kleinberg and Tardos Section 5.4 Closest Pair of Points Closest pair. Given n points in the plane, find a pair with smallest Euclidean distance between them. Fundamental geometric

More information

Data Structures Fibonacci Heaps, Amortized Analysis

Data Structures Fibonacci Heaps, Amortized Analysis Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

More information

Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.

Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case. Algorithms Efficiency of algorithms Computational resources: time and space Best, worst and average case performance How to compare algorithms: machine-independent measure of efficiency Growth rate Complexity

More information

COMPUTER SCIENCE. Paper 1 (THEORY)

COMPUTER SCIENCE. Paper 1 (THEORY) COMPUTER SCIENCE Paper 1 (THEORY) (Three hours) Maximum Marks: 70 (Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time) -----------------------------------------------------------------------------------------------------------------------

More information

From Last Time: Remove (Delete) Operation

From Last Time: Remove (Delete) Operation CSE 32 Lecture : More on Search Trees Today s Topics: Lazy Operations Run Time Analysis of Binary Search Tree Operations Balanced Search Trees AVL Trees and Rotations Covered in Chapter of the text From

More information

In mathematics, it is often important to get a handle on the error term of an approximation. For instance, people will write

In mathematics, it is often important to get a handle on the error term of an approximation. For instance, people will write Big O notation (with a capital letter O, not a zero), also called Landau's symbol, is a symbolism used in complexity theory, computer science, and mathematics to describe the asymptotic behavior of functions.

More information

Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally

Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally Recurrence Relations Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally modeled by recurrence relations. A recurrence relation is an equation which

More information

CS/COE 1501 http://cs.pitt.edu/~bill/1501/

CS/COE 1501 http://cs.pitt.edu/~bill/1501/ CS/COE 1501 http://cs.pitt.edu/~bill/1501/ Lecture 01 Course Introduction Meta-notes These notes are intended for use by students in CS1501 at the University of Pittsburgh. They are provided free of charge

More information

Data Structure [Question Bank]

Data Structure [Question Bank] Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:

More information

Math 115 Spring 2011 Written Homework 5 Solutions

Math 115 Spring 2011 Written Homework 5 Solutions . Evaluate each series. a) 4 7 0... 55 Math 5 Spring 0 Written Homework 5 Solutions Solution: We note that the associated sequence, 4, 7, 0,..., 55 appears to be an arithmetic sequence. If the sequence

More information

Class : MAC 286. Data Structure. Research Paper on Sorting Algorithms

Class : MAC 286. Data Structure. Research Paper on Sorting Algorithms Name : Jariya Phongsai Class : MAC 286. Data Structure Research Paper on Sorting Algorithms Prof. Lawrence Muller Date : October 26, 2009 Introduction In computer science, a ing algorithm is an efficient

More information

Solutions to Homework 6

Solutions to Homework 6 Solutions to Homework 6 Debasish Das EECS Department, Northwestern University ddas@northwestern.edu 1 Problem 5.24 We want to find light spanning trees with certain special properties. Given is one example

More information

The Running Time of Programs

The Running Time of Programs CHAPTER 3 The Running Time of Programs In Chapter 2, we saw two radically different algorithms for sorting: selection sort and merge sort. There are, in fact, scores of algorithms for sorting. This situation

More information

2 SYSTEM DESCRIPTION TECHNIQUES

2 SYSTEM DESCRIPTION TECHNIQUES 2 SYSTEM DESCRIPTION TECHNIQUES 2.1 INTRODUCTION Graphical representation of any process is always better and more meaningful than its representation in words. Moreover, it is very difficult to arrange

More information

Binary search algorithm

Binary search algorithm Binary search algorithm Definition Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures CMPSC 465 LECTURES 20-21 Priority Queues and Binary Heaps Adam Smith S. Raskhodnikova and A. Smith. Based on slides by C. Leiserson and E. Demaine. 1 Trees Rooted Tree: collection

More information

the recursion-tree method

the recursion-tree method the recursion- method recurrence into a 1 recurrence into a 2 MCS 360 Lecture 39 Introduction to Data Structures Jan Verschelde, 22 November 2010 recurrence into a The for consists of two steps: 1 Guess

More information

Sequential Data Structures

Sequential Data Structures Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year

More information

Binary Heaps. CSE 373 Data Structures

Binary Heaps. CSE 373 Data Structures Binary Heaps CSE Data Structures Readings Chapter Section. Binary Heaps BST implementation of a Priority Queue Worst case (degenerate tree) FindMin, DeleteMin and Insert (k) are all O(n) Best case (completely

More information

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; } Functions Recursion C++ functions Declare/prototype int myfunction (int ); Define int myfunction (int x){ int y = x*x; return y; Call int a; a = myfunction (7); function call flow types type of function

More information

Lecture Notes on Linear Search

Lecture Notes on Linear Search Lecture Notes on Linear Search 15-122: Principles of Imperative Computation Frank Pfenning Lecture 5 January 29, 2013 1 Introduction One of the fundamental and recurring problems in computer science is

More information

14:440:127 Introduction to Computers for Engineers. Notes for Lecture 06

14:440:127 Introduction to Computers for Engineers. Notes for Lecture 06 14:440:127 Introduction to Computers for Engineers Notes for Lecture 06 Rutgers University, Spring 2010 Instructor- Blase E. Ur 1 Loop Examples 1.1 Example- Sum Primes Let s say we wanted to sum all 1,

More information

The Fast Fourier Transform

The Fast Fourier Transform The Fast Fourier Transform Chris Lomont, Jan 2010, http://www.lomont.org, updated Aug 2011 to include parameterized FFTs. This note derives the Fast Fourier Transform (FFT) algorithm and presents a small,

More information

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

Analysis of Algorithms I: Binary Search Trees

Analysis of Algorithms I: Binary Search Trees Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary

More information

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Problem 1. In each of the following question, please specify if the statement

More information

SOLVING EQUATIONS WITH EXCEL

SOLVING EQUATIONS WITH EXCEL SOLVING EQUATIONS WITH EXCEL Excel and Lotus software are equipped with functions that allow the user to identify the root of an equation. By root, we mean the values of x such that a given equation cancels

More information

STATISTICA Formula Guide: Logistic Regression. Table of Contents

STATISTICA Formula Guide: Logistic Regression. Table of Contents : Table of Contents... 1 Overview of Model... 1 Dispersion... 2 Parameterization... 3 Sigma-Restricted Model... 3 Overparameterized Model... 4 Reference Coding... 4 Model Summary (Summary Tab)... 5 Summary

More information

Lecture 1: Course overview, circuits, and formulas

Lecture 1: Course overview, circuits, and formulas Lecture 1: Course overview, circuits, and formulas Topics in Complexity Theory and Pseudorandomness (Spring 2013) Rutgers University Swastik Kopparty Scribes: John Kim, Ben Lund 1 Course Information Swastik

More information

Near Optimal Solutions

Near Optimal Solutions Near Optimal Solutions Many important optimization problems are lacking efficient solutions. NP-Complete problems unlikely to have polynomial time solutions. Good heuristics important for such problems.

More information

Accentuate the Negative: Homework Examples from ACE

Accentuate the Negative: Homework Examples from ACE Accentuate the Negative: Homework Examples from ACE Investigation 1: Extending the Number System, ACE #6, 7, 12-15, 47, 49-52 Investigation 2: Adding and Subtracting Rational Numbers, ACE 18-22, 38(a),

More information

recursion, O(n), linked lists 6/14

recursion, O(n), linked lists 6/14 recursion, O(n), linked lists 6/14 recursion reducing the amount of data to process and processing a smaller amount of data example: process one item in a list, recursively process the rest of the list

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2016S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

6 March 2007 1. Array Implementation of Binary Trees

6 March 2007 1. Array Implementation of Binary Trees Heaps CSE 0 Winter 00 March 00 1 Array Implementation of Binary Trees Each node v is stored at index i defined as follows: If v is the root, i = 1 The left child of v is in position i The right child of

More information

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

More information

Query Processing C H A P T E R12. Practice Exercises

Query Processing C H A P T E R12. Practice Exercises C H A P T E R12 Query Processing Practice Exercises 12.1 Assume (for simplicity in this exercise) that only one tuple fits in a block and memory holds at most 3 blocks. Show the runs created on each pass

More information

Tutorial on Using Excel Solver to Analyze Spin-Lattice Relaxation Time Data

Tutorial on Using Excel Solver to Analyze Spin-Lattice Relaxation Time Data Tutorial on Using Excel Solver to Analyze Spin-Lattice Relaxation Time Data In the measurement of the Spin-Lattice Relaxation time T 1, a 180 o pulse is followed after a delay time of t with a 90 o pulse,

More information

IB Math Research Problem

IB Math Research Problem Vincent Chu Block F IB Math Research Problem The product of all factors of 2000 can be found using several methods. One of the methods I employed in the beginning is a primitive one I wrote a computer

More information

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

More information

DATA STRUCTURES USING C

DATA STRUCTURES USING C DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

More information

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb Binary Search Trees Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 27 1 Properties of Binary Search Trees 2 Basic BST operations The worst-case time complexity of BST operations

More information

PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC QUESTION BANK PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

More information

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent

More information

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014 Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li Advised by: Dave Mount May 22, 2014 1 INTRODUCTION In this report we consider the implementation of an efficient

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2

More information

Scheduling Shop Scheduling. Tim Nieberg

Scheduling Shop Scheduling. Tim Nieberg Scheduling Shop Scheduling Tim Nieberg Shop models: General Introduction Remark: Consider non preemptive problems with regular objectives Notation Shop Problems: m machines, n jobs 1,..., n operations

More information

CSC 180 H1F Algorithm Runtime Analysis Lecture Notes Fall 2015

CSC 180 H1F Algorithm Runtime Analysis Lecture Notes Fall 2015 1 Introduction These notes introduce basic runtime analysis of algorithms. We would like to be able to tell if a given algorithm is time-efficient, and to be able to compare different algorithms. 2 Linear

More information

Binary Heap Algorithms

Binary Heap Algorithms CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Computational Complexity Escola Politècnica Superior d Alcoi Universitat Politècnica de València Contents Introduction Resources consumptions: spatial and temporal cost Costs

More information

Single machine models: Maximum Lateness -12- Approximation ratio for EDD for problem 1 r j,d j < 0 L max. structure of a schedule Q...

Single machine models: Maximum Lateness -12- Approximation ratio for EDD for problem 1 r j,d j < 0 L max. structure of a schedule Q... Lecture 4 Scheduling 1 Single machine models: Maximum Lateness -12- Approximation ratio for EDD for problem 1 r j,d j < 0 L max structure of a schedule 0 Q 1100 11 00 11 000 111 0 0 1 1 00 11 00 11 00

More information

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm View in slide-show mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine

More information

To My Parents -Laxmi and Modaiah. To My Family Members. To My Friends. To IIT Bombay. To All Hard Workers

To My Parents -Laxmi and Modaiah. To My Family Members. To My Friends. To IIT Bombay. To All Hard Workers To My Parents -Laxmi and Modaiah To My Family Members To My Friends To IIT Bombay To All Hard Workers Copyright 2010 by CareerMonk.com All rights reserved. Designed by Narasimha Karumanchi Printed in

More information

Analysis of Computer Algorithms. Algorithm. Algorithm, Data Structure, Program

Analysis of Computer Algorithms. Algorithm. Algorithm, Data Structure, Program Analysis of Computer Algorithms Hiroaki Kobayashi Input Algorithm Output 12/13/02 Algorithm Theory 1 Algorithm, Data Structure, Program Algorithm Well-defined, a finite step-by-step computational procedure

More information

Lecture 2 February 12, 2003

Lecture 2 February 12, 2003 6.897: Advanced Data Structures Spring 003 Prof. Erik Demaine Lecture February, 003 Scribe: Jeff Lindy Overview In the last lecture we considered the successor problem for a bounded universe of size u.

More information

Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA email: ada@csie.ntu.edu.tw. === Homework submission instructions ===

Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA email: ada@csie.ntu.edu.tw. === Homework submission instructions === Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA email: ada@csie.ntu.edu.tw === Homework submission instructions === For Problem 1, commit your source code and a brief documentation

More information

Ordered Lists and Binary Trees

Ordered Lists and Binary Trees Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:

More information

Unit 1. 5. Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]

Unit 1. 5. Write iterative and recursive C functions to find the greatest common divisor of two integers. [6] Unit 1 1. Write the following statements in C : [4] Print the address of a float variable P. Declare and initialize an array to four characters a,b,c,d. 2. Declare a pointer to a function f which accepts

More information

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge, The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge, cheapest first, we had to determine whether its two endpoints

More information

Analysis of Algorithms I: Optimal Binary Search Trees

Analysis of Algorithms I: Optimal Binary Search Trees Analysis of Algorithms I: Optimal Binary Search Trees Xi Chen Columbia University Given a set of n keys K = {k 1,..., k n } in sorted order: k 1 < k 2 < < k n we wish to build an optimal binary search

More information

ASSIGNMENT 4 PREDICTIVE MODELING AND GAINS CHARTS

ASSIGNMENT 4 PREDICTIVE MODELING AND GAINS CHARTS DATABASE MARKETING Fall 2015, max 24 credits Dead line 15.10. ASSIGNMENT 4 PREDICTIVE MODELING AND GAINS CHARTS PART A Gains chart with excel Prepare a gains chart from the data in \\work\courses\e\27\e20100\ass4b.xls.

More information

Triangulation by Ear Clipping

Triangulation by Ear Clipping Triangulation by Ear Clipping David Eberly Geometric Tools, LLC http://www.geometrictools.com/ Copyright c 1998-2016. All Rights Reserved. Created: November 18, 2002 Last Modified: August 16, 2015 Contents

More information

Attacking Anonymized Social Network

Attacking Anonymized Social Network Attacking Anonymized Social Network From: Wherefore Art Thou RX3579X? Anonymized Social Networks, Hidden Patterns, and Structural Steganography Presented By: Machigar Ongtang (Ongtang@cse.psu.edu ) Social

More information

Mathematical Induction. Lecture 10-11

Mathematical Induction. Lecture 10-11 Mathematical Induction Lecture 10-11 Menu Mathematical Induction Strong Induction Recursive Definitions Structural Induction Climbing an Infinite Ladder Suppose we have an infinite ladder: 1. We can reach

More information

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1. Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Shafi Goldwasser Quiz 1 Quiz 1 Do not open this quiz booklet until you are directed

More information

SIMS 255 Foundations of Software Design. Complexity and NP-completeness

SIMS 255 Foundations of Software Design. Complexity and NP-completeness SIMS 255 Foundations of Software Design Complexity and NP-completeness Matt Welsh November 29, 2001 mdw@cs.berkeley.edu 1 Outline Complexity of algorithms Space and time complexity ``Big O'' notation Complexity

More information

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

WRITING PROOFS. Christopher Heil Georgia Institute of Technology WRITING PROOFS Christopher Heil Georgia Institute of Technology A theorem is just a statement of fact A proof of the theorem is a logical explanation of why the theorem is true Many theorems have this

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

3. Interpolation. Closing the Gaps of Discretization... Beyond Polynomials

3. Interpolation. Closing the Gaps of Discretization... Beyond Polynomials 3. Interpolation Closing the Gaps of Discretization... Beyond Polynomials Closing the Gaps of Discretization... Beyond Polynomials, December 19, 2012 1 3.3. Polynomial Splines Idea of Polynomial Splines

More information

An Immediate Approach to Balancing Nodes of Binary Search Trees

An Immediate Approach to Balancing Nodes of Binary Search Trees Chung-Chih Li Dept. of Computer Science, Lamar University Beaumont, Texas,USA Abstract We present an immediate approach in hoping to bridge the gap between the difficulties of learning ordinary binary

More information

HW4: Merge Sort. 1 Assignment Goal. 2 Description of the Merging Problem. Course: ENEE759K/CMSC751 Title:

HW4: Merge Sort. 1 Assignment Goal. 2 Description of the Merging Problem. Course: ENEE759K/CMSC751 Title: HW4: Merge Sort Course: ENEE759K/CMSC751 Title: Merge Sort Date Assigned: March 24th, 2009 Date Due: April 10th, 2009 11:59pm Contact: Fuat Keceli keceli (at) umd (dot) edu 1 Assignment Goal The final

More information

MEI Structured Mathematics. Practice Comprehension Task - 2. Do trains run late?

MEI Structured Mathematics. Practice Comprehension Task - 2. Do trains run late? MEI Structured Mathematics Practice Comprehension Task - 2 Do trains run late? There is a popular myth that trains always run late. Actually this is far from the case. All train companies want their trains

More information

A Note on Maximum Independent Sets in Rectangle Intersection Graphs

A Note on Maximum Independent Sets in Rectangle Intersection Graphs A Note on Maximum Independent Sets in Rectangle Intersection Graphs Timothy M. Chan School of Computer Science University of Waterloo Waterloo, Ontario N2L 3G1, Canada tmchan@uwaterloo.ca September 12,

More information