The material in this lecture should be review. If you have not seen it before, you should be able to learn it quickly – and on your own. So we are going.

Slides:



Advertisements
Similar presentations
CS 336 March 19, 2012 Tandy Warnow.
Advertisements

College of Information Technology & Design
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
CSE115/ENGR160 Discrete Mathematics 02/24/11 Ming-Hsuan Yang UC Merced 1.
Chapter 1 pp 1-14 Properties of Algorithms Pseudocode.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
Connected Components, Directed Graphs, Topological Sort COMP171.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Algorithm Design Techniques: Induction Chapter 5 (Except Section 5.6)
Recursion.
Connected Components, Directed Graphs, Topological Sort Lecture 25 COMP171 Fall 2006.
Connected Components, Directed graphs, Topological sort COMP171 Fall 2005.
Describing algorithms in pseudo code To describe algorithms we need a language which is: – less formal than programming languages (implementation details.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
C. – C. Yao Data Structure. C. – C. Yao Chap 1 Basic Concepts.
Discrete Mathematics Algorithms. Introduction  An algorithm is a finite set of instructions with the following characteristics:  Precision: steps are.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Discrete Structures Lecture 11: Algorithms Miss, Yanyan,Ji United International College Thanks to Professor Michael Hvidsten.
Lecture 13 Graphs. Introduction to Graphs Examples of Graphs – Airline Route Map What is the fastest way to get from Pittsburgh to St Louis? What is the.
CSE 311: Foundations of Computing Fall 2013 Lecture 8: More Proofs.
Analysis of Algorithms
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Lecture 1: Introduction and Overview CSCI 700 – Algorithms 1.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Mathematical Background and Linked Lists. 2 Iterative Algorithm for Sum Find the sum of the first n integers stored in an array v : sum (v[], n) temp_sum.
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
Symbol Tables and Search Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Proofs, Induction and Recursion Basic Proof Techniques Mathematical Induction Recursive Functions and Recurrence Relations.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
CSE 311 Foundations of Computing I Lecture 9 Proofs and Set Theory Autumn 2012 CSE
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
CSE 311: Foundations of Computing Fall 2013 Lecture 8: Proofs and Set theory.
Today’s Material Sorting: Definitions Basic Sorting Algorithms
TCSS 342 Autumn 2004 Version TCSS 342 Data Structures & Algorithms Autumn 2004 Ed Hong.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 23: Intractable Problems (Smiley Puzzles.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Trees.
Computer Representation of Information
Hubert Chan (Chapters 1.6, 1.7, 4.1)
CSE15 Discrete Mathematics 03/06/17
The NP class. NP-completeness
Growth of Functions & Algorithms
Methods of Proof.
Chapter 5. Greedy Algorithms
CSE373: Data Structures & Algorithms Lecture 19: Spanning Trees
Lecture 3 of Computer Science II
Hubert Chan (Chapters 1.6, 1.7, 4.1)
CS 3343: Analysis of Algorithms
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Chapter 5. Optimal Matchings
Bipartite Matching and Other Graph Algorithms
Data Structures: Segment Trees, Fenwick Trees
Applied Algorithms (Lecture 17) Recursion Fall-23
Binary Search Back in the days when phone numbers weren’t stored in cell phones, you might have actually had to look them up in a phonebook. How did you.
Algorithms Chapter 3 With Question/Answer Animations
Describing algorithms in pseudo code
Analysis Algorithms.
3.5 Minimum Cuts in Undirected Graphs
Data Structures Review Session
Algorithm Discovery and Design
CSE373: Data Structures & Algorithms Lecture 19: Spanning Trees
Basics of Recursion Programming with Recursion
Lecture 7 Algorithm Design & Implementation. All problems can be solved by employing any one of the following building blocks or their combinations 1.
This Lecture Substitution model
Foundations of Discrete Mathematics
Data Structures and Algorithm Analysis Priority Queues (Heaps)
Algorithms.
Discrete Mathematics CS 2610
Presentation transcript:

The material in this lecture should be review. If you have not seen it before, you should be able to learn it quickly – and on your own. So we are going to cover it FAST!!!

Recall how decimal representation works x10 0 3x x x

Binary numbers are the same – just use 2 instead of 10 (hence the name “base 2”) x2 0 1x2 1 +0x2 2 +1x =11 10

Follows directly from the definition. You should know how to do this – quickly. Hint: As computer scientists you should know all powers of 2 up 1024 (2 10 )

Steps for converting n to binary 1. Find the largest k such that 2 k ≤ n. 2. Make the k th digit a Compute the binary value for n – 2 k. (Stop when n = 2 k.)

Convert 22 to binary: 1.Find largest k such that 2 k ≤ 22 k = 4, 2 k = 16, n’ = n-16 = 6 Number is: 1XXXX, where XXXX is the binary representation of 6 2.Find the largest k such that 2 k ≤ 6 k = 2, 2 k = 4, n’’ = n’-4 = 2 Number is: 101XX, where XX is the binary representation of 2 3.Find the largest k such that 2 k ≤ 2 k=1, 2 k = 1, n’’’ = n’’ – 2 = 0 Number is: – done!

Logarithms Question: What is the meaning of log b a? Answer: The exponent of b that results in a. In other words: the value x such that b x = a.

log 2 16 = log 3 9 = log = log 4 4 = 1 log 5 1 = 0 6 log 6 12 = 12

Floor function:  x  or floor(x) The largest integer n such that n ≤ x (  4.7  =4) Question: What is the “meaning” of  log 2 n  ? It is the largest integer k such that 2 k ≤ n. Question: When converting decimal to binary, what is the first power of 2 we will use?  log 2 n  Question: How many bits do we need to store the number n?  log 2 n  +1

How many digits does n have in base 10?  log 10 n  +1 How many digits does n have in base b?  log b n  +1

How do we solve for n when we know: 2 n = h? 2 n = h log 2 2 n = log 2 h n = log 2 h

Start with a group of n people on an island. (Assume n is a power of 2.) Step 1: Vote half of the n people off the island. Step 2: Vote half of the (remaining) people off. Step 3: Vote half of the (remaining) people off. And so on… How many steps until we have only one person? Not necessary, but makes life easier

How many people do we have after each step? Initially (after “step 0”): n = n/2 0 people left. After step 1:  (1/2)(n/2 0 ) = n/2 1 people left After step 2: (1/2)(n/2 1 ) = n/4 = n/2 2 left After step 3: (1/2)(n/2 2 ) = n/8 = n/2 3 left … After step i: n/2 i people left When does n/2 i = 1? When n = 2 i, or i = log 2 n

Consider the NCAA Basketball Tournament (a single elimination tournament – half the teams are eliminated each round). Suppose it is expanded to 512 starting teams. How many rounds are needed to finish? log = 9 rounds

Graph : A set of nodes V and a multi-set E  V  V. v1v1 v2v2 v3v3 v4v4 v5v5 V={v 1, v 2, v 3, v 4, v 5 } E = {(v 1, v 2 ), (v 1, v 3 ), (v 1, v 4 ), (v 2, v 3 ), (v 1, v 3 ), (v 3, v 5 ), (v 4, v 5 ), (v 5, v 5 )}

Simple Graph : A set of nodes V and a multi-set E  V  V such that (v,v)  E for any v  V v1v1 v2v2 v3v3 v4v4 v5v5 V={v 1, v 2, v 3, v 4, v 5 } E = { (v 1, v 2 ), (v 1, v 3 ), (v 1, v 4 ), (v 2, v 3 ), (v 1, v 3 ), (v 3, v 5 ), (v 4, v 5 ), (v 5, v 5 )}

Simple Graph : A set of nodes V and a set E  V  V such that (v,v)  E for any v  V v1v1 v2v2 v3v3 v4v4 v5v5 V={v 1, v 2, v 3, v 4, v 5 } E = {(v 1, v 2 ), (v 1, v 3 ), (v 1, v 4 ), (v 2, v 3 ), (v 3, v 5 ), (v 4, v 5 )} In this course: all graphs will be simple – we will not bother saying it

Nodes u and v are adjacent if they share an edge (e.g. if (u,v)  E ) v1v1 v2v2 v3v3 v4v4 v5v5 Correct: “v 1 and v 3 are adjacent” Incorrect: “v 1 and v 5 are adjacent”

A path from u to v is a sequence of adjacent nodes starting at u and ending at v v4v4 v1v1 v2v2 v3v3 v5v5 Sample path: v 1, v 2, v 3, v 5 v1v1 v2v2 v3v3 v5v5

A cycle is a path from a node to itself using at least one edge. v4v4 v5v5 v1v1 v2v2 v3v3 v1v1 v2v2 v3v3

A graph is connected if there is a path between every pair of nodes v1v1 v2v2 v3v3 v4v4 v5v5 Connected Still connected Not connected Two connected components

A graph is a acyclic if it has no cycles. A graph is a tree if it is connected and acyclic. v1v1 v2v2 v3v3 v4v4 v5v5 Not acyclic. Acyclic, but not a tree. A tree.

Make sure you can define these terms (Simple) Graph Adjacent nodes Path Cycle Connected Connected Component Acyclic Tree

Proof: A logic-based argument that a given fact is true. Does not have to contain algebra or complicated mathematical terminology Should primarily consist of straight-forward English Must be clear and easily understood.

Mathematical notation is not necessary, but it is useful. It is essentially short-hand that conveys specific information. It is important that you are comfortable with both reading and using it.

N (“Natural numbers”): {0, 1, 2, …} E (“Evens”): {0, 2, 4, …} O (“Odds”): {1, 3, 5, …} Z (“Integers”): - N  N = {…, -2, -1, 0, 1, 2, …}  (“Real numbers”): Set of all real numbers

 : “There exists…” Example:  n  N n = n 2 Translation: “There exists a natural number that is equal to its own square.”  !: “There exists a unique…” Example:  ! n  N n = n Translation: There exists exactly one element in N that is two less then its own square.

 : “For all…” Example:  n  N n 2 ≥ n Translation: “For all elements n in N it is true that n 2 ≥ n.”

True or False?  n  N  x  x < n and x 2 = n False: Not true for n = 0  n  N  k  N k < n, k 2 = n True: n=4, k=2  n  N  ! k  N k < n, k 2 = n True: For n=4, k=2 is the only such k  ! n  N  k  N k < n, k 2 = n False: Can be made true for both n=4 and n=9

 : “If/then”, “implies” or “therefore” Example: n  N  n 2  n Translation: “If n is a natural number then n 2 is at least as large as n” or “n  N implies that n 2  n” or “n  N therefore n 2  n”

 : “if and only if” or “iff” Meaning: a  b equivalent to “a  b and b  a” Example:  n  N : n  E  n/2  N Translation: “For all natural numbers n: n is even if and only if n/2 is a natural number.” or “For all natural numbers n: n is even iff n/2 is a natural number.”

Pseudocode is a way of writing out algorithms in “simplified code” (on paper only) Skips the niggling details of an actual program in Java/C/ C++/Perl/Python/ Whatever Should be a easy read by you or anyone else Should be easy to convert it to code (by you or someone else) – the missing details should be obvious

We can think of pseudocode as a “basic” language that supports the minimum needed amount of functionality Rules: Should be easy to read Should not be bogged down in details Each line should be easily implemented

Sample Pseudocode: Bubble Sort BubbleSort(Array A, int n) 1.for i  0 to n-1 2.for j  0 to n-1-i 3.if A[j] < A[j+1] 4.swap(A[j], A[j+1]) Parameters type declarations help with clarity, but are not required Assignment operator simple enough that its not worth writing out

FindMax(Array A, int n) 1.max  -  2.for i  0 to n-1 3.if A[i] > max 4.max = A[i] 5.return max We will assume we have a built in  value.

In this course we will be writing algorithms, not programs You will describe them with pseudocode Must be clear Should convey sufficient detail for implementation Should not assume existence of complicated functions unless we have done them in class