SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
Data structures


     And

  Algorithms
References :- 


-Data Structures and program design in C++
-classical data structures
-Starting out with C++ ( 5th edition)
Data and Information 


 Data is all things and facts that may be numbers ,
letters ,images or sounds or a mixed of all of them
that are processed by computer programs .
Information is the data after processing.

          Processing
Data                         Information
Processing operations
The types of processing are
1- insertion
2- deletion
3- merge
4- sorting
5- searching
6- analysis
.
Data structure is the way how you c an
Connect between data into memory to be
one item.
Physical data structure is the space to store the data in
memory.
Logical data structure is the opinion of user about how
to program and deal with the data.


Data structures types:
1- Static data structure:
Which has a fixed size like arrays , tables, records, etc.


2- Dynamic Data Structure
which has a variant size, it has two types:
** linear data structures
  The data distribute in one level
  - Lists
  - Stacks
  - Queues

** Non-linear data structures:
   The data distribute in many levels and used pointers in
each item to point to the next item into memory in order
to facilitate the insertion and deletion operations, like tree
and graph.

  To select an appropriate data structure for specific data,
there are many factors such as size of data, space
storage, the dynamic of data and the programming
techniques.
Arrays
Array is a finite ordered set of elements of
the same type, all integers, or all
characters but not may contains both. The
size of array can not change during
program’s
execution.

Concept : An array allows you to store and work with
multiple values of the same data type.
Properties of Arrays 

1- It has a limit number of elements, and in
  one type.
2- It has fixed size.
3- Easy to access any element into array
   using the address of first element.
There are many types of arrays:     

1- One dimensional array.

2- Two dimensional array.

3- Three dimensional array.

   Even though an entire array has only one name,
the elements may be accessed and used as
individual variables. This is possible because each
element is assigned a number used as index to
pinpoint a specific element within an array.
Why use an array?




  There are many reasons, one of the most important is
that once the data is in the array it can be used more
than once without having to be input again.
One dimensional array 


     Note : the subscript (index) numbering in C++
starts at zero.

Concept :- Arrays may be initialized where they are
defined.
int a[7] = {2, 5, 9, 3, 7, 8, 6};
       a(0)     a(1)   a(2) a(3)   a(4) a(5) a(6)

           2     5      9   3      7    8   6
We can compute the address of any element (I) by
using the relation:

     Location (a(i)) = Base address + (I-1) * size

Where :

    Base address: is the address of the first element

    size          : is the size of the location in
                    memory
Two dimensional array 
It is a table consists of a number of rows and columns, so it has two
indices one for row number and one for column number.
    We can compute the address of any elements in two ways:

1- Row-wise method
   In this way the elements store in memory row by row
sequentially. The equation in array a[N,M] is :

   location a[i,j]=base address+[M*(i-1)]+j-1]*size

   where:   base address: address of first location
             M : is number of columns
2- Column-wise method         
In this way the elements store in memory column by 
column sequentially

The equation to compute the location a[I,j] is :

   location a[i,j]=base address+[N*(j-1)]+i-1]*size

where:   base address: address of first location
             N : is number of rows
Stacks 


    A Stack is a data structure that holds a sequence of elements.
Unlike arrays and list new items may be inserted, or items may be
deleted at one end called the top of stack. The items is stored and
retrieved in a Last-In-First-Out manner.


Stack Operations:
   A stack has two primary operations: push and pop. The push
operation causes a value to be stored or pushed onto the stack. The
pop operation retrieves a value from the stack.
In push operation, if the stack is not full, item is added to   
the top of the stack. If the stack is full, an error of
Overflow is returned, and the stack is unchanged.

Algorithm PUSH      


        if top >= size of stack 
             error “stack overflow”   
           else increment top 
                add item. 
In pop operation, if the stack is not empty, item is deleted    
from the top of the stack. If the stack is empty, an error of
Underflow is returned, and the stack is unchanged.



Algorithm POP        


        if stack is empty 
             error “stack underflow”   
           else delete element 
                  Decrement top 
                 
The program is:- 
#include <iostream.h>
void push (int s[],int item);
bool empty();
int i,top=5,item,s[5];
void main()
{
cout<<"enter elements....."<<endl;
for(i=0;i<top;i++)
cin>>s[i];
push(s,item);
for(i=0;i<=top;i++)
cout<<s[i];
}

void push(int s[],int item)
{if(empty())
cout<<"overflow";
else
{++top;
cout<<"enter item "<<endl;
   cin>>item;
s[top]=item;
       }
}
bool empty()
{
if(top>=5)
return true;
else return false;
}
Applications of stack        

1- In Arithmetic Expressions
   To keep the number and type of parenthesis

There are three forms of Arithmetic expressions
** Infix Notation
** Postfix Notation
** prefix Notation

Evaluate a postfix Notation:
Each time an operand is read, it is pushed onto stack. When an
operator is reached, it is executed on the two top elements of the
stack(poped and performed the indicated operation on them)


The result will pushed on the stack, so that it will be available for
use as an operand of the next operator.
2- In Recursion: 
    The concept of defining a function, so that it calls itself as a 
 subroutine. The main benefit is that it allows to take advantage of
 the repeated structure present in many problems, i.e. it is useful
 way for defining objects that have a repeated similar structural
 form, such as :


Void message()
{
  cout<<“This is a recursive functionn”;
  message();
}

In this function there is no way to stop, so to be useful, it must
contains a condition to stop as follows:
void message(int times) 
 {
    if(times >0)
 { cout<<“This is a recursive functionn”;
   message(times-1);}
 }

   Another example is the factorial of non-negative integer           
 number (n):

       1              If   n=0
n!=
       n*(n-1)!       If   n>0




   The function to find the factorial of non-negative integer number is as
shown below:
The function is :   


Int fact (int n) 
{ 
If(n==0) 
Return 1; 
Else 
Return n*fact(n-1)
}



Another example is the sum of elements in array like a[i] :

                a[0]                     if n=1
  sum(a) =
                sum[a,n-1]+a[n-1]        if n>1
Queue: 
  It is an ordered collection of items, which may be deleted at on   
end called the front of the queue, or may be inserted at the other
end called the rear of the queue.
A queue provides access to it’s elements in First In First Out   
elements in queue are processed like (FIFO) order. The
customers standing in a grocery checkout line. The first customer
in the line is the first one served.

The figure below illustrate simple queue contains three elements
 A, B, C:



       front            A    B    C            rear
Operations on queue: 
--Insertion 
  to insert an element into a linear queue ,it 
must be check if it is full or not as shown below:

Void add_q(int q[],int item)
{if (r>=size-1)
    cout<<“OVERFLOW”;
      elseq[r++]=item;
  if (f==0)
     f=1;
}
--Deletion 
  to delete one element from a linear 
queue ,it must be check if it is empty or
not as shown below:

Void del_q(int q[],int item)
{if (f=-1)
    cout<<“UNDERFLOW”;
      else
        {q[f]=-1;
  if (f==r)
     f=-1;r=-1;}
  else f++;
}}
Pointers 
   A pointer is a variable contains an 
address of location in memory.
Every pointer points to one object, but not 
more, or don’t points to any object i.e.
has a value NULL.
Two pointers may point to one object. 
When one object in memory lost i.e. no
pointer points to it it’s called Garbage.
In C++ to create a pointer points to object:
     int *p=new int
Linked Linear List 
A linked list is a series of connected nodes, 
where each node is a data structure consists
of two parts, Data and a pointer to the next
node. The nodes of linked list are usually
dynamically allocated, used and then deleted,
allowing the linked list to grow or shrink in
size as the program runs. If new information
needs to be added to linked list, the program
simply allocates another node and insert it
into the series. If a particular piece of
information needs to be removed from L.L.L,
the program deletes the node containing that
information.
Advanta 

Más contenido relacionado

La actualidad más candente

Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queueRajkiran Nadar
 
Data structures using C
Data structures using CData structures using C
Data structures using CPdr Patnaik
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure Prof Ansari
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureRai University
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structuresKuber Chandra
 
Data structure using c bcse 3102 pcs 1002
Data structure using c bcse 3102 pcs 1002Data structure using c bcse 3102 pcs 1002
Data structure using c bcse 3102 pcs 1002SANTOSH RATH
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)swajahatr
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#Shahzad
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structurekalyanineve
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureRai University
 

La actualidad más candente (20)

Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Data Structures (BE)
Data Structures (BE)Data Structures (BE)
Data Structures (BE)
 
Datastructure
DatastructureDatastructure
Datastructure
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
 
Lesson 1 overview
Lesson 1   overviewLesson 1   overview
Lesson 1 overview
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Linked list
Linked listLinked list
Linked list
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
Data structure using c bcse 3102 pcs 1002
Data structure using c bcse 3102 pcs 1002Data structure using c bcse 3102 pcs 1002
Data structure using c bcse 3102 pcs 1002
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
Data Structure
Data StructureData Structure
Data Structure
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structure
 
Chapter 4 ds
Chapter 4 dsChapter 4 ds
Chapter 4 ds
 

Destacado

Getting started with Social Media Strategy
Getting started with Social Media StrategyGetting started with Social Media Strategy
Getting started with Social Media StrategySorel Denholtz
 
מרכזיה לשירותך
מרכזיה לשירותךמרכזיה לשירותך
מרכזיה לשירותךtuviaf
 
How will you leverage Zapier and 400+ Apps to Integrate Social Content on Lis...
How will you leverage Zapier and 400+ Apps to Integrate Social Content on Lis...How will you leverage Zapier and 400+ Apps to Integrate Social Content on Lis...
How will you leverage Zapier and 400+ Apps to Integrate Social Content on Lis...Nick Kellet
 
Web 2 0 2014 social media voter conversion strategy
Web 2 0 2014 social media voter conversion strategyWeb 2 0 2014 social media voter conversion strategy
Web 2 0 2014 social media voter conversion strategyBruce Curley
 
Job description - modals
Job description -  modalsJob description -  modals
Job description - modalsErick Vega
 
Using Social Media for Recruiting
Using Social Media for RecruitingUsing Social Media for Recruiting
Using Social Media for Recruitingguest4d476c
 
Transforming your Community into Content Creators and Fundraisers
Transforming your Community into Content Creators and FundraisersTransforming your Community into Content Creators and Fundraisers
Transforming your Community into Content Creators and FundraisersJohn Haydon
 
Stemtasticreport
StemtasticreportStemtasticreport
StemtasticreportKGMK
 
How to Scale Your Admin Team as Your Company Grows by Ted Hazard
How to Scale Your Admin Team as Your Company Grows by Ted HazardHow to Scale Your Admin Team as Your Company Grows by Ted Hazard
How to Scale Your Admin Team as Your Company Grows by Ted HazardSalesforce Admins
 
3 Barriers to Achieving Internet of Things Nirvana
3 Barriers to Achieving Internet of Things Nirvana 3 Barriers to Achieving Internet of Things Nirvana
3 Barriers to Achieving Internet of Things Nirvana Ogilvy
 
Human resources planning
Human resources planningHuman resources planning
Human resources planningLufthansa
 
A new approach to sight singing
A new approach to sight singingA new approach to sight singing
A new approach to sight singingDiegoMDCristo
 
IDENTIFICAZIONE PRECOCE DEI DSA: lo screening nella scuola primaria
IDENTIFICAZIONE PRECOCE DEI DSA: lo screening nella scuola primariaIDENTIFICAZIONE PRECOCE DEI DSA: lo screening nella scuola primaria
IDENTIFICAZIONE PRECOCE DEI DSA: lo screening nella scuola primariaAda Moscarella
 
Configuracion proxy Windows server 2008
Configuracion proxy Windows server 2008Configuracion proxy Windows server 2008
Configuracion proxy Windows server 2008teresi0101
 
Land a job with the help of Seinfeld.
Land a job with the help of Seinfeld.Land a job with the help of Seinfeld.
Land a job with the help of Seinfeld.Karl Filtness
 
Quyết định số 36/2016/QĐ-TTg ngày 1/9/2016 quy định việc áp dụng thuế suất th...
Quyết định số 36/2016/QĐ-TTg ngày 1/9/2016 quy định việc áp dụng thuế suất th...Quyết định số 36/2016/QĐ-TTg ngày 1/9/2016 quy định việc áp dụng thuế suất th...
Quyết định số 36/2016/QĐ-TTg ngày 1/9/2016 quy định việc áp dụng thuế suất th...CÔNG TY TNHH MTV XUẤT NHẬP KHẨU ĐÀM VIỆT
 

Destacado (20)

Getting started with Social Media Strategy
Getting started with Social Media StrategyGetting started with Social Media Strategy
Getting started with Social Media Strategy
 
מרכזיה לשירותך
מרכזיה לשירותךמרכזיה לשירותך
מרכזיה לשירותך
 
How will you leverage Zapier and 400+ Apps to Integrate Social Content on Lis...
How will you leverage Zapier and 400+ Apps to Integrate Social Content on Lis...How will you leverage Zapier and 400+ Apps to Integrate Social Content on Lis...
How will you leverage Zapier and 400+ Apps to Integrate Social Content on Lis...
 
Web 2 0 2014 social media voter conversion strategy
Web 2 0 2014 social media voter conversion strategyWeb 2 0 2014 social media voter conversion strategy
Web 2 0 2014 social media voter conversion strategy
 
Job description - modals
Job description -  modalsJob description -  modals
Job description - modals
 
Using Social Media for Recruiting
Using Social Media for RecruitingUsing Social Media for Recruiting
Using Social Media for Recruiting
 
Transforming your Community into Content Creators and Fundraisers
Transforming your Community into Content Creators and FundraisersTransforming your Community into Content Creators and Fundraisers
Transforming your Community into Content Creators and Fundraisers
 
Stemtasticreport
StemtasticreportStemtasticreport
Stemtasticreport
 
13 reason why
13 reason why13 reason why
13 reason why
 
How to Scale Your Admin Team as Your Company Grows by Ted Hazard
How to Scale Your Admin Team as Your Company Grows by Ted HazardHow to Scale Your Admin Team as Your Company Grows by Ted Hazard
How to Scale Your Admin Team as Your Company Grows by Ted Hazard
 
3 Barriers to Achieving Internet of Things Nirvana
3 Barriers to Achieving Internet of Things Nirvana 3 Barriers to Achieving Internet of Things Nirvana
3 Barriers to Achieving Internet of Things Nirvana
 
Human resources planning
Human resources planningHuman resources planning
Human resources planning
 
Bubbling ideas
Bubbling ideasBubbling ideas
Bubbling ideas
 
81 pancreatic masses on the ultrasound
81 pancreatic masses on the ultrasound81 pancreatic masses on the ultrasound
81 pancreatic masses on the ultrasound
 
A new approach to sight singing
A new approach to sight singingA new approach to sight singing
A new approach to sight singing
 
IDENTIFICAZIONE PRECOCE DEI DSA: lo screening nella scuola primaria
IDENTIFICAZIONE PRECOCE DEI DSA: lo screening nella scuola primariaIDENTIFICAZIONE PRECOCE DEI DSA: lo screening nella scuola primaria
IDENTIFICAZIONE PRECOCE DEI DSA: lo screening nella scuola primaria
 
Configuracion proxy Windows server 2008
Configuracion proxy Windows server 2008Configuracion proxy Windows server 2008
Configuracion proxy Windows server 2008
 
CSS Grid Layout
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
 
Land a job with the help of Seinfeld.
Land a job with the help of Seinfeld.Land a job with the help of Seinfeld.
Land a job with the help of Seinfeld.
 
Quyết định số 36/2016/QĐ-TTg ngày 1/9/2016 quy định việc áp dụng thuế suất th...
Quyết định số 36/2016/QĐ-TTg ngày 1/9/2016 quy định việc áp dụng thuế suất th...Quyết định số 36/2016/QĐ-TTg ngày 1/9/2016 quy định việc áp dụng thuế suất th...
Quyết định số 36/2016/QĐ-TTg ngày 1/9/2016 quy định việc áp dụng thuế suất th...
 

Similar a هياكلبيانات

Ds
DsDs
DsAcad
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptxDwijBaxi
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDev Chauhan
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringRAJASEKHARV8
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.pptSeethaDinesh
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3infanciaj
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queuessuser7319f8
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptxskilljiolms
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1blessyboban92
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductionsirshad17
 

Similar a هياكلبيانات (20)

DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
Data structures
Data structuresData structures
Data structures
 
Ds
DsDs
Ds
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
 
Data structure
Data  structureData  structure
Data structure
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
Unit i(dsc++)
Unit i(dsc++)Unit i(dsc++)
Unit i(dsc++)
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Data Structure
Data StructureData Structure
Data Structure
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductions
 

هياكلبيانات

  • 1. Data structures And Algorithms
  • 2. References :-  -Data Structures and program design in C++ -classical data structures -Starting out with C++ ( 5th edition)
  • 3. Data and Information  Data is all things and facts that may be numbers , letters ,images or sounds or a mixed of all of them that are processed by computer programs . Information is the data after processing. Processing Data Information
  • 4. Processing operations The types of processing are 1- insertion 2- deletion 3- merge 4- sorting 5- searching 6- analysis . Data structure is the way how you c an Connect between data into memory to be one item.
  • 5. Physical data structure is the space to store the data in memory. Logical data structure is the opinion of user about how to program and deal with the data. Data structures types: 1- Static data structure: Which has a fixed size like arrays , tables, records, etc. 2- Dynamic Data Structure which has a variant size, it has two types:
  • 6. ** linear data structures The data distribute in one level - Lists - Stacks - Queues ** Non-linear data structures: The data distribute in many levels and used pointers in each item to point to the next item into memory in order to facilitate the insertion and deletion operations, like tree and graph. To select an appropriate data structure for specific data, there are many factors such as size of data, space storage, the dynamic of data and the programming techniques.
  • 7. Arrays Array is a finite ordered set of elements of the same type, all integers, or all characters but not may contains both. The size of array can not change during program’s execution. Concept : An array allows you to store and work with multiple values of the same data type.
  • 8. Properties of Arrays  1- It has a limit number of elements, and in one type. 2- It has fixed size. 3- Easy to access any element into array using the address of first element.
  • 9. There are many types of arrays:  1- One dimensional array. 2- Two dimensional array. 3- Three dimensional array. Even though an entire array has only one name, the elements may be accessed and used as individual variables. This is possible because each element is assigned a number used as index to pinpoint a specific element within an array.
  • 10. Why use an array? There are many reasons, one of the most important is that once the data is in the array it can be used more than once without having to be input again.
  • 11. One dimensional array  Note : the subscript (index) numbering in C++ starts at zero. Concept :- Arrays may be initialized where they are defined. int a[7] = {2, 5, 9, 3, 7, 8, 6}; a(0) a(1) a(2) a(3) a(4) a(5) a(6) 2 5 9 3 7 8 6
  • 12. We can compute the address of any element (I) by using the relation: Location (a(i)) = Base address + (I-1) * size Where : Base address: is the address of the first element size : is the size of the location in memory
  • 13. Two dimensional array  It is a table consists of a number of rows and columns, so it has two indices one for row number and one for column number. We can compute the address of any elements in two ways: 1- Row-wise method In this way the elements store in memory row by row sequentially. The equation in array a[N,M] is : location a[i,j]=base address+[M*(i-1)]+j-1]*size where: base address: address of first location M : is number of columns
  • 14. 2- Column-wise method  In this way the elements store in memory column by  column sequentially The equation to compute the location a[I,j] is : location a[i,j]=base address+[N*(j-1)]+i-1]*size where: base address: address of first location N : is number of rows
  • 15. Stacks  A Stack is a data structure that holds a sequence of elements. Unlike arrays and list new items may be inserted, or items may be deleted at one end called the top of stack. The items is stored and retrieved in a Last-In-First-Out manner. Stack Operations: A stack has two primary operations: push and pop. The push operation causes a value to be stored or pushed onto the stack. The pop operation retrieves a value from the stack.
  • 16. In push operation, if the stack is not full, item is added to  the top of the stack. If the stack is full, an error of Overflow is returned, and the stack is unchanged. Algorithm PUSH  if top >= size of stack  error “stack overflow”  else increment top  add item. 
  • 17. In pop operation, if the stack is not empty, item is deleted  from the top of the stack. If the stack is empty, an error of Underflow is returned, and the stack is unchanged. Algorithm POP  if stack is empty  error “stack underflow”  else delete element  Decrement top  
  • 18. The program is:-  #include <iostream.h> void push (int s[],int item); bool empty(); int i,top=5,item,s[5]; void main() { cout<<"enter elements....."<<endl; for(i=0;i<top;i++) cin>>s[i]; push(s,item); for(i=0;i<=top;i++) cout<<s[i]; }
  • 19.  void push(int s[],int item) {if(empty()) cout<<"overflow"; else {++top; cout<<"enter item "<<endl; cin>>item; s[top]=item; } } bool empty() { if(top>=5) return true; else return false; }
  • 20. Applications of stack  1- In Arithmetic Expressions To keep the number and type of parenthesis There are three forms of Arithmetic expressions ** Infix Notation ** Postfix Notation ** prefix Notation Evaluate a postfix Notation: Each time an operand is read, it is pushed onto stack. When an operator is reached, it is executed on the two top elements of the stack(poped and performed the indicated operation on them) The result will pushed on the stack, so that it will be available for use as an operand of the next operator.
  • 21. 2- In Recursion:  The concept of defining a function, so that it calls itself as a  subroutine. The main benefit is that it allows to take advantage of the repeated structure present in many problems, i.e. it is useful way for defining objects that have a repeated similar structural form, such as : Void message() { cout<<“This is a recursive functionn”; message(); } In this function there is no way to stop, so to be useful, it must contains a condition to stop as follows:
  • 22. void message(int times)  { if(times >0) { cout<<“This is a recursive functionn”; message(times-1);} } Another example is the factorial of non-negative integer  number (n): 1 If n=0 n!= n*(n-1)! If n>0 The function to find the factorial of non-negative integer number is as shown below:
  • 23. The function is :  Int fact (int n)  {  If(n==0)  Return 1;  Else  Return n*fact(n-1) } Another example is the sum of elements in array like a[i] : a[0] if n=1 sum(a) = sum[a,n-1]+a[n-1] if n>1
  • 24. Queue:  It is an ordered collection of items, which may be deleted at on  end called the front of the queue, or may be inserted at the other end called the rear of the queue. A queue provides access to it’s elements in First In First Out  elements in queue are processed like (FIFO) order. The customers standing in a grocery checkout line. The first customer in the line is the first one served. The figure below illustrate simple queue contains three elements A, B, C: front A B C rear
  • 25. Operations on queue:  --Insertion  to insert an element into a linear queue ,it  must be check if it is full or not as shown below: Void add_q(int q[],int item) {if (r>=size-1) cout<<“OVERFLOW”; elseq[r++]=item; if (f==0) f=1; }
  • 26. --Deletion  to delete one element from a linear  queue ,it must be check if it is empty or not as shown below: Void del_q(int q[],int item) {if (f=-1) cout<<“UNDERFLOW”; else {q[f]=-1; if (f==r) f=-1;r=-1;} else f++; }}
  • 27. Pointers  A pointer is a variable contains an  address of location in memory. Every pointer points to one object, but not  more, or don’t points to any object i.e. has a value NULL. Two pointers may point to one object.  When one object in memory lost i.e. no pointer points to it it’s called Garbage. In C++ to create a pointer points to object: int *p=new int
  • 28. Linked Linear List  A linked list is a series of connected nodes,  where each node is a data structure consists of two parts, Data and a pointer to the next node. The nodes of linked list are usually dynamically allocated, used and then deleted, allowing the linked list to grow or shrink in size as the program runs. If new information needs to be added to linked list, the program simply allocates another node and insert it into the series. If a particular piece of information needs to be removed from L.L.L, the program deletes the node containing that information.