1. fundamental concept - data structures using c++ by varsha patil

49
Oxford University Press © 2012 Data Structures Using C++ by Dr Varsha Patil 1. FUNDAMENTAL CONCEPTS 1

Upload: widespreadpromotion

Post on 12-Jan-2017

1.291 views

Category:

Data & Analytics


14 download

TRANSCRIPT

Page 1: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

1Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

1. FUNDAMENTAL CONCEPTS

Page 2: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

2Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Objectives Understand the well-defined, clear, and simple

approach of program design Learn fundamental aspects of algorithm and

its characteristics Learn basic concepts such as data, data type,

data object, data structure, etc. Know the power of Abstract Data Type (ADT) Study about Software Development Life

Cycle (SDLC)

Page 3: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

3Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Introduction To Programming

Program Data

Computer

Output

Fig 1: Processing a Program

Page 4: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

4Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Computer Languages can be classified into the following

3 basic categories

Machine Language Assembly Language High-level Language

Page 5: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

5Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Object-Oriented Programming

OOP is used to model the real world through objects

Object-oriented decomposition views software as a set of well-defined objects that model entities in the application domain

These objects interact with each other to form a software system

Page 6: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

6Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Introduction To Data Structures

Data Data Type Data Object Data structure Abstract Data Types (ADT)

Page 7: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

7Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Data Data is nothing but a piece of information Data input, data manipulation (or data processing)

and data output are the themes of computer The address of the ith element is calculated by the

following formula

Atomic Data Composite Data

Page 8: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

8Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Data Type Data type is a term that specifies the type of

data that a variable may hold in the programming language

Built-in Data TypesUser Defined Data Types

Page 9: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

9Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Data Object A Data Object represents a container for data

values a place where data values

may be stored and later retrieved Data Object is runtime instance of data

structure

Page 10: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

10Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Data Structure

A combination of elements each of which is either a data type or another data structure and

A set of associations or relationships (structures) involving the combined elements

A data structure is a set of domains D, a designated domain d Î D, a set of function F, and a set of axioms A

The triple (D, F, A) denotes the data structure d and it will usually be written as d

A Data Structure is

Page 11: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

11Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Data Object An Abstract Data Type is a data declaration

packaged together with the operations that are meaningful for the data type

Abstract Data Type includes declaration of data, implementation of operations, and encapsulation of data and operations

Page 12: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

12Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Types Of Data Structures

Primitive and Non-Primitive Data Structures

Linear and Non-linear Data Structures Static and Dynamic Persistent and Ephemeral Data Structures Sequential Access and Direct Access Data

Structures

Page 13: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

13Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Linear Data Structure

A Data Structure is said to be linear if its elements form a sequence or a linear list

Linear Data Structure, every data element has unique successor and unique predecessor

Page 14: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

14Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Non Linear Data Structure In non-linear data structures, every data

element may have more than one predecessor as well as successor

Elements do not form any particular linear sequence

Page 15: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

15Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Introduction to Algorithms Characteristics of Algorithm Algorithmic Design Tools Pseudo Code Flow chart

Page 16: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

16Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Algorithms The step-by-step solution is called an Algorithm Algorithm is independent of computer system and

programming language The real world performance of any software depends on two

things The algorithm chosen, and The suitability and efficiency of various layers of

implementation

Page 17: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

17Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Characteristics of Algorithms

Input Output Unambiguous Steps Finiteness Effectiveness

Page 18: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

18Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Algorithmic includes- How to devise algorithms How to validate algorithms How to analyze algorithms

Page 19: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

19Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Pseudo Code Pseudo code Notations Algorithm Header Purpose Conditions and Return Statement Statement Numbers Variables Statement Constructs Sub Algorithms

Page 20: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

20Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Statement Construct

Sequence Decision Repetition

Page 21: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

21Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Figure 2: Sequence construct

Page 22: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

22Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Figure 3: Decision Construct

If a condition is true,

Then

Else

AlgorithmPurpose :Comparing two numbersPre: NonePost: NoneReturn: None1) Read two numbers Num1 and Num22) If Num1 > Num2a. Then Print Num1b. Else Print Num23) Stop

Series of Actions

Series of Actions

Example

Page 23: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

23Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Figure 3: Decision Construct

If a condition is true,

ThenAlgorithmPurpose :Comparing two numbersPre: NonePost: NoneReturn: None1) Read two numbers Num1 and Num22) If Num1 > Num2a. Then Print Num1b. Else Print Num23) Stop

Series of Actions

Series of Actions

Example

Page 24: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

24Data Structures in C++ by Dr. Varsha Patil Oxford University Press © 2012

Figure 4: Repetition Construct

Page 25: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

25Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Relationship between Data, Data Structures, and Algorithms

A data structure represents a set of data items with a specific relationship between them.

The success of a software project often depends upon the choices made in the representation of data and algorithms designed to process the data

The proper choice of a data structure can be a key point in the design of many algorithms

Page 26: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

26Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Implementation of Data Structure

Specification Implementation

Page 27: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

27Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Flow Chart

A very effective tool to show the logic flow of a program

A flow chart is a pictorial representation of an algorithm.

It hides all of the details of an algorithm by giving the picture;

It shows how the algorithm flows from beginning to end

Page 28: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

28Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Structure

Figure 5: Flow chart for adding three numbers

Page 29: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

29Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Analysis of Algorithms

Complexity of Algorithms Space Complexity Time Complexity Computing Time Complexity of Algorithm Big-O Notation

Page 30: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

30Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Space Complexity

Amount of computer memory required during the program execution, as a function of the input size

Space complexity measurement which is space requirement of an algorithm can be done at two different times:

Compile time and Execution time

Page 31: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

31Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Compile Time Space Complexity

Compile Time Space Complexity is defined as the storage requirement of a program at compile time

Space Complexity = Space needed of compile time

Page 32: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

32Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Runtime space complexity

If program is recursive or uses dynamic variables or dynamic data structure then there is a need to determine space complexity at runtime

The memory requirement is summation of the Program Space Data Space And Stack Space

Page 33: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

33Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Time Complexity

Time Complexity of an algorithm is a measure of how much time is required to execute an algorithm for a given number of inputs

Time Complexity T(P) is the time taken by program P and the sum of the compile and execution time

Page 34: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

34Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Worst Case Complexity of the algorithm is the function defined by the maximum number of steps taken on any instance of size n

Best CaseComplexity of the algorithm is the function defined by the minimum number of steps taken on any instance of size n

Average CaseComplexity of the algorithm is the function defined by an average number of steps taken on any instance of size n

Best, Worst and Average Cases

Page 35: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

35Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Computing Time Complexity of

Algorithm

The total time taken by the algorithm or program is calculated using the sum of the time taken by each of executable statement in algorithm or program

Time required by each statement depends on Time required for executing it once Number of times the statement is

executed

Page 36: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

36Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Software Engineering Software Engineering is the establishment

and use of sound engineering methods and principles to obtain reliable software

that works on real machines A fundamental concept in Software

Engineering is the Software Development Life Cycle (SDLC)

Page 37: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

37Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Software Engineering

Analysis Phase Design Phase Implementation Phase Testing Phase Verification

Page 38: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

38Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Figure 6: System Development Phases

Software Engineering

Page 39: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

39Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Analysis Phase Define the User Define the Needs Define the Requirements Define the Methods

Page 40: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

40Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Design Phase Modularity The design phase uses a

very well-established principle called Modularity

The whole package is divided into small modules

Page 41: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

41Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Implementation PhaseTools Flowchart Pseudo Code Coding

Page 42: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

42Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Testing Phase

Testing Phase Once the programs have been written, they

must be tested. There are two types of testing:

Black Box White Box

Page 43: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

43Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Verification Program verification is a process to prove

that the program does what it is intended to do

It is said that 'even verification must be verified'

This means, along with system, tests made are to be verified

Also, every software quality must be verified

Page 44: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

44Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

KEY TERMS DATA DATA TYPE DATA OBJECT DATA STRUCTURE ABSTRACT DATA TYPE LINEAR DATA STRUCUTRE NON LINEAR DATA STRUCTURE ALGORITHM ASSEMBLER COMPILER PROGRAM PSEUDOCODE FLOWCHART SOFTWARE ENGINEERING

Page 45: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

45Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Summary Computer is a programmable data processing machine that accepts input;

instructions to process input (program) and generates required output. Data and program are stored in computer’s memory. A program is written in computer’s language.

The art of programming consists of designing or choosing algorithms and expressing them in a programming language. An algorithm is a stepwise description of action which leads the problem from its start state to its goal state

One of the common tools used to define algorithms is pseudo code. Pseudo code is an English-like representation of the code required for an algorithm. It is part of English, part structured code

A very effective tool to show the logic flow of a program is the flow chart. A flow chart is a pictorial representation of an algorithm. It hides all of the details of an algorithm by giving the picture; it shows how the algorithm flows from beginning to end

Program verification is a process to prove that the program does what it is intended to do

Page 46: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

46Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Summary Engineering is the establishment and use of sound

engineering methods and principles to obtain reliable software that works on real machines

A data structure represents a set of data items with a specific relationship between them. The success of a software project often depends upon the choices made in the representation of data and algorithms designed to process the data. The proper choice of a data structure can be a key point in the design of many algorithms

Page 47: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

47Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Summary The various types Software Engineering is the

establishment and use of sound engineering methodologies and the principle to writing reliable of data structures are:

Primitive and Non-primitive data structures Linear and Non-linear data structures Static and Dynamic data structures Persistent and Ephemeral data structures Sequential and Direct access data structures

Page 48: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

48Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

Summary There is an intimate relationship between the structuring of data,

and analysis of algorithms. In fact, a data structure and an algorithm should be thought of as a one single unit, neither one along making sense without the other. · Algorithms heavily depend on the organization of data

There can be several organizations of data and/or algorithms for a given problem. Difficulty lies in deciding which algorithms is the best. We can compare one algorithm with other and choose the best. For comparison we need to analyze algorithms. Analysis involves measuring the performance of an algorithm in terms of time and space complexity

Page 49: 1. Fundamental Concept - Data Structures using C++ by Varsha Patil

49Oxford University Press © 2012

Data Structures Using C++ by Dr Varsha Patil

End of Chapter 1 …!