Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Mathematics CS 2610

Similar presentations


Presentation on theme: "Discrete Mathematics CS 2610"— Presentation transcript:

1 Discrete Mathematics CS 2610
February 24, part 5

2 Algorithm- Insertion Sort
For each element: The elements on its left are already sorted Shift the element with the element on the left until it is in the correct place. See animation

3 Algorithm- Insertion Sort
procedure insertSort (a1, a2, …, an: distinct integers) for j=2 to n begin i=j - 1 while i > 0 and ai > ai+1 swap ai and ai+1 i=i-1 end Worst-Case: The sequence is in decreasing order At step j, the while loop condition is executed j times the body of the loop is executed j-1 times

4 Greedy Algorithms Can you think of a better solution ?
Problem: Assign meeting to conference rooms Policy: In decreasing order of room capacity, assign a meeting to the next largest available room Room A 200 Room B 150 Room C 150 Room D 100 Room E 75 Room F 50 Meeting 1: 70 Meeting 2: 46 Meeting 3: 125 Meeting 4: 110 Meeting 5: 30 Meeting 6: 87 M 1 M 2 Can you think of a better solution ? M3 X M5 X

5 Greedy Algorithm Policy: : In ascending order of room capacity, assign a meeting to the smallest room that can hold the meeting. Room A 200 Room B 150 Room C 150 Room D 100 Room E 75 Room F 50 Meeting 1:70 Meeting 2:46 Meeting 3:125 Meeting 4:110 Meeting 5:30 Meeting 6:87 M 2 M 1 M5 M3 M4 M6

6 Order of Growth Terminology
O(1) Constant O(log cn) Logarithmic (c  Z+) O(logc n) Polylogarithmic (c  Z+) O(n) Linear O(nc) Polynomial (c  Z+) O(cn) Exponential (c  Z+) O(n!) Factorial Best Worst

7 Complexity of Problems
Tractable A problem that can be solved with a deterministic polynomial (or better) worst-case time complexity. Also denoted as P Example: Search Problem Sorting problem Find the maximum

8 Complexity of Problems
Intractable Problems that are not tractable. Example: Traveling salesperson problem Wide use of greedy algorithms to get an approximate solution. For example under certain circumstances you can get an approximation that is at most double the optimal solution.

9 P vs. NP NP: Solvable problems whose solution can be checked in polynomial time. PNP The most famous unproven conjecture in computer science is that this inclusion is proper. PNP rather than P=NP

10 Complexity of Problems
Not Solvable Proven to have no algorithm that computes it Example: Halting problem (Alan Turing) Determine whether an arbitrary given algorithm, will eventually halt for any given finite input. Corollary: The question of whether or not a program halts for a given input is unsolvable.


Download ppt "Discrete Mathematics CS 2610"

Similar presentations


Ads by Google