Top Banner
Data Structures and Algorithms Week #1
36

Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Jan 02, 2016

Download

Documents

Neil Davis
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Data Structures and Algorithms

Week #1

Page 2: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Data Structures and Algorithms

This course represents the foundation of your Computer Science education.

This will be a challenging course 6 Programming projects of increasing difficulty. I am here to guide and help you succeed in a

difficult subject. I am not here to teach you programming. I can teach you how to cook but I cannot teach you good programming skills.

Learning C++ is an individual journey that takes time and practice.

Page 3: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Data Structures and Algorithms

Data Structures and Algorithms The key to your professional reputation A much more dramatic effect can be made on the performance

of a program by changing to a better algorithm than by hacking converting to assembler

Keep your text for long-term reference! Professional software engineers have algorithms text(s) on their

shelves Hackers have user manuals for the latest software package

Which they’ll have to throw away next year anyway!

Page 4: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Data Structures and Algorithms If you don't understand anything, ASK!

I do my best but I can't read your mind I'll always assume that if you don't ask than you understood everything and

know the subject

The skills that you learn here will not only help you the Data Structures Comp Exam, they will follow you throughout your career.

For these reasons you should try your best to do well in this course if you want have success in this field.

Meet the challenge head on and….

Enjoy!

Page 5: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Data Structures and Algorithms

Exams and Coursework

3 Exams (45% of final grade) - EG Exam 1: September 23rd (30% of EG) Exam 2: November 4th (30% of EG) Final Exam: December 11th (40% of EG)

6 Projects (50% of final grade) - PG Project 1: September 11th (1/6th of PG) Project 2: September 25th (1/6th of PG) Project 3: October 16th (1/6th of PG) Project 4: October 30th (1/6th of PG) Project 5: November 13th (1/6th of PG) Project 6: November 27th (1/6th of PG)

5% for attendance and participation in class - PAG

Page 6: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Data Structures and Algorithms

Grading Table

0 - 100 grade Letter Equivalent

0 - 59

60 - 70

70 - 80

80 - 90

90 - 100 A

B

C

D

F

Page 7: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Data Structures and Algorithms

Books Required

Algorithms in C++Robert SedgewickAddison-Wesley

Recommended Any programming language book as reference

for example:The C++ Programming LanguageStroustrup, BAddison-Wesley

Page 8: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Data Structures and Algorithms

General Policies

For detailed information see policy sheet Late programming projects will be accepted based on the

following policy: 1 day late: less 25% 2 days late: less 50% 3 days late: less 75% 4 days late: not accepted

All days count (including Saturday, Sunday and bank holidays) Projects are submitted in class (hard copy and floppy). Refer to

the policy sheet for more details Submissions using email are not accepted

Page 9: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Data Structures and Algorithms

General Policies Cheating will not be tolerated. If caught, disciplinary actions

will be taken. It's OK to help some of your friends who may have problems

in their projects but it is not OK to share code or answers. If they need, help them but never show your answers

All projects should be done individually Mid Term Exam will be 75 minutes long; Final will be 120

minutes long. All exams are accumulative

Page 10: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Discrete Math review

Sets Logarithmic Functions Logic Induction Counting

Page 11: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Sets

A set is a collection of individual elements in the domain D. The universal set U contains every element in D . The null set contains no element.

If A is a set in the domain D , A must be a subset of the universal set U , denoted as A U.

If A consists of some but not all elements, A is then called a proper subset of U , denoted as

A U .

Page 12: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Sets

A set is a collection of definite and separate objects.

The cardinality of a set is the number of elements in the set.

A subset of a set is a set comprised of a sub-collection of the elements of the original set.

Example: Consider the set S = {2, 5, 7}. The subsets of S are the sets {2} , {5}, {7}, {2,5} , {2,7} , {5,7} , {2, 5, 7}and {} (the empty set).

Fact: If a set has cardinality = n  , then the number of subsets = 2n .

Page 13: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Sets

A proper subset of a set is a set comprised of a sub-collection of some, but not all, of the elements of the original set.

Example: Consider the set S = {2, 5, 7}. The proper subsets of S are the sets {2} , {5}, {7}, {2,5} , {2,7} , {5,7} and {} (the empty set).

S = cardinality of 3 23 7 ?

Page 14: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Sets There are only two different types of sets: 1. 1. An Infinite Set is a set that can always be

placed in a one-to-one correspondence to a proper subset of itself.

 The Basic Infinite Set is the set of positive whole numbers {1, 2, 3, 4, 5,……}. New Notation: The Basic Infinite Set has cardinality =   .

A Finite Set is a set that cannot be placed in a one-to-one correspondence to a proper subset of itself.

Something to think about….2 subsets ?

Page 15: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Logarithmic Functions

Logarithms were invented about 1614 by John Napier.  The word logarithm was derived from two Greek words, logos, which means "ratio," and arithmos, which means "number." 

Before calculators and computers were available, common logarithms were used to do certain kinds of calculations

Growth and decay Big O notation growth of computational complexity

Page 16: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Logarithmic Functions

Logarithms are exponents A logarithmic function is the inverse of an

exponential function One way to describe a logarithmic function is

to interchange variables in the equation y = ax

Thus, x = ay is logarithmic

Page 17: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Logarithmic Functions

For logarithmic functions we use the notation loga x

Therefore, The following are equivalent.1. x = ay;  and

2. y = loga x

Page 18: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Logarithmic Functions

Definition of Logarithm Suppose b> 0 and .  For n > 0, there is a

number p such that logb n = p if and only if bp

= n. log2 256 = ? 2p = 256

log10 1000 = ? 10p = 1000

log7 2401 = ? 7p = 2401

Page 19: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

LogicExamples: Boolean functions: NOT, AND, OR, XOR, . . .

a NOT( a)0 11 0

Page 20: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

LogicExamples: Boolean functions: NOT, AND, ORExamples: Boolean functions: NOT, AND, OR

a a NOT( a)NOT( a)

0 10 1

1 01 0

a b AND( a, b)

0 0 0

0 1 0

1 0 0

1 1 1

a b OR( a, b)

0 0 0

0 1 1

1 0 1

1 1 1

Page 21: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

LogicExamples: Boolean functions: XOR, XNOR, NORExamples: Boolean functions: XOR, XNOR, NOR

a b XOR( a, b)

0 0 0

0 1 1

1 0 1

1 1 0

a b XNOR( a, b)

0 0 1

0 1 0

1 0 0

1 1 1

a b NOR( a, b)

0 0 1

0 1 0

1 0 0

1 1 0

Page 22: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

LogicBoolean SimplificationBoolean Simplification

Express Express FF in terms of in terms of AA and and BB

A B A B FF

0 1 0 1 00

1 0 1 0 11

1 1 1 1 11

F = AB + AB

A ( B + B ) = F

Using the uniting theorem

Page 23: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

The P word….Induction

The Principle of Mathematical Induction

Suppose we have an assertion P(n) about the positive integers. Then if we show both of (i) and (ii) below, then P(n) is true for all

n >= 1. (i). P(1) is true (ii). For each k >= 1: If P(k) is true, then P(k+1) is true.

Page 24: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

The P word….Induction

Prove that Prove that 1+2+3+…+ n1+2+3+…+ n = =

n(n+1)2

Prove that Prove that 1+3+5+…+ (2n – 1)1+3+5+…+ (2n – 1) = = nn22

Page 25: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

SeriesArithmetic

One common type of series is the arithmetic series (also called an arithmetic progression). Each new term in an arithmetic series is the previous term plus a given number. For example this is an arithmetic series: 1+4+7+10+13+....

In this case each term is the previous term plus 3. The difference between each term (the 3 in this case) is called the "common difference" and is generally denoted by the letter d.

There are many arithmetic series that have d=3. To specify which series we mean, we need to know one more piece of information: the value of the first term (usually called "a").

Page 26: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Series

Arithmetic If we're given a and d, then, that specifies a

unique arithmetic series. All arithmetic series therefore have the following form: a+(a+d)+(a+2d)+(a+3d)+....

So in general we can say that the value of the nth term is a+(n-1)d

Page 27: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Series

Geometric Another common type of series is the geometric series (also

called a geometric progression). In this case, each term is the previous term multiplied by a given number.

Here's a geometric series, for example:2+6+18+54+...

In this case, each term is the previous term multiplied by 3. The number you multiply by (in this case 3) is called the "common ratio" and is generally denoted by r.

There are many geometric series that have r=3. To specify which series we mean, again we need to know one more piece of information: the value of the first term (usually called "a").

Page 28: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Series

Geometric A geometric series is uniquely specified by the

values of a and r. Every geometric series has the following form:

a+ar+ar2+ar3+....... Writing the series in this way we can see the

formula for working out the value of any term. The first term is just a. The second term is a multiplied by r once. The third term is a multiplied by r twice, and so on. So the nth term must be a multiplied by r (n-1) times, that's arn-1.

Page 29: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Series

Are there others?

Page 30: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Counting

Product Rule: n ways to do m tasks = nm ways.

How many different bit strings are there of length 7?

Page 31: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Counting

Pigenhole Principle: If N objects are placed into k boxes, then there is at least one box containing at least [N/k] objects.

Ten persons were born on the 1st, 11th and the 27th of the months of May, August and November. How many share the exact same birthday?

Tells us nothing of the date. Asserts only that one exists!

Page 32: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Counting

Permutations and Combinations

Permutations: Given that position is important, if one has 4 different objects (e.g. A, B, C and D), how many unique ways can they be placed in 3 positions (e.g. ABD, ACD, BDA, DBA, BAD, ADB, ADC, DCA, DAC, CDA etc.)

An ordered arrandement of r elements of a set is called a r-permutation.

n!(n – r)!

P( n, r ) =

Page 33: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

CountingPermutations and Combinations

Combinations: If one has 4 different objects (e.g. A, B, C and D) how many ways can they be grouped as 2 objects when position does not matter (e.g. AB, AC, AD are correct but DA is not ok as is equal to AD.)

An r-combination is simply a subset of the set with r elements.

C ( n, r ) = n!

r! ( n-r )!

Page 34: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Base Conversion

The base value of a number system is the number of different values the set has before repeating itself. For example, decimal has a base of ten values, 0 to 9. Binary = 2 (0, 1) Octal = 8 (0 - 7) Decimal = 10 (0 - 9) Duodecimal = 12 (used for some purposes by the Romans) Hexadecimal = 16 (0 - 9, A-F) Vigesimal = 20 (used by the Mayans) Sexagesimal = 60 (used by the Babylonians)

Page 35: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Base Conversion

Successive Division 3710 base 6

37/6 = 6 r 1 6/6 = 1 r 0 1/6 = 0 r 1 3710 base 6 = 101

Page 36: Data Structures and Algorithms Week #1. Data Structures and Algorithms This course represents the foundation of your Computer Science education. This.

Base Conversion

1016 base 10 1x60+0x61+1x62 = 1+0+36 = 37

5810base4

11110base13