September 10, 2001 Algorithms and Data Structures Simonas Šaltenis Nykredit Center for Database Research Aalborg University

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

September 12, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
ALGORITHMS Introduction. Definition Algorithm: Any well-defined computational procedure that takes some value or set of values as input and produces some.
Chapter 1 – Basic Concepts
September 19, Algorithms and Data Structures Lecture IV Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Introduction to Analysis of Algorithms
CSE 830: Design and Theory of Algorithms
1 Data Structures A program solves a problem. A program solves a problem. A solution consists of: A solution consists of:  a way to organize the data.
CSE 830: Design and Theory of Algorithms Dr. Eric Torng.
Introduction to Algorithm design and analysis
COMP s1 Computing 2 Complexity
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
CSC2105: Algorithms Mashiour Rahman American International University Bangladesh.
Algorithms Friday 7th Week. Algorithms What is an Algorithm? –A series of precise steps, known to stop eventually, to solve a problem –NOT necessarily.
Introduction Data Structures & Algorithm Data Structures & Algorithm.
Lecture 2 Computational Complexity
2IL50 Data Structures Fall 2015 Lecture 2: Analysis of Algorithms.
September 15, Algorithms and Data Structures Simonas Šaltenis Aalborg University
Jessie Zhao Course page: 1.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
September 29, Algorithms and Data Structures Lecture V Simonas Šaltenis Aalborg University
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
1Computer Sciences Department. Book: Introduction to Algorithms, by: Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Electronic:
September 17, 2001 Algorithms and Data Structures Lecture II Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
September 9, Algorithms and Data Structures Lecture II Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 1. Complexity Bounds.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 2: Getting Started.
Computer Science/Ch. Algorithmic Foundation of CS 4-1 Chapter 4 Chapter 4 Algorithmic Foundation of Computer Science.
Introduction to Complexity Analysis. Computer Science, Silpakorn University 2 Complexity of Algorithm algorithm คือ ขั้นตอนการคำนวณ ที่ถูกนิยามไว้อย่างชัดเจนโดยจะ.
Algorithms A well-defined computational procedure that takes some value as input and produces some value as output. (Also, a sequence of computational.
2IS80 Fundamentals of Informatics Fall 2015 Lecture 6: Sorting and Searching.
Searching Topics Sequential Search Binary Search.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
2IL50 Data Structures Spring 2016 Lecture 2: Analysis of Algorithms.
September 10, 2001 Algorithms and Data Structures Simonas Šaltenis Nykredit Center for Database Research Aalborg University
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
September 18, Algorithms and Data Structures Lecture II Simonas Šaltenis Aalborg University
Lecture 2 Algorithm Analysis
CMPT 438 Algorithms.
Advanced Algorithms Analysis and Design
COP 3503 FALL 2012 Shayan Javed Lecture 15
Introduction Algorithms Order Analysis of Algorithm
Data Structures and Algorithms
CS 3343: Analysis of Algorithms
Introduction to the Design and Analysis of Algorithms
Algorithms and Data Structures Lecture VI
Introduction to Algorithms
Sorting by Tammy Bailey
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
Algorithm Analysis CSE 2011 Winter September 2018.
DATA STRUCTURES Introduction: Basic Concepts and Notations
CS 583 Fall 2006 Analysis of Algorithms
CS 3343: Analysis of Algorithms
Algorithm Analysis (not included in any exams!)
Algorithms + Data Structures = Programs -Niklaus Wirth
Asymptotic Notations Algorithms Lecture 9.
Objective of This Course
Algorithms and Data Structures Lecture III
Algorithms + Data Structures = Programs -Niklaus Wirth
CS200: Algorithms Analysis
CSE 2010: Algorithms and Data Structures Algorithms
Algorithms and Data Structures
Ch. 2: Getting Started.
Math/CSE 1019N: Discrete Mathematics for Computer Science Winter 2007
Algorithms and Data Structures Lecture II
Algorithms and Data Structures
Presentation transcript:

September 10, 2001 Algorithms and Data Structures Simonas Šaltenis Nykredit Center for Database Research Aalborg University

September 10, Administration People Simonas Šaltenis Anders B. Christensen Daniel Povlsen Home page Check the homepage frequently! Course book “ Introduction to Algorithms”, 2.ed Cormen et al. Lectures, Fib 15, A, 8:15-10:00, Mondays and Thursdays

September 10, Administration (2) Exercises: every week after the lecture Exam: SE course, written Troubles Simonas Šaltenis E1-215

September 10, Syllabus Introduction (1) Correctness, analysis of algorithms (2,3,4) Sorting (1,6,7) Elementary data structures, ADTs (10) Searching, advanced data structures (11,12,13,18) Dynamic programming (15) Graph algorithms (22,23,24) Computational Geometry (33) NP-Completeness (34)

September 10, What is it all about? Solving problems Get me from home to work Balance my checkbook Simulate a jet engine Graduate from SPU Using a computer to help solve problems Designing programs (architecture, algorithms) Writing programs Verifying programs Documenting programs

September 10, Data Structures and Algorithms Algorithm Outline, the essence of a computational procedure, step-by-step instructions Program – an implementation of an algorithm in some programming language Data structure Organization of data needed to solve the problem

September 10, Overall Picture Data Structure and Algorithm Design Goals Implementation Goals Correctness Efficiency Robustness Adaptability Reusability

September 10, Overall Picture (2) This course is not about: Programming languages Computer architecture Software architecture Software design and implementation principles Issues concerning small and large scale programming We will only touch upon the theory of complexity and computability

September 10, History Name: Persian mathematician Mohammed al-Khowarizmi, in Latin became Algorismus First algorithm: Euclidean Algorithm, greatest common divisor, B.C. 19 th century – Charles Babbage, Ada Lovelace. 20 th century – Alan Turing, Alonzo Church, John von Neumann

September 10, Algorithmic problem Infinite number of input instances satisfying the specification. For example: A sorted, non-decreasing sequence of natural numbers. The sequence is of non-zero, finite length: 1, 20, 908, 909, , Specification of input ? Specification of output as a function of input

September 10, Algorithmic Solution Algorithm describes actions on the input instance Infinitely many correct algorithms for the same algorithmic problem Input instance, adhering to the specification Algorithm Output related to the input as required

September 10, Sort Example: Sorting INPUT sequence of numbers a 1, a 2, a 3,….,a n b 1,b 2,b 3,….,b n OUTPUT a permutation of the sequence of numbers Correctness For any given input the algorithm halts with the output: b 1 < b 2 < b 3 < …. < b n b 1, b 2, b 3, …., b n is a permutation of a 1, a 2, a 3,….,a n Correctness For any given input the algorithm halts with the output: b 1 < b 2 < b 3 < …. < b n b 1, b 2, b 3, …., b n is a permutation of a 1, a 2, a 3,….,a n Running time Depends on number of elements (n) how (partially) sorted they are algorithm Running time Depends on number of elements (n) how (partially) sorted they are algorithm

September 10, Insertion Sort A 1nj i Strategy Start “empty handed” Insert a card in the right position of the already sorted hand Continue until all cards are inserted/sorted Strategy Start “empty handed” Insert a card in the right position of the already sorted hand Continue until all cards are inserted/sorted for j=2 to length(A) do key=A[j] “insert A[j] into the sorted sequence A[1..j-1]” i=j-1 while i>0 and A[i]>key do A[i+1]=A[i] i-- A[i+1]:=key for j=2 to length(A) do key=A[j] “insert A[j] into the sorted sequence A[1..j-1]” i=j-1 while i>0 and A[i]>key do A[i+1]=A[i] i-- A[i+1]:=key

September 10, Analysis of Algorithms Efficiency: Running time Space used Efficiency as a function of input size: Number of data elements (numbers, points) A number of bits in an input number

September 10, The RAM model Very important to choose the level of detail. The RAM model: Instructions (each taking constant time): Arithmetic (add, subtract, multiply, etc.) Data movement (assign) Control (branch, subroutine call, return) Data types – integers and floats

September 10, Analysis of Insertion Sort for j=2 to length(A) do key=A[j] “insert A[j] into the sorted sequence A[1..j-1]” i=j-1 while i>0 and A[i]>key do A[i+1]=A[i] i-- A[i+1]:=key cost c 1 c 2 0 c 3 c 4 c 5 c 6 c 7 times n n-1 n-1 n-1 n-1 Time to compute the running time as a function of the input size

September 10, Best/Worst/Average Case Best case: elements already sorted  t j =1, running time = f(n), i.e., linear time. Worst case: elements are sorted in inverse order  t j =j, running time = f(n 2 ), i.e., quadratic time Average case: t j =j/2, running time = f(n 2 ), i.e., quadratic time

September 10, Best/Worst/Average Case (2) For a specific size of input n, investigate running times for different input instances: 1n 2n 3n 4n 5n 6n

September 10, Best/Worst/Average Case (3) For inputs of all sizes: 1n 2n 3n 4n 5n 6n Input instance size Running time ….. best-case average-case worst-case

September 10, Best/Worst/Average Case (4) Worst case is usually used: It is an upper-bound and in certain application domains (e.g., air traffic control, surgery) knowing the worst-case time complexity is of crucial importance For some algorithms worst case occurs fairly often The average case is often as bad as the worst case Finding the average case can be very difficult

September 10, Growth Functions

September 10, Growth Functions (2)

September 10, That’s it? Is insertion sort the best approach to sorting? Alternative strategy based on divide and conquer MergeSort sorting the numbers is split into sorting and and merging the results Running time f(n log n)

September 10, Example 2: Searching INPUT sequence of numbers (database) a single number (query) a 1, a 2, a 3,….,a n ; q j OUTPUT an index of the found number or NIL ; ; 9 NIL

September 10, Searching (2) j=1 while j<=length(A) and A[j]!=q do j++ if j<=length(A) then return j else return NIL j=1 while j<=length(A) and A[j]!=q do j++ if j<=length(A) then return j else return NIL Worst-case running time: f(n), average-case: f(n/2) We can’t do better. This is a lower bound for the problem of searching in an arbitrary sequence.

September 10, Example 3: Searching INPUT sorted non-descending sequence of numbers (database) a single number (query) a 1, a 2, a 3,….,a n ; q j OUTPUT an index of the found number or NIL ; ; 9 NIL

September 10, Binary search left=1 right=length(A) do j=(left+right)/2 if A[j]==q then return j else if A[j]>q then right=j-1 else left=j+1 while left<=right return NIL left=1 right=length(A) do j=(left+right)/2 if A[j]==q then return j else if A[j]>q then right=j-1 else left=j+1 while left<=right return NIL Idea: Divide and conquer, one of the key design techniques

September 10, Binary search – analysis How many times the loop is executed: With each execution its length is cult in half How many times do you have to cut n in half to get 1? lg n

September 10, Next Week Correctness of algorithms Asymptotic analysis, big O notation.