ds new

37
Presented By: Guided By: DEVKARAN Ms. FARHAT ANJUM (BCA II,2015) HOD, Computer Science 1

Upload: csgdrcst

Post on 12-Apr-2017

41 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Ds new

Presented By: Guided By:DEVKARAN Ms. FARHAT ANJUM(BCA II,2015) HOD, Computer Science 1

Page 2: Ds new

2

Chapter 1Chapter 1

Objectives

• Use pseudocode in the development of algorithms • Understand the need for Abstract Data Type (ADT)• Understand the implementation of ADTs• Use void pointers and pointer to functions• Understand the role of Big-O notation

Basic ConceptsBasic Concepts

Page 3: Ds new

3

Pseudocode

Pseudocode is an English-like representation of the algorithm logic. It Pseudocode is an English-like representation of the algorithm logic. It consists of an extended version of the basic algorithmic constructs: consists of an extended version of the basic algorithmic constructs:

sequence, selection, and iterationsequence, selection, and iteration. . • Algorithm Header

• Purpose, Condition, and Return• Statement Numbers • Variables• Statment Constructs • Algorithm Analysis

Page 4: Ds new

4

Page 5: Ds new

5

Page 6: Ds new

6

The Abstract Data Type

An ADT consists of a data declaration packaged An ADT consists of a data declaration packaged together with the operations that are meaningful together with the operations that are meaningful on the data while embodying the structured on the data while embodying the structured principles of encapsulation and data hiding. In this sectionprinciples of encapsulation and data hiding. In this sectionwe define the basic parts of an ADT.we define the basic parts of an ADT.

• Atomic and Composite Data• Data Type• Data Structure• Abstract Data Type

Page 7: Ds new

7

Page 8: Ds new

8

Data StructureAggregation of atomic and composite data into a set with defined relationships. Structure refers to a set of rules that hold the data together.

• A combination of elements in which each is either a data type or another data structure.

• A set of associations of relationship involving combined elements.

Example:

Page 9: Ds new

9

Page 10: Ds new

ADT users are NOT concerned with how the task is done but rather what it can do.

An abstract data type is a data declaration packaged together with the operations that are meaningful for the data type.

We encapsulate the data and the operations on the data, and then hide them from the user.

All references to and manipulation of the data in a data structure are handled through defined interfaces to the structure.

10

Page 11: Ds new

11

Model for an Abstract Data Type

In this section we provide a conceptual model for an Abstract Data Type (ADT).

• ADT Operation – passage like• ADT Data Structure – controlled entirely

Page 12: Ds new

12

Page 13: Ds new

13

ADT Implementations

There are two basic structures we can use to implement an ADT list: arrays and linked lists. In this section we discuss the basic linked-list implementation.

• Array Implementation• Linked List Implemenation

Page 14: Ds new

14

Page 15: Ds new

15

Page 16: Ds new

16

Page 17: Ds new

17

Generic Code for ADT

In this section we discuss and provide examples of two C tools that are required to implement an ADT.

• Pointer to Void• Pointer to Function

Page 18: Ds new

18

Page 19: Ds new

19

Page 20: Ds new

20

Page 21: Ds new

21

Page 22: Ds new

22

(Continued)

Page 23: Ds new

23

Page 24: Ds new

24

Page 25: Ds new

25

Page 26: Ds new

26

Page 27: Ds new

27

(Continued)

Page 28: Ds new

28

Page 29: Ds new

29

Page 30: Ds new

30

Page 31: Ds new

31

Page 32: Ds new

32

Page 33: Ds new

33

Page 34: Ds new

34

Page 35: Ds new

35

Page 36: Ds new

36

Algorithm EfficiencyTo design and implement algorithms, programmers To design and implement algorithms, programmers must have a basic understanding of what constitutes must have a basic understanding of what constitutes good, efficient algorithms. good, efficient algorithms.

Linear Loops -Efficiency is a function of the number of intstructions. - Loop update either adds or subtracts.

• Logarithmic Loops-The controlling variable is either multiplied or divided in each iteration.- The number of iteration is a function of the multiplier or divisor.

• Nested Loops- The number of iterations is the total number which is the product of the number of iterations in the inner loop and number of iterations in the outer loop.

• Big-O Notation -Not concerned with exact measurement of efficiency but with the magnitude.- A dominant factor determines the magnitute.

Page 37: Ds new

37