Lecture 12: Revision Lecture Dr John Levine 52236 Algorithms and Complexity March 27th 2006.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

Problems and Their Classes
Garfield AP Computer Science
CSC 421: Algorithm Design & Analysis
Lecture 8: Informed Search Dr John Levine Algorithms and Complexity February 27th 2006.
CompSci Searching & Sorting. CompSci Searching & Sorting The Plan  Searching  Sorting  Java Context.
S. J. Shyu Chap. 1 Introduction 1 The Design and Analysis of Algorithms Chapter 1 Introduction S. J. Shyu.
ISOM MIS 215 Module 7 – Sorting. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 19: Searching and Sorting Algorithms
Searching and Sorting Topics  Sequential Search on an Unordered File  Sequential Search on an Ordered File  Binary Search  Bubble Sort  Insertion.
Midterm 2 Overview Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Data Structures & Algorithms What The Course Is About s Data structures is concerned with the representation and manipulation of data. s All programs.
CS333/ Topic 11 CS333 - Introduction CS333 - Introduction General information Goals.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Sorting Chapter 10.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
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.
CIS 068 Welcome to CIS 068 ! Lesson 9: Sorting. CIS 068 Overview Algorithmic Description and Analysis of Selection Sort Bubble Sort Insertion Sort Merge.
1 Complexity Lecture Ref. Handout p
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Lecture 10: Class Review Dr John Levine Algorithms and Complexity March 13th 2006.
Course Web Page Most information about the course (including the syllabus) will be posted on the course wiki:
Chapter 12 Recursion, Complexity, and Searching and Sorting
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Analysis of Algorithms
Merge Sort. What Is Sorting? To arrange a collection of items in some specified order. Numerical order Lexicographical order Input: sequence of numbers.
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
Algorithms  Al-Khwarizmi, arab mathematician, 8 th century  Wrote a book: al-kitab… from which the word Algebra comes  Oldest algorithm: Euclidian algorithm.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
Lecture 6: Problem Solving Dr John Levine Algorithms and Complexity February 10th 2006.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
Lecture 4: Sorting Algorithms Prof Branestawm’s Sorting Challenge.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Lecture 7: Uninformed Search Dr John Levine Algorithms and Complexity February 13th 2006.
December 4, Algorithms and Data Structures Lecture XV Simonas Šaltenis Aalborg University
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
Algorithms and their Applications CS2004 ( ) Professor Jasna Kuljis (adapted from Dr Steve Swift) 6.1 Classic Algorithms - Sorting.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Sorting and Searching by Dr P.Padmanabham Professor (CSE)&Director
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
Chapter 9 Sorting. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is.
CSE 340: Review (at last!) Measuring The Complexity Complexity is a function of the size of the input O() Ω() Θ() Complexity Analysis “same order” Order.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
CES 592 Theory of Software Systems B. Ravikumar (Ravi) Office: 124 Darwin Hall.
Lecture # 1 Introduction Analysis of Algorithm by Qamar Abbas Analysis of Algorithms.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
Honors Track: Competitive Programming & Problem Solving Seminar Topics Kevin Verbeek.
Growth of Functions & Algorithms
Data Structures Lab Algorithm Animation.
Teach A level Computing: Algorithms and Data Structures
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
Welcome to CIS 068 ! Lesson 9: Sorting CIS 068.
Searching CLRS, Sections 9.1 – 9.3.
Analysis of Algorithms
Major Design Strategies
CS203 Lecture 15.
Major Design Strategies
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Presentation transcript:

Lecture 12: Revision Lecture Dr John Levine Algorithms and Complexity March 27th 2006

Lecture List Lecture 1: Why algorithms are so important Lecture 2: Big-Oh notation, a first look at different complexity classes (log, linear, log-linear, quadratic, polynomial, exponential, factorial) Lecture 3: simple search in a list of items is O(n) with unordered data but O(log n) with ordered data, and can be even faster with a good indexing scheme and parallel processors Lecture 4: sorting: random sort is O(n!), naïve sort is O(n 2 ), bubblesort is O(n 2 ), quicksort is O(n log n)

Lecture List Lecture 5: more on sorting: why comparison sort is O(n log n), doing better than O(n log n) by not doing comparisons (e.g. bucket sort) Lecture 6: harder search: how to represent a problem in terms of states and moves Lecture 7: uninformed search through states using an agenda: depth-first search and breadth-first search Lecture 8: making it smart: informed search using heuristics; how to use heuristic search without losing optimality – the A* algorithm

Lecture List Lecture 9: game tree search (Mark Dunlop’s notes), minimax and alpha-beta pruning Lecture 10: class review, ADT for lookup table, hash tables Lecture 11: Dijkstra’s algorithm Lecture 12: revision, NP-hard problems

Syllabus: Algorithmic Complexity Introduction to Algorithmic Complexity: basic algorithmic classification, with examples; the order notation (Big-oh); elementary complexity and estimation of run times; the tyranny of growth. Covered in specifically in Lectures 1 and 2 and Practical 1, also covered throughout the course Examinable Typical exam question: say what Big-oh is, give an analysis of some code fragments

Syllabus: Algorithmic Complexity Big-Oh notation (see Wikipedia article) The major classes of complexity: O(1), O(log n), O(n), O(n log n), O(n 2 ), O(n 3 ),…,O(a n ), O(n!) Analysis of nested loops and operations on arrays Why complexity is important: the tyranny of growth Easy problems (P) are solvable in polynomial time Hard problems (NP) are only solvable in exponential time It is thought that P ≠ NP but no-one has proved this

Syllabus: Searching and Sorting Searching and Sorting: the complexity of a range of techniques, including the divide and conquer approach; the relative complexity of searching and sorting algorithms; the sorting algorithms covered will include bubble sort, insertion sort, merge sort and quick sort; searching, including sequential search and the binary chop; hashing. Partially covered by Lectures 3 and 4 We’ll do a quick recap of the four sorting algorithms We’ll look at hash tables today Examinable

Syllabus: Sorting Insertion sort: insert items one at a time into the correct position in a sorted list, aka naïve sort, O(n 2 ) Bubble sort: pass through list swapping adjacent pairs, repeat until sorted, O(n 2 ) Quicksort: choose pivot as estimate of middle item, partition into two sets (> pivot, < pivot), then partition each set using the same process and repeat until the list is sorted, O(n log n) Merge sort: divide into two sets, sort each set, then merge the two sorted sets, O(n log n)

Syllabus: Sorting The best we can do by comparisons is O(n log n): n items implies n! possible unsorted sequences, each comparison divides this by 2, hence we need to make log(n!) comparisons to identify the sequence, and log(n!) ≈ n log n We don’t have to use comparisons: if we are sorting items which have a natural finite sequence, we can use something like bucket sort, which is O(n) There are numerous search algorithms: see the Wikipedia article for many more

Syllabus: Searching Linear search through an (unordered) list of items is O(n), and if n is very large we want to do better Binary search is O(log n); search using a binary tree to store the data is O(log n) Using a hash table to hold the data, the search is O(1), but finding a really good hash function is hard!

Syllabus: Game Trees Binary Trees revisited: implementations by array; expression trees; binary tree implementation of sorted list; access times; algorithms covered include traversal, searching, balancing and deletion. Already covered in Programming Techniques We did state space search and game trees instead Game trees, minimax search and alpha-beta pruning are examinable, the rest is not (because last year’s students didn’t do it) Typical exam question: map out a simple game tree and say what move the computer should make next

Syllabus: Game Trees Game trees: mapping out of states for each possible move by each player in turn Colouring the game tree: finding out what move the computer should make Minimax search: assume your opponent chooses the move to minimise the evaluation function, and you choose the move which forces the evaluation function to be maximised Alpha-beta pruning: don’t search branches of the game tree when you already know they are poor

Syllabus: Graph Algorithms Graphs revisited: directed and undirected graphs; representations of graphs; basic graph algorithms; applications of graphs to real world problems (for example telecommunications, transportation systems, dependencies between objects). To be covered next week Representation of graphs, Dijkstra’s algorithm Application to the tube map problem Examinable Typical exam question: show application of Dijkstra’s algorithm to a real world problem

Syllabus: Graph Algorithms Dijkstra’s algorithm: from initial vertex A, find all vertices reachable in a single step. Add the shortest reachable vertex and the path taken to get from A to the vertex to the set S. From this new vertex, find all vertices reachable in a single step. Now add the shortest reachable vertex which is not already in S to S. Repeat until all vertices are in S. Simple analysis: O(V 2 )

Syllabus: NP-Hard Problems Permutations and Combinations: branch and bound; greedy algorithms; backtracking search; typical problems, for example the TSP and related problems, the knapsack problem. Mostly covered by our consideration of state space search and games, and also in Topics 1 and 2 I will touch briefly on this area in my summary and revision lecture in Week 10 Not directly examinable – see the Week 10 lecture for what you need to know in this area

Syllabus: NP-Hard Problems What do you do with an NP-hard problem? Many of these are optimisation problems, so many solutions are feasible, very few are optimal Apply a polynomial time algorithm and make do with a less than perfect solution Run an improvement algorithm and wait for as long as you possibly can (always have a feasible solution) Branch-and-bound: similar to alpha-beta pruning Most instances are not hard: you may be able to find some structure in the instance which you can exploit