Important

© All Rights Reserved

9 views

Important

© All Rights Reserved

- The Relationship Between the World Wide Web and the UNIVAC Computer With SAROS
- Linked Lists
- Teaching Guide for When Times Are Tough - BrickHouse Education - TG9781598351033
- Data Structures.list Implementation
- 2nd Quarter Math 8 Project
- Basic Math Ass
- Handout Data Structures
- 52158371-DATA-STRUCTURE-AND-PROGRAMMING-METHODOLOGY
- lessonplanforgradeone
- DCIT22 Course Syllabus
- csc
- amcat syllabus
- hamilton reflection part 2
- ed127 itcr 2 - ana parra
- kuvempu university Assignment b41
- hello1
- Appreciation
- Matrix Rotation
- MCM0412.
- Learn Code

You are on page 1of 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

- The Relationship Between the World Wide Web and the UNIVAC Computer With SAROSUploaded byGath
- Linked ListsUploaded byapi-3807137
- Teaching Guide for When Times Are Tough - BrickHouse Education - TG9781598351033Uploaded byBrickHouse Education Website
- Data Structures.list ImplementationUploaded bynothingelse420
- 2nd Quarter Math 8 ProjectUploaded byLabli Mercado
- Basic Math AssUploaded bydivyaloga
- Handout Data StructuresUploaded byshanpriyaelango
- 52158371-DATA-STRUCTURE-AND-PROGRAMMING-METHODOLOGYUploaded bySahil Singla
- lessonplanforgradeoneUploaded byapi-354309794
- DCIT22 Course SyllabusUploaded bySofia Rodriguez
- cscUploaded byBala Kirshnan
- amcat syllabusUploaded byahamedyaseen
- hamilton reflection part 2Uploaded byapi-380367681
- ed127 itcr 2 - ana parraUploaded byapi-285889647
- kuvempu university Assignment b41Uploaded byArindam
- hello1Uploaded byLavanya
- AppreciationUploaded byHafiy Wak
- Matrix RotationUploaded byKunal Malhotra
- MCM0412.Uploaded byYogesh2323
- Learn CodeUploaded byIvánCadena
- Preeja Unit1 Linked List (1)Uploaded byPreeja Ravishankar Wayanad
- Problem SolvingUploaded bySiddharth Gupta
- So Question n AnswerUploaded byRAVI
- COMPUTER SCIENCE TECHNICAL TEST PLACEMENT PAPER-1.docUploaded bymm281991
- Linked ListUploaded byNandaShivani
- Lecture 4 data structure Linked List.pptUploaded bySello Hlabeli
- DS-Unit-I NewUploaded byMathiazhagan Arumugam
- Week 1 2019Uploaded byDileep Chenugulapalli
- year 8 rural experience - disruptive innovationUploaded byapi-37392463
- sem3Uploaded bySahrukh Khan

- System Verilog FAQsUploaded byRavindra Mathanker
- ADSP-InstrUploaded byPynsuk Pk
- GOOGLE SketchUp - Tutorial Bezier Spline (Writing Ruby Extension)Uploaded byXaverius Nanda
- Load CombinationsUploaded bymas ayu
- simulation of ac engineUploaded byAFAparicio
- Ozone Architecture v1Uploaded byHimanshu Rathore
- Introductioon to Object OrientationUploaded byMuhammad Imron
- FPM OverviewUploaded bySabsKrishna
- pSOSUploaded byapi-19457121
- 03-ETL-081028-2055Uploaded byMahesh Sharma
- qtp-dumpsUploaded byRamu Palanki
- C Interview Question and AnswersUploaded byharis313
- smrtUploaded bynanoscribdlogin
- Cto Non Ebs LoadUploaded byposhala_raj
- Corona Intellij SettingsUploaded byAlessandro Crippa
- daaUploaded byRajesh Manoharan
- Sending Smart Forms in HTML FormatUploaded byChaithanya
- 6 Golden Rules for New SAP HANA Developers _ SCNUploaded bydanielpinto01
- sctp-apiUploaded bytuhinsundey
- Web ServicesUploaded byRishi Mathur
- Percepio ManualUploaded by沈德鴻
- seleniumUploaded byNheb Naares Nheb Naarees
- Mat Lab TrainingUploaded byIng Toreto Diaz
- c++ prodictionUploaded byMøHämêdZãķârįä
- Modern Web Development.pdfUploaded byTadeoRiverosKoloszwa
- progcppUploaded byBolan Oluwa
- Open Office BaseUploaded byoniebles01
- ENGG1811 Assignment 1 (Semester 1, 2017)Uploaded bySasuke
- Executing Microsoft SQL Server Stored Procedure From PHP on LinuxUploaded byAbhilash V Pillai
- sequencing.pptxUploaded bySundaramali Govindaswamy G

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.