Algorithm & data structures lec1

21
Algorithm & Data Structures CSC-112 Fall 2011

description

It covers the basic introduction of algorithms

Transcript of Algorithm & data structures lec1

Page 1: Algorithm & data structures lec1

Algorithm & Data Structures CSC-112Fall 2011

Page 2: Algorithm & data structures lec1

My Profile Name:

Syed Muhammad Raza

Education:

MSc Wireless Communication

LTH – Sweden , 2007-2009

BS Computer Information Sciences

PIEAS – Pakistan , 2002-2006

Contact Information:

Email: (Preferred mean of communication)

[email protected]

Cell #: (Only in case of emergencies)

0333-5577460

Page 3: Algorithm & data structures lec1

Rules

Don’t Mess With Me&

I Won’t Mess With You

Page 4: Algorithm & data structures lec1

Course Overview

Fundamentals of Algorithms

Review of Programming

Sorting and Searching

Stacks

Queues, Priority Queues and Circular Queues

Linked List

Trees

Hashing

Graphs

Page 5: Algorithm & data structures lec1

Text Book

No Text Book&

Every Text Book

Page 6: Algorithm & data structures lec1

Marks Distribution

Lab 25% of 100 Marks

Theory 75% of 100 Marks

 

Sessional 1 = 10 Marks

Sessional 2 = 15 Marks

Final Paper = 50 Marks

Assignment = 15 Marks

Quiz = 10 Marks

Total = 100 Marks

Page 7: Algorithm & data structures lec1

Lets see what you got!

Page 8: Algorithm & data structures lec1

Algorithm

Page 9: Algorithm & data structures lec1

Problem Solving

Problem solving is the process of transforming the description of a problem into the solution of that problem by using our knowledge of the problem domain and by relying on our ability to select and use appropriate problem-solving strategies, techniques, and tools.

Page 10: Algorithm & data structures lec1

Algorithms

An Algorithm is a step by step solution to a

problem

Why bother writing an algorithm

For your own use in the future - Don't have to

rethink the problem.

So others can solve the problem, even if they

know very little about the principles behind how

the solution was derived.

Page 11: Algorithm & data structures lec1

Examples of Algorithms

Washing machine instructions

Instructions for a ready-to-assemble piece of

furniture

A Classic: GCD - Greatest Common Divisor - The

Euclidean Algorithm

Page 12: Algorithm & data structures lec1

Washing Machine Instructions

Separate clothes into white clothes and colored clothes.

For white clothes:

Set water temperature knob to HOT.

Place white laundry in tub.

For colored clothes:

Set water temperature knob to COLD

Place colored laundry in tub.

Add 1 cup of powdered laundry detergent to the tub.

Close lid and press the start button.

Page 13: Algorithm & data structures lec1

Observations

There are a finite number of steps.

We are capable of doing each of the instructions.

When we have followed all of the steps, the

washing machine will wash the clothes and then

will stop.

Are all of the clothes clean ?

Do we want the washing machine to run until all

of the clothes are clean ?

Page 14: Algorithm & data structures lec1

Refinement of the Definition

Our old definition:

An algorithm is a step by step solution to a problem.

Adding our observations:

An algorithm is a finite set of executable instructions that

directs a terminating activity.

Page 15: Algorithm & data structures lec1

Instructions for a Ready-to-Assemble Furniture

"Align the marks on side A with the grooves on

Part F “

Why are these instructions typically so hard to

follow ?

Lack of proper tools - instructions are not executable

Which side is A ? A & B look alike. Both line up with Part F

- Ambiguous instructions.

Page 16: Algorithm & data structures lec1

Final Definition

An algorithm is a finite set of unambiguous, executable instructions that directs a terminating activity.

Page 17: Algorithm & data structures lec1

History of Algorithms

The study of algorithms began as a subject in mathematics.

The search for algorithms was a significant activity of early

mathematicians.

Goal: To find a single set of instructions that could be used

to solve any problem of a particular type.

Page 18: Algorithm & data structures lec1

GCD- Euclidean Algorithm

Assign M and N the value of the larger and the value of the

smaller of the two positive integer input values, respectively.

Divide M by N and call the remainder R.

If R is not 0, then assign M the value of N, assign N the value

of R and return to step 2, otherwise the greatest common

divisor is the value currently assigned to N.

Page 19: Algorithm & data structures lec1

Finding GCD of 24 & 9

M N R

24 9 6

9 6 3

6 3 0

So 3 is the GCD of 24 and 9.

Do we need to know the theory that Euclid used to come up with this

algorithm in order to use it ?

What intelligence is required to find the GCD using this algorithm ?

Page 20: Algorithm & data structures lec1

Idea Behind the Algorithms

Once an algorithm behind a task has been

discovered

Don't need to understand the principles.

Task is reduced to following the instructions.

Intelligence is "encoded into the algorithm"

Page 21: Algorithm & data structures lec1

Algorithm Representation Syntax and Semantics

Syntax refers to the representation itself.

Semantics refers to the concept represented.