KEMBAR78
DSA(Lec-1,2,3) For C++ Introduction for basics | PPTX
Data Structures and
Algorithm
LECTURE 01/02 (INRODUCTION)
Course objective
Introduce methods for organizing data so that the data can be accessed
and updated efficiently within a computer program.
COURSE OUTLINE
Course/ Lab Marking
 Assignments 10%
 Quizzes 05%
 Project 05%
 OHT Exam 30%
 Final Exam 50%
What is Data?
What is Data Structure?
Data Structure Anyway?
It’s an agreement about:
 how to store a collection of objects in memory,
 what operations we can perform on that data,
 the algorithms for those operations, and
 how time and space efficient those algorithms are.
Data Structure Example Applications
 How does Google quickly find web pages that contain a search term?
 How does your Operating System track which memory (disk or RAM) is
free?
 How does the processor handles multitasking
Selection of Data Structure
What is an algorithm?
 Well-defined computational procedure
 Takes set of values as input and produces set of values as output
 Tool to solve well defined computational problems
Data Structures and Algorithms
 Data structures
 Representation and organization of data
 Algorithms
 Methods for implementing operations on data structures
 Data structures and algorithms are closely related
 Data structures are often tuned for certain algorithms
What kind of problems are solved by
algorithms?
 Human Genome Project
 Internet: Routing, searches, security
 Electronic commerce
 Commercial enterprises
 Inflectional disease modeling
Properties of Algorithm
 Input :- Zero or more quantities are supplied.
 Output :- At least one quantity produce.
 Definiteness :- Each instruction is clear and unambiguous.
 Correctness :- An algorithm should produce the correct output values for
each set of input values.
 Finiteness :- Should produce the desired output after a finite number of steps
for any input in the set.
 Effectiveness :- To perform each step of an algorithm exactly and in a finite
amount of time.
 Generality :- The procedure should be applicable for all problems of the
desired form.
Analysis of Algorithm
The purpose of algorithm analysis is to determine:
Time efficiency/Running Time:-Performance in terms of running times for different input
sizes and structure. Running time is dependent on the size of input as well as structure
of input.
Example : Sequential search vs. Binary search
The number of comparisons done by sequential search and binary search of x
(value being searched).
Types of Data Structure
Primitive Data Structure
 Integer
 Float
 Character
 Boolean
Non-Primitive Data Structure
Non-Primitive Data Structure (cot.)
Non-Primitive Data Structure (cot.)
Some Frequently Used DS
Array
 Contagious memory location
 Add items
 Remove item
 Replace item
 Display item
Stack
Queue
List
Tree
Abstract Data Type and Data Structure
Abstract data type
 Abstract Data type (ADT) is a type (or class) for objects whose behavior is
defined by a set of value and a set of operations.
 The definition of ADT only mentions what operations are to be performed
but not how these operations will be implemented.
 It does not specify how data will be organized in memory and what
algorithms will be used for implementing the operations.
 ADTs support abstraction, encapsulation and data hiding.
Abstract Data Type and Data Structure
The Core Operation of ADT
Have you ever used a data structure
to store your data?
 Arrays in C/C++
 Stores objects sequentially in memory
 Can access, change, insert or delete objects
 Algorithms for insert & delete will shift items as needed
CLASS
 A class is simply a collection of data and methods which can act on that data.
 Classes describe a model/concept/type and defines the possible behavior and
possible states of that (in your example, a Person can have a name, address, etc.
 A class serves only as a plan, or a template, or sketch- of a number of similar things (i.e.
objects)
 A class is a mechanism for creating user-defined data types.
Objects
 An object is an instance of a
class.
 A class and an object of that
class has the same relationship
as a data type and a variable
 All objects with the same
characteristics constitute one
class.
Objects
Professor Smith
Professor Jones
Professor Mellon
Attributes
STRUCTURE OF A CLASS
DEFINING A CLASS IN C++
class person
{
public:
Int age ;
public:
// public class members
};
Void main(){
Person p1;
P1.age =12;
}
class circle
{
private:
float radius;
public:
circle(){radius=5.5;}
circle(float r) {set(r);}
void set(float r) //sets circle
attributes
{
If(r>0)
{radius = r;}
else
{radius=5.5;}
}
float calcArea() //calculates area
{
return 3.14*power(radius,2);
}
float getRadius()
{
Return radius;
}
};
void main()
{
circle c1; //create circles
circle c2(6);
circle c3(-3);
c1.calcArea();
cout<<c3.calcArea()<<endl;
cout<<c3.getRadius();
}
Task
Create a class “Room”. Choose appropriate data members (height, breadth
and length, your program should be able to calculate
 Area of room (length * breadth)
 Volume of room (length * breadth * height)

DSA(Lec-1,2,3) For C++ Introduction for basics

  • 1.
  • 2.
    Course objective Introduce methodsfor organizing data so that the data can be accessed and updated efficiently within a computer program.
  • 3.
  • 4.
    Course/ Lab Marking Assignments 10%  Quizzes 05%  Project 05%  OHT Exam 30%  Final Exam 50%
  • 5.
  • 6.
    What is DataStructure?
  • 7.
    Data Structure Anyway? It’san agreement about:  how to store a collection of objects in memory,  what operations we can perform on that data,  the algorithms for those operations, and  how time and space efficient those algorithms are.
  • 8.
    Data Structure ExampleApplications  How does Google quickly find web pages that contain a search term?  How does your Operating System track which memory (disk or RAM) is free?  How does the processor handles multitasking
  • 9.
  • 10.
    What is analgorithm?  Well-defined computational procedure  Takes set of values as input and produces set of values as output  Tool to solve well defined computational problems
  • 11.
    Data Structures andAlgorithms  Data structures  Representation and organization of data  Algorithms  Methods for implementing operations on data structures  Data structures and algorithms are closely related  Data structures are often tuned for certain algorithms
  • 12.
    What kind ofproblems are solved by algorithms?  Human Genome Project  Internet: Routing, searches, security  Electronic commerce  Commercial enterprises  Inflectional disease modeling
  • 13.
    Properties of Algorithm Input :- Zero or more quantities are supplied.  Output :- At least one quantity produce.  Definiteness :- Each instruction is clear and unambiguous.  Correctness :- An algorithm should produce the correct output values for each set of input values.  Finiteness :- Should produce the desired output after a finite number of steps for any input in the set.  Effectiveness :- To perform each step of an algorithm exactly and in a finite amount of time.  Generality :- The procedure should be applicable for all problems of the desired form.
  • 14.
    Analysis of Algorithm Thepurpose of algorithm analysis is to determine: Time efficiency/Running Time:-Performance in terms of running times for different input sizes and structure. Running time is dependent on the size of input as well as structure of input. Example : Sequential search vs. Binary search The number of comparisons done by sequential search and binary search of x (value being searched).
  • 15.
    Types of DataStructure
  • 16.
    Primitive Data Structure Integer  Float  Character  Boolean
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
    Array  Contagious memorylocation  Add items  Remove item  Replace item  Display item
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
    Abstract Data Typeand Data Structure Abstract data type  Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of value and a set of operations.  The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented.  It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations.  ADTs support abstraction, encapsulation and data hiding.
  • 27.
    Abstract Data Typeand Data Structure
  • 28.
  • 29.
    Have you everused a data structure to store your data?  Arrays in C/C++  Stores objects sequentially in memory  Can access, change, insert or delete objects  Algorithms for insert & delete will shift items as needed
  • 30.
    CLASS  A classis simply a collection of data and methods which can act on that data.  Classes describe a model/concept/type and defines the possible behavior and possible states of that (in your example, a Person can have a name, address, etc.  A class serves only as a plan, or a template, or sketch- of a number of similar things (i.e. objects)  A class is a mechanism for creating user-defined data types.
  • 31.
    Objects  An objectis an instance of a class.  A class and an object of that class has the same relationship as a data type and a variable  All objects with the same characteristics constitute one class. Objects Professor Smith Professor Jones Professor Mellon Attributes
  • 32.
  • 33.
    DEFINING A CLASSIN C++ class person { public: Int age ; public: // public class members }; Void main(){ Person p1; P1.age =12; }
  • 34.
    class circle { private: float radius; public: circle(){radius=5.5;} circle(floatr) {set(r);} void set(float r) //sets circle attributes { If(r>0) {radius = r;} else {radius=5.5;} } float calcArea() //calculates area { return 3.14*power(radius,2); } float getRadius() { Return radius; } }; void main() { circle c1; //create circles circle c2(6); circle c3(-3); c1.calcArea(); cout<<c3.calcArea()<<endl; cout<<c3.getRadius(); }
  • 35.
    Task Create a class“Room”. Choose appropriate data members (height, breadth and length, your program should be able to calculate  Area of room (length * breadth)  Volume of room (length * breadth * height)