L01_BasicCounting_print

L01_BasicCounting_print - 1 COMP170 Discrete Mathematical...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 COMP170 Discrete Mathematical Tools for Computer Science Discrete Math for Computer Science K. Bogart, C. Stein and R.L. Drysdale Section 1.1, pp. 1-8 Basic Counting Version 2.0: Last updated, May 13, 2007 Slides c 2005 by M. J. Golin and G. Trippen 2 Counting What’s the big deal? Counting is easy, isn’t it? How many different ways are there to choose 2 balls from 6 How many different ways are there to choose 2 students from a class of 4 students? 6 Same as balls 3 Counting What’s the big deal? Counting is easy, isn’t it? How many different ways are there to choose 2 balls from 6 How many different ways are there to choose 2 students from a class of 5 students? 10 Might still be able to list all 4 Counting What’s the big deal? Counting is easy, isn’t it? How many different ways are there to choose 2 balls from 6 How many different ways are there to choose 2 students from a class of 100 students? Too many to list 4950 5 Counting What’s the big deal? Counting is easy, isn’t it? How many different ways are there to choose 2 balls from 6 How many different ways are there to choose 6 numbers out of 1 . . . 49 ? Hong Kong Mark 6! 13,983,816 6 Counting What’s the big deal? Counting is easy, isn’t it? How many different ways are there to choose 2 balls from when order counts 12 7 In Computer Science we often need to count objects. Sometimes it’s the number of steps a computer program takes This lets us compare runtimes of different programs. Sometimes, it’s the number of objects of a particular type, e.g., passwords containing between 6-10 characters This lets us evaluate security. The more passwords available, the lower the chance that someone can guess a password 8 1.1 Basic Counting • The Sum Principle and set notation • Abstraction • Summing Consecutive Integers • The Product Principle • Two-Element Subsets 9 The Sum Principle Start with an exercise illustrating the sum principle. Consider the following loop from selection-sort , (comp171) , which sorts a list of items (1) for i = 1 to n-1 (2) for j = i +1 to n (3) if (A[ i ] > A[ j ]) (4) exchange A[ i ] and A[ j ] If you’ve never programmed before Don’t worry! This is Pseudocode ; You will learn more in the tutorial 10 The Sum Principle Start with an exercise illustrating the sum principle. Consider the following loop from selection-sort , (comp171) , which sorts a list of items (1) for i = 1 to n-1 (2) for j = i +1 to n (3) if (A[ i ] > A[ j ]) (4) exchange A[ i ] and A[ j ] How many times is the comparison A[ i ] > A[ j ] made in line 3? 11 Lines 2–4 are executed n- 1 times, once for each i between 1 and n- 1 . (1) for i = 1 to n-1 (2) for j = i +1 to n (3) if (A[ i ] > A[ j ]) (4) exchange A[ i ] and A[ j ] 12 Lines 2–4 are executed n- 1 times, once for each i between 1 and n- 1 ....
View Full Document

This note was uploaded on 08/25/2010 for the course COMP COMP170 taught by Professor M.j.golin during the Spring '10 term at HKUST.

Page1 / 38

L01_BasicCounting_print - 1 COMP170 Discrete Mathematical...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online