0 Stimmen dafür0 Stimmen dagegen

10 Aufrufe83 SeitenImportant

Nov 05, 2016

© © All Rights Reserved

PPTX, PDF, TXT oder online auf Scribd lesen

Important

© All Rights Reserved

Als PPTX, PDF, TXT **herunterladen** oder online auf Scribd lesen

10 Aufrufe

Important

© All Rights Reserved

Als PPTX, PDF, TXT **herunterladen** oder online auf Scribd lesen

- The Woman Who Smashed Codes: A True Story of Love, Spies, and the Unlikely Heroine who Outwitted America's Enemies
- Steve Jobs
- NIV, Holy Bible, eBook
- NIV, Holy Bible, eBook, Red Letter Edition
- Hidden Figures Young Readers' Edition
- Cryptonomicon
- Make Your Mind Up: My Guide to Finding Your Own Style, Life, and Motavation!
- The Golden Notebook: A Novel
- Alibaba: The House That Jack Ma Built
- The 10X Rule: The Only Difference Between Success and Failure
- Autonomous: A Novel
- Hit Refresh: The Quest to Rediscover Microsoft's Soul and Imagine a Better Future for Everyone
- Hit Refresh: The Quest to Rediscover Microsoft's Soul and Imagine a Better Future for Everyone
- Life After Google: The Fall of Big Data and the Rise of the Blockchain Economy
- Algorithms to Live By: The Computer Science of Human Decisions
- Console Wars: Sega, Nintendo, and the Battle that Defined a Generation
- The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution

Sie sind auf Seite 1von 83

Data Structures

Lecture 1

Dr. Iftikhar Azim Niaz

ianiaz@comsats.edu.pk

Quaid-i-Azam University

Presidents Gold Medalist

Karachi University

Methodology) 2010

2

Deck Officer

Quaid-i-Azam University

Head of Department

Lecturer

Islamabad Campus

3

Why?

Why are you

studying Data

Structure and

Computer

Science ?

interest, or commitment that makes

somebody want to do something, or

something that causes such a feeling

Encarta Dictionary

Just a random choice, no particular reasons

A required course

I failed CSC211 before;

Want to be taught by a tough instructor

More

5

is ...

I take it because I

am interested

Course Details

Course Code:

CSC 211

Course Title:

Data Structures

Credit Hours:

3+1

Course Prerequisites CSC141

Course Objectives:

The course is designed to teach students

structures and schemes, which allow them

to write programs to efficiently manipulate,

store, and retrieve data.

Course Description

has been recognized as a discipline whose mastery is

fundamental and crucial to the success of many

engineering projects and which is amenable to

scientific treatment and presentation.

It has advanced from a craft to an academic discipline

it is abundantly clear that a systematic and scientific

approach to program construction primarily has a

bearing in the case of large, complex programs which

involve complicated sets of data.

Hence, a methodology of programming is also bound

to include all aspects of data structuring.

8

Course Objectives

and understanding of algorithms and data

structures and the associated design and

analysis techniques

To examine previously studied algorithms and

data structures more rigorously and introduce the

student to "new" algorithms and data structures.

It focuses the student's attention on the design of

program structures that are correct, efficient in

both time and space utilization, and defined in

terms of appropriate abstractions.

9

Course Goals

will be able to:

structures, trees, graphs, and hash tables

Select appropriate data structures for a specied problem

Compare and contrast the basic data structures used in

Computer Science: lists, stacks, queues, trees and graphs

Describe classic sorting techniques

Recognize when and how to use the following data

structures: arrays, linked lists, stacks, queues and binary

trees.

Identify and implement the basic operations for

manipulating each type of data structure

10

Course Goals

student will be able to:

algorithms.

Apply various sorting algorithms including bubble, insertion,

selection and quick sort.

Understand recursion and be able to give examples of its

use

Use dynamic data structures

Know the standard Abstract Data Types, and their

implementations

Students will be introduced to (and will have a basic

understanding of) issues and techniques for the assessment

of the correctness and efficiency of programs.

11

Course Outline - I

Linear and non-linear data structures

Arrays and pointers

List data structure

Singly linked list

Doubly linked list

Analysis of List data structures

Circular linked list

Stack; Implementation of stack using arrays and

linked list

Applications of a stack

12

Course Outline - II

Evaluation of postfix expressions

Queues; Implementation of queues using arrays

and linked list

Circular Queues; Priority Queues;

Trees; Tree traversals; Binary search trees and

implementation

Heaps and Heap sort;

Graphs; Minimum spanning trees;

Hashing

Files

13

Recommended Books

Textbooks:

Design in C, 2nd Edition, Pearson Education Inc. India , 2007

2nd Edition, Pearson Education Inc. India, 1997 .

Reference Books:

Prentice Hall India, 2009

Publishing Company, New Delhi, India, 2006.

14

15

16

Assignments .

15%

Quizzes

10%

Sessionals

25%

Final

....

....

. 50%

17

A Nice Quote

Want to get something in life

Always think positive

You will definitely get the thing you want

18

A nice saying

I keep 6 honest serving men.

They taught me all I knew.

Their names are:

WHAT and WHY and WHEN and HOW and WHERE

and WHO.

(R. Kipling)

on the road of learning,

these are your best companions.

19

Work Hard

Try More

exercises and

more practice

assignments by

yourself

20

Five Tips

Machine

that, do it quietly

21

you?

yes

No

22

23

Your Question:

24

So your answer:

Great thinkers

will always be needed.

25

Study:

code up binary search.

Good thing is was not for a

nuclear power plant.

26

algorithmic design techniques.

27

Programming is Problem

Solving

Programming is a process of problem solving

Outline the problem requirements

Specify what the solution should do

Design steps, called an algorithm, to solve the

problem (the general solution)

Verify that your solution really solves the problem

process in which a solution is arrived at in a

finite amount of time

28

Computer Programming

Nicklaus Wirth

that allows a machine to perform various tasks

which, by hand, would be tedious or so time

consuming as to be essentially impossible to do.

Machines work incredibly quickly, never get tired,

and are excellent at following orders; however, they

will only perform as well as the instructions

presented to them.

Set of instructions that tell the computer what to do

and how to do?

29

Introduction to Problem

Solving

Programming is a problem solving activity.

writing an instruction for the computer to solve

something for you.

Problem solving is the process of transforming

the description of a problem into a solution 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.

30

amount to be paid by a customer buying

cupcakes.

31

using Software Development Method

(SDM), which is as follows:

1.

2.

3.

4.

5.

6.

Analyze the problem.

Design the algorithm to solve the problem.

Implement the algorithm.

Test and verify the completed program.

Documentation

32

1. Requirement Specification

requires you to state the problem clearly

and to gain the understanding of what to

be solved and what would be the solution.

When specifying problem requirement, we

ask ourselves the following questions:

What the solution should provide.

What is needed to solve it.

If there are constraints and special conditions.

33

Yummy Cupcake

Problem: You are required to calculate the amount to be

paid by a customer buying cupcakes.

34

Problem Analysis

identify the following:

media to be used

Output(s) expected from the problem, their

form and the output media to be used

Special constraints or conditions (if any)

Any formulas or equations to be used

35

Yummy Cupcake

Input?

Quantity of the cupcake purchased (integer)

Price per cupcake (RM, float)

Output?

Total amount to be paid by the customer (RM, float)

Constraint/condition?

Quantity purchased must be more than zero

Price per cupcake must be more than zero (it is not free)

We assume that the price given is the standard price to all

cupcakes

Formula/equation?

36

Designing algorithm

requires you to develop a list of steps,

arranged in a specific logical order which,

when executed, produces the solution for a

problem.

Using top-down design (also called divide and

conquer):

For each major task, you further divide it into subtasks (refinement step)

computers point of view.

37

It must have an output(s)

It should not be ambiguous (there should not be

different interpretations to it. Every step in algorithm

must be clear as what it is supposed to do)

It must be general (it can be used for different

inputs)

It must be correct and it must solve the problem for

which it is designed

It must execute and terminate in a finite amount of

time

It must be efficient enough so that it can solve the

intended problem using the resource currently

available on the computer

38

Yummy Cupcake

Major Task:

1.

Read the quantity of cupcake purchased

2.

Read the price per cupcake

3.

Calculate total amount to pay

4.

Display the total amount to pay

However, looking at the above algorithm, we can still further refine

step 3, by introducing the formula to calculate the amount to pay.

After refinement:

5.

Read the quantity of cupcake purchased

6.

Read the price per cupcake

7.

Total amount to pay = quantity of cupcake x price per cupcake

8.

Display the total amount to pay

39

algorithm is very important. Consider the

following, will the result be the same?

1.

2.

3.

pay

Get the quantity of cupcake

purchased

Total amount to pay = quantity

of cupcake x price per cupcake

40

Control Structure

Pseudocode or Flowchart.

In 1966, two researchers, C. Bohn and G.

Jacopini, demonstrated that any algorithm

can be described using only 3 control

structures: sequence, selection and

repetition.

41

Control Structure

statements that are executed in the

order they are written in an algorithm.

Selection: Defines two courses of action

depending on the outcome of a condition.

A condition is an expression that is, when

computed, evaluated to either true or

false.

Repetition: Specifies a block of one or

more statements that are repeatedly

executed until a condition is satisfied.

42

What is an Algorithm?

There are two parts to a computer

program.

There is the process or sequence of

steps which are necessary to

complete the given task and

the translation of this process into a

language which the computer can

understand.

43

Algorithm (Definition)

for performing some action.

A precisely defined sequence of (computational

steps) that transform a given input into a

desired output.

An algorithm tells us how to perform a task.

The logical steps to solve a problem.

Some examples of algorithms in everyday life

are food preparation, directions for assembling

equipment or instructions for filling out income

tax forms.

44

supplied

Output: At least one desired result is produced

Definiteness: Each instruction must be clear

and unambiguous

Finiteness: Algorithm terminates after a finite

number of steps

Effectiveness: Each instruction must be

feasible and very basic

45

From Algorithms to

Programs

Problem

Algorithm: A sequence

of instructions describing

how to do a task

Computer Program

46

Algorithm Representation

Pseudocode

Algorithm

Flow Chart

47

What is Pseudocode?

steps in an algorithm diagrammatically. These were

bulky, difficult to draw and often led to poor

program structure.

Pseudocode is the method of writing down an

algorithm.

Pseudocode is easy to read and write. It represents

the statements of an algorithm in English like

language.

Pseudocode is really structured English. It is

English which has been formalised and abbreviated

to look like very high level computer languages.

48

Pseudocodes

that can be used to design and describe

algorithms.

Gives the correct solution in all cases

Eventually ends

49

Example of Pseudocode

1. Open freezer door

2. Take out Meal

3. Close freezer door

4. Open microwave door

5. Put Meal on carousel

6. Shut microwave door

7. Set microwave on high for 5 minutes

8. Start microwave

9. Wait 5 minutes

10. Open microwave door

11. Remove Meal

12. Close microwave door

50

Example of Algorithm

procedure Do_Thursday

{

Wake_up ;

Take_A_Shower ;

Eat_Breakfast ;

Drive_To_university ;

Attend_ALGO_Lecture ;

...etc...etc...etc...

Drive_From_university ;

...etc...etc...etc...

}

procedure Do_Week

{

Do_Monday ;

Do_Tuesday ;

Do_Thursday ;

...etc...etc...etc...

}

51

Pseudocode

relaxed syntax that

extended version of the

is easy to read

basic control structures

(sequential, conditional,

iterative)

52

Pseudocode Rules

There are however certain conventions:

Statements are written in simple English;

Each instruction is written on a separate line;

Logic-showing Keywords are written in UPPER

CASE

(e.g. IF , THEN, FOR, WHILE )

Each set of instructions is written from top to

bottom with only one entry and one exit;

Groups of statements may be formed into

modules, and that group given a name.

53

Pseudocode

The symbol is used to indicate that the

reminder of a line should be treated as a

comment. If more than one statement appears on

a single line, a semicolon will be used to separate

them.

ASSIGNMENT STATEMENTS have the form x

e, which assigns the value of expression e to

variable x. Multiple assignments can be

performed in one statement; for example,

x

y e assigns the value of e to variables x

and y.

54

Pseudocode

x := e

where x is a variable and e is an expression.

When an assignment statement is executed,

values of all variables in the expression), and

then its value is placed in the memory location

corresponding to x (replacing any previous contents

of this location) .

55

Find an algorithm that takes two values x and y

interchanged to obtain the output.

Method: If we try

x := y

y :=x

We would not obtain the desired output. Step 1

correctly changed x but the original value of x

was lost. Step 2 has no effect on the value of y.

To obtain the desired results, we must save the

original value of x.

56

obtain the desired results, we must save

Example

1.

2.

3.

4.

5.

assigning the value of x to a new variable

called Save.

Input x, y

[Input the values]

Save := x [Storing the original x]

x := y

[Part of the output]

y := Save [The original x value]

Output x, y

[Values Transposed]

57

Flowcharts

show a step by step solution using symbols

which represent a task.

shapes that are connected by flow lines.

It is an alternative to pseudocoding;

whereas a pseudocode description is

verbal, a flowchart is graphical in nature.

58

Flowchart Symbols

Terminal symbol - indicates the beginning and

end points of an algorithm.

Process symbol - shows an instruction other than

input, output or selection.

Input-output symbol - shows an input or an

output operation.

Disk storage I/O symbol - indicates input

from or output to disk storage.

Printer output symbol - shows hardcopy printer

output.

59

Selection symbol - shows a selection

process for two-way selection.

Off-page connector provides continuation of

a logical path on another page.

On-page connector - provides continuation

of logical path at another point in the same

page.

Flow lines - indicate the logical sequence of

execution steps in the algorithm.

60

A series of steps or statements that are executed in the

structure

order they are written in an algorithm.

optionally marked with the keywords begin and end.

begin

statement 1.

statement 2.

statement n.

end

begi

n

statement 1

statement 2

statement n

end

61

structure

Problem:

calculate a persons age

Begin

read birth year

age = current year birth year

display age

End

begi

n

Age = current

year birth year

Display age

end

62

Defines two courses of action depending on the

structure

outcome of a condition. A condition is an expression

false.

The keyword used are if and else.

Format:

if (condition)

then-part

else

else-part

end_if

No

elsestatement(s)

Condition?

Yes

thenstatement(s)

63

Beginstructure

read age

if (age is greater than 55)

print Pencen

else

print Kerja lagi

end_if

End

Begin

read age

if (age > 55)

print Pencen

else

print Kerja lagi

end_if

End

Begin

Read age

YES

NO

print Pencen

End

64

Sometimes

in certain situation, we may omit the else-part.

control

structure

print This is an odd number

end_if

Example 1

contains other if/else structure in its then-part or else-part.

if (number is equal to 1)

print One

else if (number is equal to 2)

print Two

else if (number is equal to 3)

print Three

else

print Other

end_if

Example 2

65

Exercise

Draw the flowchart diagram for

Example 1 and Example 2

66

Specifies a block of one or more

structure

until a condition is satisfied.

The keyword used is while.

Format:

while (condition)

loop-body

end_while

Condition?

yes

Loop

Statement(s)

no

67

the age of 10 people (one after another).

For this problem, we need a way to count how many people

whose age have been processed (read and displayed).

Therefore, we introduce a concept of counter, a variable

used to count the number of people whose age have been

processed by the program.

68

Counter initialisation

Begin

number of users giving his age = 1

while (number of users giving his age <= 10)

read the age from the user.

Loop condition

print the user age.

number of user giving his age + 1

Updating counter

end_while

End

Begin

users = 1

while (users <= 10)

read age

print age.

users = users + 1

end_while

End

69

Begin

users = 1

NO

End

YES

read age

print age

users =users + 1

70

Subsequently..

You can start the

counter with ZERO

Begin

number of users giving his age = 0

while (number of users giving his age < 10)

read the age from the user.

print the user age.

The loop condition

must less than the

number of user giving his age + 1

value it requires to

end_while

stop

End

Begin

users = 0

while (users < 10)

read age

print age.

users = users + 1

end_while

End

Be

consiste

nt

71

Little extra

have learnt so far.

Problem:

Write a program that will calculate and print the

age of 10 persons, given their birth year. If the

age of the person is above 55, then the

program will print Pencen, otherwise, the

program will print Kerja lagi.

72

Begin

Example 3

users = 1

while (users <= 10)

begin

Read birth year

age = current year birth year

Note that in this

print age

example, we are

if age > 55

using all the

print Pencen

three control

else

structures:

print Kerja lagi

sequence,

end_if

selection and

users = users + 1

repetition

end

end_while

End

73

Exercise

Draw the flowchart diagram for

Example 3

74

Implementation

writing a computer program using a programming

language (for example, using C language)

of the intended problem

supposed to do

(Think of those many viruses, buffer overflows, trojan

horses, etc. that we experience almost daily. All these

result from programs doing more than they were

intended to do)

75

executing a program to demonstrate its

correctness

ensuring that a program meets userrequirement

execute the program and test/verify it with

different inputs before the program can be

released to the public or other users (or to

the instructor of this class)

76

Documentation

program does.

Writing comments between the line of codes

Creating a separate text file to explain the

program

modify your program, but also for you to

understand your own program after a long time

(believe me, you will forget the details of your

own program after some time ...)

77

Documentation cont

whole of or a part of it again

Other programmer or end user will need some

information about your program for reference or

maintenance

You may someday have to modify the program, or may

discover some errors or weaknesses in your program

stage of software development method, it is

actually an ongoing process which should be

done from the very beginning of the software

development process.

78

Exercise time!!!

79

Volume calculation

Write a pseudocode and a flowchart for a

C program that reads the value of height,

width and length of a box from the user

and prints its volume.

80

The unit for electricity usage is kWh. For

domestic usage, the monthly rate is 21.8

cents/unit for the first 200 unit, 25.8 cents/unit

for the next 800 units and 27.8 cents/unit for

each additional units. Given the amount of

electricity units (in kWh) used by a customer,

calculate the amount of money needs to be

paid by the customer to TNB. A bill statement

needs to be printed out.

Write a pseudocode or a flow chart to solve

the above problem.

81

Sum of 1 to 10

Write a pseudocode or flowchart for a

program that would compute and print the

sum of all integers between 1 and 10.

82

Summary

Introduced the concept of problem

solving : a process of transforming the

description of a problem into a solution.

consists of 6 steps

selection and repetition structures

83

- comp_thinking.pdfHochgeladen vonEugenia Maria Ohota
- Introduction to Linked ListHochgeladen vonNaldrein Rean Luansing
- Unit 1Hochgeladen vonjedes
- BCA Syllabus Scheme Syllabus 2011-12Hochgeladen vonKomal Sehrawat Dahiya
- Stack OverflowHochgeladen vonredchaoz
- Why BrownHochgeladen vonJim Homer
- Problem SolvingHochgeladen vonsantoshbjs
- Set Data Structure-2Hochgeladen vonTech_MX
- CTI_Courseware_-_EMPD_-_Cert_-_eBook.B.pdfHochgeladen vonred12red
- jitev7iip001-013scott1.pdfHochgeladen vonAhmad Shiddiq
- DS Lab-TP-2013Hochgeladen vonDeb Chaudhuri
- PoliciesHochgeladen vonEdwin Okoampa Boadu
- Semester II MCA SyllabusHochgeladen vonNitesh Sharma
- stacks using linked list codeHochgeladen vonmohsankayani3462
- scimakelatex.20425.xxx6Hochgeladen vonborlandspam
- Unit - 1Hochgeladen vonprinceji
- Computer sem 3Hochgeladen vonAtish Jain
- Practical FileHochgeladen vonDevansh Gupta
- Algorithms 11 00158Hochgeladen vonamine.besrour5214
- sesem4lmannualHochgeladen vonSherrilVincent
- Lecture07 StructuresHochgeladen vonZhu Ghe Liang
- 2008_43Hochgeladen vonAkshay Aggarwal
- complete.pdfHochgeladen vonMárcio Moscoso
- HRM CaseHochgeladen vonAhmad Siddiq Rasooly
- Practicing as Problem Solving - BoomKaMusicHochgeladen vonAnonymous gZoIU7Z
- Training for CES'sHochgeladen vonOana Stanculescu-Ilie
- p12-Teimoori_FaalHochgeladen vonMas Gund
- Advantages of Heterogeneous Agent Populations for Exploration and Pathfinding in Unknown TerrainHochgeladen vonSEP-Publisher
- edtc520 implementationplan ggarciaHochgeladen vonapi-409951254
- Prog Contemporary-World FBD EnHochgeladen vonchela

- 05308264Hochgeladen vonRakesh Thapliyal
- SAP TDI FAQHochgeladen vonumeshkr1234
- Autoliv LeanHochgeladen vonRajasekaran Murugan
- Geomembrane Gcl BrochureHochgeladen vonMohammad Shehab Bhuiyan
- Rights of Way - OECD DefnHochgeladen vonSulekha Bhattacherjee
- User Manual Mini Cassette FJM_CACHochgeladen vonutaiuliancatalin
- hazard identificationHochgeladen vonAmi Osh
- PGPX Brochure Class of 2016.pdfHochgeladen vonPrasant Goel
- Manual Satellite p755 s5120Hochgeladen vonEnrique Espino Maraví
- Ebers Moll Model Ppt Compatibility ModeHochgeladen vonA Rama Lakshman Reddy
- LaserJet 1018 SMHochgeladen vonasc401
- At Info Security AwarenessHochgeladen vonsagarfrom
- ACME - Spool Valve Leakage BehaviourHochgeladen vonUros Gordic
- Aldon-gate Openers 2012Hochgeladen vonedmartstmanserv
- Ujian Setara 1 2017 KimiaHochgeladen vonZulkifli Bin Pari
- 3566_E_032_A4Hochgeladen vonArshad Jummani
- W B Holzapfel- Physics of solids under strong compressionHochgeladen vonYsam2
- Introduction to GISHochgeladen vonAnthony Mulenga
- durgeshHochgeladen vonDurgesh Gupta
- kaizenHochgeladen vonRyan Llaneta
- OTBI Quick HintsHochgeladen vonmanoj
- Dbms Project ReportHochgeladen vonGarry Kmr
- OSI MODEl Business....PDF FilleHochgeladen vonHumanist Mahbub Alam
- Heat Spy CatalogHochgeladen vonSathish Kumar
- 3D_Consolidation_of_Tunis_Soft_Clay_Impr.pdfHochgeladen vonamine ayari
- VLC Farmland EAHochgeladen von2rQiTPh4Kn
- Adeel AejazHochgeladen vonADEEL.AEJAZ
- ISO 9001 2015 Change Matrix - DIS.pdfHochgeladen vonAllen de Guzman
- Old Techniques New Channel Mobile Malware Adapting Pc Threat Techniques PDF 8 w 1049Hochgeladen vonAditya Vijay
- Abrasive Grinding PresentationHochgeladen vonSanjay Mehrishi

## Viel mehr als nur Dokumente.

Entdecken, was Scribd alles zu bieten hat, inklusive Bücher und Hörbücher von großen Verlagen.

Jederzeit kündbar.