SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
Arrays, Records and
Pointers
Csc-391
2
Data Structures and Algorithms
Introductio
nLinear data structure. Is used to store similar types of data. An array is a
finite collection of similar elements stored in adjacent memory locations.
Decleration of the Arrays: (In C)
the array name, the element type and the array size.
Examples:
int a[20], b[3],c[7]; // one-dimensional arrays
float f[5], c[2];
char m[4], n[20];
Initialization of an array is the process of assigning initial values.
Examples:
float, b[3]={2.0, 5.5, 3.14};
char name[4]= {‘E’,’m’,’r’,’e’};
int c[10]={0};
© SMT, Faculty, CSE, IUBAT
3
Data Structures and Algorithms
Two- dimensional arrays
©SMT, Faculty, CSE, IUBAT
4
Data Structures and Algorithms
Two- dimensional arrays
©SMT, Faculty, CSE, IUBAT
5
Data Structures and Algorithms
Two- dimensional arrays
©SMT, Faculty, CSE, IUBAT
6
Data Structures and Algorithms
Remarks
Pointer arrays and pointers:
Array of pointers is called pointer array. Details on pointers and arrays is discussed
in Array, func, point
document
Jagged arrays:
Arrays whose rows or
columns begins with
different numbers
of data elements and
ends with unused space,
are called
jagged array.
Dynamic arrays:
int *my_array;
my_array = new int[10]; // array size is defined during run-time
Group
1
Group
2
Group
3
Group
4
Evans Conrad Davis Baker
Harris Felt Segal Cooper
Lewis Glass Ford
Shaw Hill Gray
King Jones
Penn Reed
Silver
Troy
Wagner
* * * * 0 0 0 0 0
* * * * * * * * *
* * 0 0 0 0 0 0 0
* * * * * * 0 0 0
©SMT, Faculty, CSE, IUBAT
7
Data Structures and Algorithms
#include<iostream.h>
int main ()
{
int i,n; int * p;
cout << "How many numbers would you like to type? ";
cin >> i;
p= new int[i]; // it takes memory at run-time from Heap
if(p == NULL)
cout << "Error: memory could not be allocated";
else
{
for(n=0; n<i; n++)
{
cout << "Enter number: ";
cin >> p[n];
}
int*k=p; // to hold the base address of dynamic array
cout << "You have entered: n";
for(n=0; n<i; n++) cout << *k<< ", "; k++;
cout<<"n";
delete[] p; // it release the memory to send it back to Heap
}
return 0;
}
Sample code for Dynamic
Array declaration
©SMT, Faculty, CSE, IUBAT
8
Data Structures and Algorithms
Records and structure (struct in C)
Records may contain different types of information. Structures are used to store
these records. A structure is a collection of logically related variables under a
single unit/name. (In c++ we can create class to store records)
Example:
struct Rectangle // this is type/name for structure
{ float Length;
float width;
float area;
};
A structure is
usually
declared before
main( )
function.
©SMT, Faculty, CSE, IUBAT
9
Data Structures and Algorithms
Travers, Insert, Delete on Arrays
a) Traversing in Linear Array
b) inserting in Linear Array
©SMT, Faculty, CSE, IUBAT
10
Data Structures and Algorithms
Travers, Insert, Delete on Arrays
c) Deleting from Linear Array
©SMT, Faculty, CSE, IUBAT
11
Data Structures and Algorithms
Searching
Linear Search
The linear search compares each element of the array with the search key
until the search key is found. To determine that a value is not in the
array, the program must compare the search key to every element in the array. It
is also called “Sequential Search” because it traverses the data sequentially
to locate the element.
©SMT, Faculty, CSE, IUBAT
12
Data Structures and Algorithms
Searching
Binary Search
It is useful for the large sorted arrays. The binary search algorithm can
only be used with sorted array and eliminates one half of the elements in
the array being searched after each comparison.
©SMT, Faculty, CSE, IUBAT
13
Data Structures and Algorithms
Searching
Binary Search
©SMT, Faculty, CSE, IUBAT
14
Data Structures and Algorithms
Sorting
Bubble Sort
The technique we use is called “Bubble Sort” because the bigger value
gradually
bubbles their way up to the top of array like air bubble rising
in water, while the small values sink to the bottom of array.
This technique is to make several passes through the array. On
each pass,
successive pairs of elements are compared. If a pair is in
increasing order (or the values are identical), we leave the values as
they are. If a pair is in decreasing order, their values are swapped in
the array.
©SMT, Faculty, CSE, IUBAT
15
Data Structures and Algorithms
Sorting
Bubble Sort
©SMT, Faculty, CSE, IUBAT
16
Data Structures and Algorithms
Sorting
Bubble Sort
©SMT, Faculty, CSE, IUBAT

Mais conteúdo relacionado

Mais procurados

Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arraysSatyam Soni
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array pptsandhya yadav
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array PointerTareq Hasan
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)Imdadul Himu
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)EngineerBabu
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programmingnmahi96
 
Data structure and algorithm All in One
Data structure and algorithm All in OneData structure and algorithm All in One
Data structure and algorithm All in Onejehan1987
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2Rajendran
 

Mais procurados (20)

Array in c++
Array in c++Array in c++
Array in c++
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arrays
 
Array in c
Array in cArray in c
Array in c
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Data structure and algorithm All in One
Data structure and algorithm All in OneData structure and algorithm All in One
Data structure and algorithm All in One
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Arrays
ArraysArrays
Arrays
 

Destaque

Destaque (20)

Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
 
Arrays
ArraysArrays
Arrays
 
Array in c language
Array in c languageArray in c language
Array in c language
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Cse lab persentation
Cse lab persentationCse lab persentation
Cse lab persentation
 
2.DS Array
2.DS Array2.DS Array
2.DS Array
 
Arrays in CPP
Arrays in CPPArrays in CPP
Arrays in CPP
 
Ch1- Introduction to dbms
Ch1- Introduction to dbmsCh1- Introduction to dbms
Ch1- Introduction to dbms
 
Computer processing
Computer processingComputer processing
Computer processing
 
Instagram
InstagramInstagram
Instagram
 
Normalization
NormalizationNormalization
Normalization
 
General instution reasearch
General instution reasearchGeneral instution reasearch
General instution reasearch
 
deque and it applications
deque and it applicationsdeque and it applications
deque and it applications
 
[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
String operation
String operationString operation
String operation
 
Applications of queues ii
Applications of queues   iiApplications of queues   ii
Applications of queues ii
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Recursion
RecursionRecursion
Recursion
 

Semelhante a Arrays, Records and Pointers: Linear Data Structures

Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#Shahzad
 
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
 
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
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureRai University
 
Arrays Fundamentals Unit II
Arrays  Fundamentals Unit IIArrays  Fundamentals Unit II
Arrays Fundamentals Unit IIArpana Awasthi
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
 
Data structures "1" (Lectures 2015-2016)
Data structures "1" (Lectures 2015-2016) Data structures "1" (Lectures 2015-2016)
Data structures "1" (Lectures 2015-2016) Ameer B. Alaasam
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structurechouguleamruta24
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptxSajalFayyaz
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arraysmaamir farooq
 
DATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxDATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxShivamKrPathak
 

Semelhante a Arrays, Records and Pointers: Linear Data Structures (20)

Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
 
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
 
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
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Data structure
Data structureData structure
Data structure
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
Arrays Fundamentals Unit II
Arrays  Fundamentals Unit IIArrays  Fundamentals Unit II
Arrays Fundamentals Unit II
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Unit 3
Unit 3 Unit 3
Unit 3
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 
Cs341
Cs341Cs341
Cs341
 
Data structures "1" (Lectures 2015-2016)
Data structures "1" (Lectures 2015-2016) Data structures "1" (Lectures 2015-2016)
Data structures "1" (Lectures 2015-2016)
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Arrays
ArraysArrays
Arrays
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
DATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxDATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptx
 

Mais de Shakila Mahjabin

Mais de Shakila Mahjabin (10)

CSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL QuestionCSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL Question
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
Solution of Erds
Solution of ErdsSolution of Erds
Solution of Erds
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Algo analysis
Algo analysisAlgo analysis
Algo analysis
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
Codes on structures
Codes on structuresCodes on structures
Codes on structures
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
 
Data Structure Basics
Data Structure BasicsData Structure Basics
Data Structure Basics
 

Último

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 

Último (20)

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 

Arrays, Records and Pointers: Linear Data Structures

  • 2. 2 Data Structures and Algorithms Introductio nLinear data structure. Is used to store similar types of data. An array is a finite collection of similar elements stored in adjacent memory locations. Decleration of the Arrays: (In C) the array name, the element type and the array size. Examples: int a[20], b[3],c[7]; // one-dimensional arrays float f[5], c[2]; char m[4], n[20]; Initialization of an array is the process of assigning initial values. Examples: float, b[3]={2.0, 5.5, 3.14}; char name[4]= {‘E’,’m’,’r’,’e’}; int c[10]={0}; © SMT, Faculty, CSE, IUBAT
  • 3. 3 Data Structures and Algorithms Two- dimensional arrays ©SMT, Faculty, CSE, IUBAT
  • 4. 4 Data Structures and Algorithms Two- dimensional arrays ©SMT, Faculty, CSE, IUBAT
  • 5. 5 Data Structures and Algorithms Two- dimensional arrays ©SMT, Faculty, CSE, IUBAT
  • 6. 6 Data Structures and Algorithms Remarks Pointer arrays and pointers: Array of pointers is called pointer array. Details on pointers and arrays is discussed in Array, func, point document Jagged arrays: Arrays whose rows or columns begins with different numbers of data elements and ends with unused space, are called jagged array. Dynamic arrays: int *my_array; my_array = new int[10]; // array size is defined during run-time Group 1 Group 2 Group 3 Group 4 Evans Conrad Davis Baker Harris Felt Segal Cooper Lewis Glass Ford Shaw Hill Gray King Jones Penn Reed Silver Troy Wagner * * * * 0 0 0 0 0 * * * * * * * * * * * 0 0 0 0 0 0 0 * * * * * * 0 0 0 ©SMT, Faculty, CSE, IUBAT
  • 7. 7 Data Structures and Algorithms #include<iostream.h> int main () { int i,n; int * p; cout << "How many numbers would you like to type? "; cin >> i; p= new int[i]; // it takes memory at run-time from Heap if(p == NULL) cout << "Error: memory could not be allocated"; else { for(n=0; n<i; n++) { cout << "Enter number: "; cin >> p[n]; } int*k=p; // to hold the base address of dynamic array cout << "You have entered: n"; for(n=0; n<i; n++) cout << *k<< ", "; k++; cout<<"n"; delete[] p; // it release the memory to send it back to Heap } return 0; } Sample code for Dynamic Array declaration ©SMT, Faculty, CSE, IUBAT
  • 8. 8 Data Structures and Algorithms Records and structure (struct in C) Records may contain different types of information. Structures are used to store these records. A structure is a collection of logically related variables under a single unit/name. (In c++ we can create class to store records) Example: struct Rectangle // this is type/name for structure { float Length; float width; float area; }; A structure is usually declared before main( ) function. ©SMT, Faculty, CSE, IUBAT
  • 9. 9 Data Structures and Algorithms Travers, Insert, Delete on Arrays a) Traversing in Linear Array b) inserting in Linear Array ©SMT, Faculty, CSE, IUBAT
  • 10. 10 Data Structures and Algorithms Travers, Insert, Delete on Arrays c) Deleting from Linear Array ©SMT, Faculty, CSE, IUBAT
  • 11. 11 Data Structures and Algorithms Searching Linear Search The linear search compares each element of the array with the search key until the search key is found. To determine that a value is not in the array, the program must compare the search key to every element in the array. It is also called “Sequential Search” because it traverses the data sequentially to locate the element. ©SMT, Faculty, CSE, IUBAT
  • 12. 12 Data Structures and Algorithms Searching Binary Search It is useful for the large sorted arrays. The binary search algorithm can only be used with sorted array and eliminates one half of the elements in the array being searched after each comparison. ©SMT, Faculty, CSE, IUBAT
  • 13. 13 Data Structures and Algorithms Searching Binary Search ©SMT, Faculty, CSE, IUBAT
  • 14. 14 Data Structures and Algorithms Sorting Bubble Sort The technique we use is called “Bubble Sort” because the bigger value gradually bubbles their way up to the top of array like air bubble rising in water, while the small values sink to the bottom of array. This technique is to make several passes through the array. On each pass, successive pairs of elements are compared. If a pair is in increasing order (or the values are identical), we leave the values as they are. If a pair is in decreasing order, their values are swapped in the array. ©SMT, Faculty, CSE, IUBAT
  • 15. 15 Data Structures and Algorithms Sorting Bubble Sort ©SMT, Faculty, CSE, IUBAT
  • 16. 16 Data Structures and Algorithms Sorting Bubble Sort ©SMT, Faculty, CSE, IUBAT