MA/CSSE 473 Day 12 Amortization (growable Array) Knuth interview Brute Force Examples.

Slides:



Advertisements
Similar presentations
Algorithm Design Techniques
Advertisements

Chapter 3 Brute Force Brute force is a straightforward approach to solving a problem, usually directly based on the problem’s statement and definitions.
MATH 224 – Discrete Mathematics
CS261 Data Structures Dynamic Arrays. Pro: only core data structure designed to hold a collection of elements Pro: random access: can quickly get to any.
MA/CSSE 473 Day 13 Divide and Conquer Closest Points Convex Hull Answer Quiz Question 1.
S. J. Shyu Chap. 1 Introduction 1 The Design and Analysis of Algorithms Chapter 1 Introduction S. J. Shyu.
CS4413 Divide-and-Conquer
Quicksort Quicksort     29  9.
ISOM MIS 215 Module 7 – Sorting. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
The Design and Analysis of Algorithms
Chapter 19: Searching and Sorting Algorithms
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Design and Analysis of Algorithms - Chapter 31 Brute Force A straightforward approach usually based on problem statement and definitions Examples: 1. Computing.
Introduction to Analysis of Algorithms
1 -1 Chapter 1 Introduction Why Do We Need to Study Algorithms? To learn strategies to design efficient algorithms. To understand the difficulty.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Design and Analysis of Algorithms - Chapter 31 Brute Force A straightforward approach usually based on problem statement and definitions Examples: 1. Computing.
Homework page 102 questions 1, 4, and 10 page 106 questions 4 and 5 page 111 question 1 page 119 question 9.
1 -1 Chapter 1 Introduction Why to study algorithms? Sorting problem: To sort a set of elements into increasing or decreasing order. 11, 7, 14,
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
Backtracking.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Design and Analysis of Algorithms - Chapter 11 Algorithm An algorithm is a.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
TK3043 Analysis and Design of Algorithms Introduction to Algorithms.
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
Lecture 6 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
MA/CSSE 473 Day 13 Permutation Generation. MA/CSSE 473 Day 13 HW 6 due Monday, HW 7 next Thursday, Student Questions Tuesday’s exam Permutation generation.
Week 2 CS 361: Advanced Data Structures and Algorithms
IT 60101: Lecture #201 Foundation of Computing Systems Lecture 20 Classic Optimization Problems.
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
Dynamic Programming. Well known algorithm design techniques:. –Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic programming.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
MA/CSSE 473 Day 17 Permutations by lexicographic order number.
Algorithms  Al-Khwarizmi, arab mathematician, 8 th century  Wrote a book: al-kitab… from which the word Algebra comes  Oldest algorithm: Euclidian algorithm.
Theory of Algorithms: Brute Force. Outline Examples Brute-Force String Matching Closest-Pair Convex-Hull Exhaustive Search brute-force strengths and weaknesses.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
INTRODUCTION. What is an algorithm? What is a Problem?
5-1-1 CSC401 – Analysis of Algorithms Chapter 5--1 The Greedy Method Objectives Introduce the Brute Force method and the Greedy Method Compare the solutions.
MA/CSSE 473 Day 19 Exam Prep. MA/CSSE 473 Day 19 If you want additional practice problems for Tuesday's exam: –The "not to turn in" problems from various.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Chapter 3 Brute Force. A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples:
Design and Analysis of Algorithms (09 Credits / 5 hours per week) Sixth Semester: Computer Science & Engineering M.B.Chandak
CSE 340: Review (at last!) Measuring The Complexity Complexity is a function of the size of the input O() Ω() Θ() Complexity Analysis “same order” Order.
Lecture 7 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
© The McGraw-Hill Companies, Inc., Chapter 1 Introduction.
MA/CSSE 473 Day 16 Combinatorial Object Generation Permutations.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Ch3 /Lecture #4 Brute Force and Exhaustive Search 1.
Exhaustive search Exhaustive search is simply a brute- force approach to combinatorial problems. It suggests generating each and every element of the problem.
Introduction to Data Structure and Algorithms
MA/CSSE 473 Day 11 Knuth interview Amortization (growable Array) Brute Force Examples.
Introduction to Algorithms: Brute-Force Algorithms.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
Brute Force A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples: Computing.
Brute Force II.
Limitation of Computation Power – P, NP, and NP-complete
Design and Analysis of Algorithms (09 Credits / 5 hours per week)
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 3 String Matching.
Objective of This Course
COSC 320 Advanced Data Structures and Algorithm Analysis
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
3. Brute Force Selection sort Brute-Force string matching
3. Brute Force Selection sort Brute-Force string matching
Chapter 1 Introduction.
INTRODUCTION TO ALOGORITHM DESIGN STRATEGIES
Department of Computer Science & Engineering
3. Brute Force Selection sort Brute-Force string matching
Presentation transcript:

MA/CSSE 473 Day 12 Amortization (growable Array) Knuth interview Brute Force Examples

MA/CSSE 473 Day 12 Questions? Donald Knuth Interview Amortization Brute force (if time) Divide and conquer intro Q1-2

Donald Knuth Interview List a few things that you found interesting in the interview What questions would you ask Donald Knuth if you had the chance?

Amortized efficiency analysis P49-50 in the textbook We analyze not just a single operation, but a sequence of operations performed on the same structure –We conclude something about the worst-case of the average of all of the operations in the sequence Example: Growable array exercise from 220/230, which we will quickly review today Q1

Growable Array (implement ArrayList) An ArrayList has a size and a capacity The capacity is the length of the fixed-size array currently allocated to hold the list elements For definiteness, we start with size=0 and capacity=12 We add a total of N items (N is not known in advance), one at a time, each to the end of the structure When there is no room in the array (i.e. capacity=size and we need to add another element) –Allocate a new, larger array –copy the size existing elements to the new array –add the new element to the new array

Growable Array (implement ArrayList) When there is no room in the array (i.e. capacity=size and we need to add another element) –Allocate a new, larger array –copy the size existing elements to the new array –add the new element to the new array What is the total/average overhead (due to element copying) if a.we add one to the array capacity each time we have to grow it? b.we double the array capacity each time we have to grow it? Note in the second case that the amortized worst-case cost is asymptotically less than the worst case for a single element Every time we have to enlarge the capacity, we make it so we do not have to enlarge again soon. Q2

Brute Force Algorithms Straightforward, simple, not subtle, usually a simple application of the problem definition. Often not very efficient Easy to implement, so often the best choice if you know you'll only apply it to small input sizes 3-4

What is a brute force approach to 1.Calculate the n th Fibonacci number? 2.Compute the n th power of an integer? 3.Search for a particular value in a sorted array? 4.Sort an array? 5.Search for a substring of a string? 6.Find the maximum contiguous subsequence in an array of integers? 7.Find the largest element in a Binary Search Tree? 8.Find the two closest points among N points in the plane? 9.Find the convex hull of a set of points in the plane? 10.Find the shortest path from vertex A to vertex B in a weighted graph? 11.Solve the traveling salesman problem? 12.Solve the knapsack problem? 13.Solve the assignment problem? 14.Solve the n  n non-attacking chess queens problem? 15.Other problems that you can think of?

DIVIDE AND CONQUER

Divide-and-conquer algorithms Definition Examples seen prior to this course or so far in this course