DAST, Spring 2004. © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

Garfield AP Computer Science
CSE332: Data Abstractions Lecture 14: Beyond Comparison Sorting Dan Grossman Spring 2010.
Lecture 12: Revision Lecture Dr John Levine Algorithms and Complexity March 27th 2006.
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Algorithms Recurrences. Definition – a recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs Example.
Spring 2015 Lecture 5: QuickSort & Selection
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
CSE332: Data Abstractions Lecture 12: Introduction to Sorting Tyler Robison Summer
© 2006 Pearson Addison-Wesley. All rights reserved10-1 Chapter 10 Algorithm Efficiency and Sorting CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 4 Comparison-based sorting Why sorting? Formal analysis of Quick-Sort Comparison.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Object (Data and Algorithm) Analysis Cmput Lecture 5 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this.
Analysis of Algorithms CS 477/677 Midterm Exam Review Instructor: George Bebis.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Data Structures, Spring 2004 © L. Joskowicz 1 DAST – Final Lecture Summary and overview What we have learned. Why it is important. What next.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
CSE 373 Data Structures Lecture 15
1 Summary of lectures 1.Introduction to Algorithm Analysis and Design (Chapter 1-3). Lecture SlidesLecture Slides 2.Recurrence and Master Theorem (Chapter.
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.
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
Teaching Teaching Discrete Mathematics and Algorithms & Data Structures Online G.MirkowskaPJIIT.
1 Summary of lectures 1.Introduction to Algorithm Analysis and Design (Chapter 1-3). Lecture SlidesLecture Slides 2.Recurrence and Master Theorem (Chapter.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Sorting Sanghyun Park Fall 2002 CSE, POSTECH. Sorts To Consider Selection sort Bubble sort Insertion sort Merge sort Quick sort Why do we care about sorting?
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Analysis of Algorithms
CSC 41/513: Intro to Algorithms Linear-Time Sorting Algorithms.
ECOE 456/556: Algorithms and Computational Complexity Lecture 1 Serdar Taşıran.
Algorithms  Al-Khwarizmi, arab mathematician, 8 th century  Wrote a book: al-kitab… from which the word Algebra comes  Oldest algorithm: Euclidian algorithm.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Fall 2015 Lecture 4: Sorting in linear time
1 CSE 326: Data Structures Sorting It All Out Henry Kautz Winter Quarter 2002.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
Cliff Shaffer Computer Science Computational Complexity.
Data Structure Introduction.
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.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Searching and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
1 BIM304: Algorithm Design Time: Friday 9-12am Location: B4 Instructor: Cuneyt Akinlar Grading –2 Midterms – 20% and 30% respectively –Final – 30% –Projects.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Sorting and Searching by Dr P.Padmanabham Professor (CSE)&Director
Algorithm Analysis (Big O)
CES 512 Theory of Software Systems B. Ravikumar (Ravi) Office: 141 Darwin Hall Course Web site:
Searching Topics Sequential Search Binary Search.
CES 592 Theory of Software Systems B. Ravikumar (Ravi) Office: 124 Darwin Hall.
DATA STRUCTURES (CS212D) Overview & Review Instructor Information 2  Instructor Information:  Dr. Radwa El Shawi  Room: 
Program Performance 황승원 Fall 2010 CSE, POSTECH. Publishing Hwang’s Algorithm Hwang’s took only 0.1 sec for DATASET1 in her PC while Dijkstra’s took 0.2.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
19 March More on Sorting CSE 2011 Winter 2011.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
Sorting and Runtime Complexity CS255. Sorting Different ways to sort: –Bubble –Exchange –Insertion –Merge –Quick –more…
Algorithm homework help For More Detail help.aspx - Phone:-
Lecture 2 Algorithm Analysis
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
Advanced Algorithms Analysis and Design
Summary of lectures Introduction to Algorithm Analysis and Design (Chapter 1-3). Lecture Slides Recurrence and Master Theorem (Chapter 4). Lecture Slides.
Objective of This Course
Chapter 3: The Efficiency of Algorithms
CSE 326: Data Structures Sorting
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Presentation transcript:

DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems Lecture and exercise topics Style of lectures and requirements

DAST, Spring © L. Joskowicz 2 Programs and algorithms Why do we need algorithms?  to solve problems with a computing device What is the difference between an algorithm and a program?  a program is an implementation of an algorithm to be run on a specific computer and operating system. An algorithm is more abstract in that it does not deal with machine specific details – think of it as a method to solve a problem. The course emphasis is on algorithms.

DAST, Spring © L. Joskowicz 3 Data structures A data structure is a method of storing data for the purpose of efficient computation  variables, arrays, linked lists, binary trees How data is stored is key for how a problem will be solved. Assumptions about the nature of the data determine what data structure and algorithm will be used  sorting integers vs. words Data structures and algorithm development go hand in hand! You cannot have one without the other!

DAST, Spring © L. Joskowicz 4 Abstract Data Types –ADT An abstract data type is a collection of formal specifications of data-storing entities with a well designed set of operations. The set of operations defined with the ADT specification are the operations it “supports” What is the difference between a data structure (or a class of objects) and an ADT?  The data structure or class is an implementation of the ADT to be run on a specific computer and operating system. Think of it as an abstract JAVA class. The course emphasis is on ADTs.

DAST, Spring © L. Joskowicz 5 Focus of the course In this course, we will study algorithms and ADTs for solving the most common computational problems: searching, sorting, indexing, etc. We will learn how to rigorously analyze an algorithm and describe its space and time complexity  is A1 always better than A2? We will learn how to adapt know algorithms and develop new ones. You will implement in JAVA variations of the algorithms to better understand them!

DAST, Spring © L. Joskowicz 6 Algorithms and problem solving Say you have a computational problem to solve Is there an algorithm that solves it?  not always! Example: the halting problem. Is there an efficient algorithm that solves it?  not always! Example: packing problem. Is my algorithm the best possible algorithm?  not necessarily! Example: sorting in O(n 2 ) What is the best algorithm we can develop?  sorting takes Ω(nlogn) time and Ω(n) space.

DAST, Spring © L. Joskowicz 7 Easy problems, hard problems Over the past 50 years (and especially the last 30 years), many algorithms for a wide variety of computational tasks have been developed A classification of hard and easy problems has also been developed, together with formal tools to prove what is their complexity and how they are related to each other.  Equivalence classes of complexity Ω(n) – linear; Ω(nlogn); Ω(n 2 ) – quadratic; Ω(n k ) – polynomial; Ω(2 n ) – exponential; Ω( 2 2 n ) doubly exponential unsolvable!

DAST, Spring © L. Joskowicz 8 Easy problem: shortest path planning Find the shortest path (minimum number of changes and stops) between two stations in the Paris metro O(n) in the number of segments

DAST, Spring © L. Joskowicz 9 Bin packing: a hard problem! Given a board and a set of parts, pack them without overlap so that they occupy the smallest rectangle. 7 parts, 30 squares

DAST, Spring © L. Joskowicz 10 Bin packing: possible solutions 40 squares 36 squares

DAST, Spring © L. Joskowicz 11 Bin packing: optimal solution Algorithm Generate all the legal combinations record area covered keep the best one 30 squares Number of legal configurations: combinatorial There is no better solution in the worst case!!

DAST, Spring © L. Joskowicz 12 What kind of efficiency? Given an algorithm A, we can ask the following questions on its time and space complexity. Best case: what is the complexity for the most favorable kind of input? Worst case: what is the complexity for the least favorable kind of input? Average case: what is the complexity for the average kind of input? Upper and lower bounds: what is the best we can do for this problem? Trade-off between time and space.

DAST, Spring © L. Joskowicz 13 Efficiency: sorting Given an array of n integers A[i], sort them in increasing order. Two algorithms (among many others) to do this: BubbleSort: compare two adjacent numbers, and exchange them if A[i-1] < A[i]. Repeat n times. MergeSort: recursively split the array in half, sort each part, and then merge them together.

DAST, Spring © L. Joskowicz Bubble sort (1) One pass start nd iteration st iteration n th iteration … …

DAST, Spring © L. Joskowicz 15 Bubble sort (2) nd pass rd pass n th pass … … n passes 1 st pass

DAST, Spring © L. Joskowicz 16 Merge sort (1) Split phase level

DAST, Spring © L. Joskowicz 17 Merge sort (2) Merge phase level

DAST, Spring © L. Joskowicz 18 Comparison SPACET Best I M Worst E Average Bubble Sort nn one pass n 2 n passes n 2 /2 n/2 passes Merge Sort n log n MergeSort: Number of levels: 2 l = n  l = log 2 n Time for merge: n

DAST, Spring © L. Joskowicz 19 Other types of algorithms and analyses Up to now, you have studied exact, deterministic algorithms. There are other types as well: Randomized algorithms: makes random choices during execution: pick a random element from an array instead of the first one  minimize the chances of always picking a bad one! Probabilistic analysis for randomized algorithms Approximation algorithms: instead of finding an optimal solution, find one close to it  bin packing.

DAST, Spring © L. Joskowicz 20 Course topics (1) Techniques for formal analysis of asymptotic algorithm complexity with recurrence equations Techniques for solving recurrence equations: substitution, recursion-tree, master method. Proving upper and lower bounds Sorting, in-depth: merge sort, quick sort, counting sort, radix sort, bucket sort.

DAST, Spring © L. Joskowicz 21 Course topics (2) Common ADTs and their algorithms: heaps, priority queues, binary trees, AVL trees, Red- Black trees, B-trees. Huffman codes, hash tables, hash functions Graph algorithms: Breadth-First Search, Depth-First Search, Shortest path algorithms, Minimum Spanning Trees, Strongly Connected Components. Union-Find of sets (time permitting).

DAST, Spring © L. Joskowicz 22 Programming skills Selected topics in JAVA Learn how to choose and implement ADTs Design and program a medium size project: the bookstore Learn how to use a debugger

DAST, Spring © L. Joskowicz 23 Style of the lectures Algorithms and ADTs are described at a higher level, in pseudo-code, not in JAVA. We assume you know how to program by now, so you can turn an algorithm and an ADT into a JAVA program. More abstract and rigorous thinking: formal proofs of complexity, proofs of algorithm correctness.

DAST, Spring © L. Joskowicz 24