SlideShare a Scribd company logo
Linear Data Structures Arrays Strings Structures Stacks Queues Link List (Logically Linear)‏
Representation of Single Dimensional Arrays Dimension  ? Whole array is stored in a single contiguous memory block. Address of the first element is called the  base address  and it is also the start address of array. The address of the ith element is given by the following formula: Address i  = base_address + i * size_of_element Arrays are very efficient way of organizing data since accessing array elements requires O(1). elem n-1 … elem i … elem 2 elem 1 elem 0
float sum (float *list, int n)‏ { float temp = 0; int i; for (i = 0; i < n; i++)‏ temp = temp + *(list + i); return temp; } float sum (float list[], int n)‏ { float temp = 0; int i; for (i = 0; i < n; i++)‏ temp = temp + list[i]); return temp; }
Representation of Two Dimensional Array Can be called Table Needs two dimensions   -  One for Rows - Other for columns Two representations Row Major Column Major
Representations of Table Row Major ( First subscript changes least frequently and last subscript changes most frequently)‏ (i,j)th element = Base Address + (i * N + j) * size of array  Column Major ( Last subscript changes least frequently and first subscript changes more frequently)‏ (i,j)th element = Base Address + (j * M + i) * size of array
void add (int a[][], int b[][],   int c[][],   int rows, int cols)‏ { int i, j; for (i=0; i<rows; i++)‏ for (j=0; j<cols; j++)‏ c[i][j] = a[i][j] + b[i][j]; } What’s wrong?
const int N = 100; void add (int a[][N], int b[][N],   int c[][N],   int rows, int cols)‏ { int i, j; for (i=0; i<rows; i++)‏ for (j=0; j<cols; j++)‏ c[i][j] = a[i][j] + b[i][j]; } Why?
Two Dimensional Array Offset of a[i][j]? 54 345 106 0 99 82 76 22 64 38 2 3 6 3 5 1 User’s view (abstraction)‏ 54 345 106 0 99 82 76 22 64 38 2 3 6 3 5 1 System’s view (implementation)‏
Two Dimensional Array Offset of a[i][j]? Number of elements in each row? i th  row  total elements in the previous rows? j th  element in i th  row Offset (in units)  N i * N i * N + j The addressing formula needs to know the number of columns but does not need the number of rows! 54 345 106 0 99 82 76 22 64 38 2 3 6 3 5 1 User’s view (abstraction)‏
Row major – C, Pascal, C++, etc. Column Major – FORTRAN Ada - indefinite Two Dimensional Array
Row Major  Slice along the 1 st  dimension to get an array of N-1 dimensions Continue until you are left with one dimension only. Offset of a[d 0 ] [d 1 ] …[d n-1 ] Multi-Dimensional Arrays A[D 0 ] [D 1 ]…[D n-1 ] (…((d 0 *D 1  + d 1 )*D 2  + d 2 )*D 3  + …) + d n-1
Simple View General formula in Row Major  A[s1,s2,s3,...sn] = Base Address + ((s 1  * D 2 *D 3 *..D n ) + (s 2 * D 3 *D 4 *..D n ) + (s n-1 *D n ) + S n ) * Size of array General formula in Column Major  A[s1,s2,s3,...sn] = Base Address + ((s n  * D 1 *D 2 *..D n-1 ) + (s n-1 * D 1 *D 2 *..D n-2 ) + (s 2 *D 1 ) + S 1 ) * Size of array
Symmetric  Diagonal Triangular Sparse * make programs of all these properties Special Matrices
Ordered Lists One of the most common data object is an ordered list. An ordered list has elements with definite ordering. The simplest example of an ordered list is an ordered pair which has only two elements. Examples of ordered lists: Months of the years (Jan, Feb, Mar, Apr, May,…., Dec)‏ English Alphabets (A, B, C, …, Z)‏ Words in a sentence (“This is a book on data structures.”)‏ Names of the students in a class stored in the order of their roll numbers.
Operations Defined on an Ordered List Find the length of list. Check if the list is empty. Traverse the list in some order. Get the i th  elements in the list. Change the value of the i th  element. Insert a new element at the i th  position. Delete the i th  element. *Make programs of all these properties
Representation of an Ordered List The easiest way to represent an ordered list is by an one-dimensional array where we store the i th  element of the list in the array element with index i. This is called  sequential  or  linear mapping  – mapping a one-dimensional vector onto a one-dimensional space.
class LinearList { public:  LinearList(int s); // constructor ~ LinearList () {delete [ ] ListArray; }  // destructor bool add (int value); bool remove (int index); bool change(int index, int value); bool get(int index, int & value); void printAll(); bool isFull() {return size == maxSize ;} bool isEmpty()  {return size == 0; } int  length() {return size;} private: int maxSize; // max List size int *ListArray; int size; // no. of elements in the List void readjust(int index); void moveForward(int index); void moveBackward(int index); }; Linear List Using Arrays
LinearList :: LinearList(int s)‏ { maxSize = s; ListArray = new int[maxSize]; size = 0; } void LinearList :: printALL()‏ { for (i = 0; i < size; i++)‏ cout << ListArray[i] << newline; }
bool LinearList :: get(int index, int & value) { if (index < size  && index >= 0) { value = ListArray[index]; return true; } else return false; }
bool LinearList::add(int value)‏ { if (! isFull() ) {  for (int i = size; i >= 1; i--) { if (ListArray[i-1] > value)‏ ListArray[i] = ListArray[i -1]; else break; } ListArray[i] = value; size++; return true;  } else return false; }
bool LinearList::remove(int index)‏ { if (index < size  && index >= 0)  {  for (int i = index; i < size - 1; i++)‏ ListArray[i] = ListArray[i +1]; size--; return true;  } else return false; }
bool LinearList :: change(int index, int value) { if (index < size  && index >= 0) { ListArray[index] = value; readjust(index); return true; } else return false; } void LinearList :: readjust(int index) { if ((index < (size - 1)) &&  (ListArray[index] > ListArray[index + 1]))‏ moveForward(index); else if ((index > 0)  &&  (ListArray[index] < ListArray[index - 1]))‏ moveBackward(index); }
void LinearList :: moveForward(int index) { int temp = ListArray[index]; int i = index; while ((i < (size - 1)) &&  (ListArray[i] > ListArray[i + 1])) { ListArray[i] = ListArray[i+1]; i = i + 1; } if (i != index)  ListArray[i] = temp; } void LinearList :: moveBackward(int index) { int temp = ListArray[index]; int i = index; while ((i > 0 ) &&  (ListArray[i] < ListArray[i - 1])) { ListArray[i] = ListArray[i-1]; i = i - 1; } if (i != index)  ListArray[i] = temp; }
Assignment# 1  last date of submission :  02-09-2008 (Tuesday)‏ Obtain an addressing formula for elements a[i,j] in the upper triangular matrix of order nxn. You can assume that this upper triangular is stored row by row  Arrays   - Read a matrix , find upper triangular matrix, find  diagonal matrix, find determinant of a matrix  Strings  - Read a string , find the length of string,  a particular  word, replace a particular word with new word.  - Read an array of names of students  and sort it. Structures  - Make an array of structures (Roll-No, Name,  Marks, Grade) , Display all records, find all the students with particular grade , find the record of a particular student, delete record of a  particular student
Ad

More Related Content

What's hot (20)

Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Functions in C
Functions in CFunctions in C
Functions in C
Shobhit Upadhyay
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
Self-Employed
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
Muhammad Hammad Waseem
 
Stack application
Stack applicationStack application
Stack application
Student
 
Red black tree
Red black treeRed black tree
Red black tree
Dr Sandeep Kumar Poonia
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
Madhu Bala
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
Time andspacecomplexity
Time andspacecomplexityTime andspacecomplexity
Time andspacecomplexity
LAKSHMITHARUN PONNAM
 
Data structure-questions
Data structure-questionsData structure-questions
Data structure-questions
Shekhar Chander
 
Linked list
Linked listLinked list
Linked list
Md. Afif Al Mamun
 
B tree
B treeB tree
B tree
Rajendran
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
Reggie Niccolo Santos
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
Dr. Sindhia Lingaswamy
 

Viewers also liked (13)

2D Array
2D Array2D Array
2D Array
Swarup Boro
 
Arrays
ArraysArrays
Arrays
SARITHA REDDY
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
widespreadpromotion
 
Arrays
ArraysArrays
Arrays
archikabhatia
 
Spoj Hints
Spoj HintsSpoj Hints
Spoj Hints
Akshay Dixit
 
Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithms
Aakash deep Singhal
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
Aakash deep Singhal
 
Representation of binary tree in memory
Representation of binary tree in memoryRepresentation of binary tree in memory
Representation of binary tree in memory
Rohini Shinde
 
Arrays and addressing modes
Arrays and addressing modesArrays and addressing modes
Arrays and addressing modes
Bilal Amjad
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
Nikhil Pandit
 
Array in C
Array in CArray in C
Array in C
Kamal Acharya
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
bca2010
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
widespreadpromotion
 
Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithms
Aakash deep Singhal
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
Aakash deep Singhal
 
Representation of binary tree in memory
Representation of binary tree in memoryRepresentation of binary tree in memory
Representation of binary tree in memory
Rohini Shinde
 
Arrays and addressing modes
Arrays and addressing modesArrays and addressing modes
Arrays and addressing modes
Bilal Amjad
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
bca2010
 
Ad

Similar to 02 Arrays And Memory Mapping (20)

DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
Data structure and algorithm list structures
Data structure and algorithm list structuresData structure and algorithm list structures
Data structure and algorithm list structures
gangaresearch21
 
unit-2-dsa.pptx
unit-2-dsa.pptxunit-2-dsa.pptx
unit-2-dsa.pptx
sayalishivarkar1
 
Array
ArrayArray
Array
Vivian Chia En Chiang
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
NehaJain919374
 
DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1
Malikireddy Bramhananda Reddy
 
Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...
nsitlokeshjain
 
Module_3_Arrays - Updated.pptx............
Module_3_Arrays - Updated.pptx............Module_3_Arrays - Updated.pptx............
Module_3_Arrays - Updated.pptx............
ChiragKankani
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
Arthik Daniel
 
Data Structures & Algorithms - Lecture 3
Data Structures & Algorithms - Lecture 3Data Structures & Algorithms - Lecture 3
Data Structures & Algorithms - Lecture 3
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
Data structure
Data  structureData  structure
Data structure
Arvind Kumar
 
Abstract Algebra and Category Theory
Abstract Algebra and Category Theory Abstract Algebra and Category Theory
Abstract Algebra and Category Theory
Naveenkumar Muguda
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
ToniyaP1
 
Data structure array
Data structure  arrayData structure  array
Data structure array
MajidHamidAli
 
Algorithm
AlgorithmAlgorithm
Algorithm
sultanarun
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
chin463670
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
Terry Yoast
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
Guru Nanak Technical Institutions
 
Data Structures and Agorithm: DS 02 Array List.pptx
Data Structures and Agorithm: DS 02 Array List.pptxData Structures and Agorithm: DS 02 Array List.pptx
Data Structures and Agorithm: DS 02 Array List.pptx
RashidFaridChishti
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
Data structure and algorithm list structures
Data structure and algorithm list structuresData structure and algorithm list structures
Data structure and algorithm list structures
gangaresearch21
 
Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...
nsitlokeshjain
 
Module_3_Arrays - Updated.pptx............
Module_3_Arrays - Updated.pptx............Module_3_Arrays - Updated.pptx............
Module_3_Arrays - Updated.pptx............
ChiragKankani
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
Arthik Daniel
 
Abstract Algebra and Category Theory
Abstract Algebra and Category Theory Abstract Algebra and Category Theory
Abstract Algebra and Category Theory
Naveenkumar Muguda
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
ToniyaP1
 
Data structure array
Data structure  arrayData structure  array
Data structure array
MajidHamidAli
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
chin463670
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
Terry Yoast
 
Data Structures and Agorithm: DS 02 Array List.pptx
Data Structures and Agorithm: DS 02 Array List.pptxData Structures and Agorithm: DS 02 Array List.pptx
Data Structures and Agorithm: DS 02 Array List.pptx
RashidFaridChishti
 
Ad

Recently uploaded (20)

Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
CSUC - Consorci de Serveis Universitaris de Catalunya
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 

02 Arrays And Memory Mapping

  • 1. Linear Data Structures Arrays Strings Structures Stacks Queues Link List (Logically Linear)‏
  • 2. Representation of Single Dimensional Arrays Dimension ? Whole array is stored in a single contiguous memory block. Address of the first element is called the base address and it is also the start address of array. The address of the ith element is given by the following formula: Address i = base_address + i * size_of_element Arrays are very efficient way of organizing data since accessing array elements requires O(1). elem n-1 … elem i … elem 2 elem 1 elem 0
  • 3. float sum (float *list, int n)‏ { float temp = 0; int i; for (i = 0; i < n; i++)‏ temp = temp + *(list + i); return temp; } float sum (float list[], int n)‏ { float temp = 0; int i; for (i = 0; i < n; i++)‏ temp = temp + list[i]); return temp; }
  • 4. Representation of Two Dimensional Array Can be called Table Needs two dimensions - One for Rows - Other for columns Two representations Row Major Column Major
  • 5. Representations of Table Row Major ( First subscript changes least frequently and last subscript changes most frequently)‏ (i,j)th element = Base Address + (i * N + j) * size of array Column Major ( Last subscript changes least frequently and first subscript changes more frequently)‏ (i,j)th element = Base Address + (j * M + i) * size of array
  • 6. void add (int a[][], int b[][], int c[][], int rows, int cols)‏ { int i, j; for (i=0; i<rows; i++)‏ for (j=0; j<cols; j++)‏ c[i][j] = a[i][j] + b[i][j]; } What’s wrong?
  • 7. const int N = 100; void add (int a[][N], int b[][N], int c[][N], int rows, int cols)‏ { int i, j; for (i=0; i<rows; i++)‏ for (j=0; j<cols; j++)‏ c[i][j] = a[i][j] + b[i][j]; } Why?
  • 8. Two Dimensional Array Offset of a[i][j]? 54 345 106 0 99 82 76 22 64 38 2 3 6 3 5 1 User’s view (abstraction)‏ 54 345 106 0 99 82 76 22 64 38 2 3 6 3 5 1 System’s view (implementation)‏
  • 9. Two Dimensional Array Offset of a[i][j]? Number of elements in each row? i th row total elements in the previous rows? j th element in i th row Offset (in units) N i * N i * N + j The addressing formula needs to know the number of columns but does not need the number of rows! 54 345 106 0 99 82 76 22 64 38 2 3 6 3 5 1 User’s view (abstraction)‏
  • 10. Row major – C, Pascal, C++, etc. Column Major – FORTRAN Ada - indefinite Two Dimensional Array
  • 11. Row Major Slice along the 1 st dimension to get an array of N-1 dimensions Continue until you are left with one dimension only. Offset of a[d 0 ] [d 1 ] …[d n-1 ] Multi-Dimensional Arrays A[D 0 ] [D 1 ]…[D n-1 ] (…((d 0 *D 1 + d 1 )*D 2 + d 2 )*D 3 + …) + d n-1
  • 12. Simple View General formula in Row Major A[s1,s2,s3,...sn] = Base Address + ((s 1 * D 2 *D 3 *..D n ) + (s 2 * D 3 *D 4 *..D n ) + (s n-1 *D n ) + S n ) * Size of array General formula in Column Major A[s1,s2,s3,...sn] = Base Address + ((s n * D 1 *D 2 *..D n-1 ) + (s n-1 * D 1 *D 2 *..D n-2 ) + (s 2 *D 1 ) + S 1 ) * Size of array
  • 13. Symmetric Diagonal Triangular Sparse * make programs of all these properties Special Matrices
  • 14. Ordered Lists One of the most common data object is an ordered list. An ordered list has elements with definite ordering. The simplest example of an ordered list is an ordered pair which has only two elements. Examples of ordered lists: Months of the years (Jan, Feb, Mar, Apr, May,…., Dec)‏ English Alphabets (A, B, C, …, Z)‏ Words in a sentence (“This is a book on data structures.”)‏ Names of the students in a class stored in the order of their roll numbers.
  • 15. Operations Defined on an Ordered List Find the length of list. Check if the list is empty. Traverse the list in some order. Get the i th elements in the list. Change the value of the i th element. Insert a new element at the i th position. Delete the i th element. *Make programs of all these properties
  • 16. Representation of an Ordered List The easiest way to represent an ordered list is by an one-dimensional array where we store the i th element of the list in the array element with index i. This is called sequential or linear mapping – mapping a one-dimensional vector onto a one-dimensional space.
  • 17. class LinearList { public: LinearList(int s); // constructor ~ LinearList () {delete [ ] ListArray; } // destructor bool add (int value); bool remove (int index); bool change(int index, int value); bool get(int index, int & value); void printAll(); bool isFull() {return size == maxSize ;} bool isEmpty() {return size == 0; } int length() {return size;} private: int maxSize; // max List size int *ListArray; int size; // no. of elements in the List void readjust(int index); void moveForward(int index); void moveBackward(int index); }; Linear List Using Arrays
  • 18. LinearList :: LinearList(int s)‏ { maxSize = s; ListArray = new int[maxSize]; size = 0; } void LinearList :: printALL()‏ { for (i = 0; i < size; i++)‏ cout << ListArray[i] << newline; }
  • 19. bool LinearList :: get(int index, int & value) { if (index < size && index >= 0) { value = ListArray[index]; return true; } else return false; }
  • 20. bool LinearList::add(int value)‏ { if (! isFull() ) { for (int i = size; i >= 1; i--) { if (ListArray[i-1] > value)‏ ListArray[i] = ListArray[i -1]; else break; } ListArray[i] = value; size++; return true; } else return false; }
  • 21. bool LinearList::remove(int index)‏ { if (index < size && index >= 0) { for (int i = index; i < size - 1; i++)‏ ListArray[i] = ListArray[i +1]; size--; return true; } else return false; }
  • 22. bool LinearList :: change(int index, int value) { if (index < size && index >= 0) { ListArray[index] = value; readjust(index); return true; } else return false; } void LinearList :: readjust(int index) { if ((index < (size - 1)) && (ListArray[index] > ListArray[index + 1]))‏ moveForward(index); else if ((index > 0) && (ListArray[index] < ListArray[index - 1]))‏ moveBackward(index); }
  • 23. void LinearList :: moveForward(int index) { int temp = ListArray[index]; int i = index; while ((i < (size - 1)) && (ListArray[i] > ListArray[i + 1])) { ListArray[i] = ListArray[i+1]; i = i + 1; } if (i != index) ListArray[i] = temp; } void LinearList :: moveBackward(int index) { int temp = ListArray[index]; int i = index; while ((i > 0 ) && (ListArray[i] < ListArray[i - 1])) { ListArray[i] = ListArray[i-1]; i = i - 1; } if (i != index) ListArray[i] = temp; }
  • 24. Assignment# 1 last date of submission : 02-09-2008 (Tuesday)‏ Obtain an addressing formula for elements a[i,j] in the upper triangular matrix of order nxn. You can assume that this upper triangular is stored row by row Arrays - Read a matrix , find upper triangular matrix, find diagonal matrix, find determinant of a matrix Strings - Read a string , find the length of string, a particular word, replace a particular word with new word. - Read an array of names of students and sort it. Structures - Make an array of structures (Roll-No, Name, Marks, Grade) , Display all records, find all the students with particular grade , find the record of a particular student, delete record of a particular student

Editor's Notes

  • #15: One of the most common data object is an ordered list. An ordered list has elements with definite ordering. The simplest example of an ordered list is an ordered pair which has only two elements. Following are some examples of ordered lists: Months of the years (Jan, Feb, Mar, Apr, May,…., Dec)‏ English Alphabets (A, B, C, …, Z)‏ Words in a sentence (“This is a book on data structures.”)‏ Names of the students in a class stored in the order of their roll numbers. It may be noted that the elements in an ordered-list must maintain a specified order. For example, changing the orders of words in a sentence will change the sentence. That is, it will no longer be the same sentence. As an abstract data type, an ordered-list will typically support the following operations: Create a new empty list. Delete a list. Find the number of elements in the list or length of the list. Check if the list is empty. Check if more elements can be added to the list or whether the list is full. Traverse the list in some order. Get the i th elements in the list. Change the value of the i th element. Insert a new element at the i th position. Insert a new element according to the specified order. Delete the i th element. The easiest way to represent an ordered list is by an one-dimensional array where we store the i th element of the list in the array element with index i. This is called sequential or linear mapping. That is mapping a one-dimensional vector onto a one-dimensional space.
  • #18: It is always a very good idea to explicitly keep track of the number elements in a list. This will make your life more comfortable. Your algorithms simpler and will be more independent of the data type stored in your list.
  翻译: