Data, Information and Data Structure
Data, Information and Data Structure
• Data is one of the most powerful tools available to any business or organisation
that wants not only to survive but rise to the top in today’s competitive and
challenging world. The more information available, the more options and better
solutions to problems and obstacles open up.
• Data is information optimized for processing and movement, facts and figures stored on computers.
• Data structures are a specific way of organizing data in a specialized format on a computer so that the information can
be organized, processed, stored, and retrieved quickly and effectively. They are a means of handling information,
rendering the data for easy use.
• Data Structure is the systematic way used to organise the data. It helps efficiently organize, manage, and store data.
Data structures
classification Data & Information
• Data structures are broadly classified • Data refers to raw facts or figures. These facts could be
about people, locations, among other things. Data can
into two types: occur in various forms such as numbers, texts, and many
other forms.
• Linear Data Structures: Arrays,
stacks, queues, and linked lists to
organize data sequentially. A • Information can simply be said to be processed data that
has been given meaning. The data has been assigned
linear data structure is a structure in with a context to make it meaningful.
which the elements are stored
sequentially, and the elements are
connected to the previous and the
next element. As the elements are
stored sequentially, so they can be
traversed or accessed in a single run.
• Non-linear Data Structures: Trees
and graphs organize data
hierarchically or interconnectedly,
allowing for complex relationships
between data elements. In which the
data elements are not arranged in a
contiguous manner. As the
arrangement is nonsequential, so the
data elements cannot be traversed or
accessed in a single run.
Linear Data Structures Non-Linear Data Structures
• Array:- In an array, elements in • Graph:-In graph data structure,
memory are arranged in each node is called vertex and
continuous memory. All the each vertex is connected to other
elements of an array are of the vertices through edges.
same type. • Trees :- Similar to a graph, a tree
• Stack:-In stack data structure, is also a collection of vertices and
elements are stored in the LIFO edges. However, in tree data
principle. That is, the last element structure, there can only be one
stored in a stack will be removed edge between two vertices.
first.
• Queue:-Unlike stack, the queue
data structure works in the FIFO
principle where first element stored
in the queue will be removed first.
• Linked List:- In linked list data
structure, data elements are
connected through a series of • https://www.programiz.com/dsa/dat
nodes. And, each node contains a-structure-types
the data items and address to the
Linear Data Structures Non Linear Data Structures
The data items are arranged in sequential order, one after the The data items are arranged in non-sequential order
other. (hierarchical manner).
All the items are present on the single layer. The data items are present at different layers.
It can be traversed on a single run. That is, if we start from the It requires multiple runs. That is, if we start from the first
first element, we can traverse all the elements sequentially in a element it might not be possible to traverse all the elements in
single pass. a single pass.
The time complexity increase with the data size. Time complexity remains the same.
• Linear Search ( Array A, searching element e, I index of array, n is number of elements in array ).
• Step 1: Set i to 0
• Step 2: if i > n then go till last step
• Step 3: if A[i] = e
• step 4: break;
• Step 5: Set i to i + 1
• Step 6: Print element a found at index i and go to next step
• Step 7: Print element not found
• Step 8: Exit
• i←i+1
• end while
end
• #include <iostream> • while(j>=0&&a[j]>s)
• using namespace std; • {
• int main() • a[j+1]=a[j];
• { • j--;
• int i,j,s,a[10]; • }
• • a[j+1]=s;
• for(i=0;i<4;i++) • }
• { • cout<<"the sorted array
• cin>>a[i]; is"<<endl;
• } • for(i=0;i<4;i++)
• for(i=1;i<4;i++) • {
• { • cout<<a[i]<<endl;
• s=a[i]; • }
• j=i-1; •
• return 0;
•}
Two dimensional Arrays
• It is also known as multidimensional array. It contains
a row index and a column index. Both the row's and
column's index begins with 0.
• Just like a one-dimensional array, Compile time and
runtime initialization of two dimensional array is
possible.
Declaration:-
data-type array-name[row-size][column-size]
Example:-
int a[3][4];
Compile-time initialization
Examples:-
int a[2][2] = {1, 2, 3, 4}; // {{1, 2},{3, 4}}
Int a[2][3] = {1, 2, 3, 4}; // {{1, 2, 3},{4}}
int a[2][4] = {1, 2, 3, 4}; // {{1,2,3,4}}
First of all the values are stored in first row, and then if
there is any extra value, it goes to next row.
Example:-
int a[][3] = {
{0,0,0},
{1,1,1}
}; // no any values is assigned to row in array. It means
that initialization of any number of rows. But must
specify number of columns, else it will give a compile
time error.
We can also initialize 2D arrays like this
int a[2][4] = { {0, 1, 2, 3} , {4, 5, 6, 7} };
or
int a[2][4] = {0,1,2,3,4,5,6,7};
Both are equivalent
Int [2][4] ={0} ;// all initialized with zero
int [3][4]= {1,1,1,1,2,2,2,2}
firstly
1 1 1 1
2 2 2 2
• { • {
• int arr[3][3];
• int arr[2][2];
• int i, j;
• int i, j;
• cout<<"Enter array elements:";
• cout<<"Enter array elements:";
• for(i = 0; i < 3;i++)
• for(i = 0; i < 2;i++)
• {
• { • for(j = 0; j < 3; j++)
• for(j = 0; j < 2; j++) • {
• { • cin>>arr[i][j];
• cin>>arr[i][j]; • }
• } • }
• } • for(i = 0; i < 3; i++)
• for(i = 0; i < 2; i++) • {
• { • for(j = 0; j < 3; j++)
• return 0;
• }
• Pointer to Array int a[5]={1,2,3,4,5};
int *p[5]=&a[0]; //array of pointer
#include<iostream>
using namespace std;
int main()
{
int a[5]={1,2,3,4,5};
int *p=&a[0];
cout<<*p;
return 0;
}
• #include<iostream> • #include<iostream>
• using namespace std; • using namespace std;
• int main() • int main()
• { • {
• int a[5]={1,2,3,4,5}; • int a[5]={1,2,3,4,5};
• for (int i=0;i<5;i++) • for (int i=0;i<5;i++)
• { • {
• int *p=&i[a]; • int *p=&a[i];
• //cout<<*p; • Cout<<*p
• //cout<<*(a+i); • }
• cout<<*(i+a); • return 0;
• } • }
• return 0;
• }
Types of pointers
Void pointer • Deference is not allowed in
This pointer is not associated with void pointer
any datatype, so it can be int a= 10;
converted into any other type of void *vp;
pointer.
Vp= &a;
Syntax :- void *vp; //declaration
Cout<<*vp);
int a= 10;
this is not allowed.
Int *p=&a // p pointer can store
To use this “typecasting” is required.
only integer type of variable. But
Why:- because in case of int , char
in case of void it can point to any float(pointers) compiler knows how many bytes
type of variable. It is also know are required , but in case of void compiler don’t
as generic pointer. know about it , then there comes the need of
typecasting.
• by using void pointer, there is no so this is also the reason why Deference is not
need to use of different datatypes allowed in void pointer.
.
• #include <iostream> • #include <iostream>
• using namespace std; • using namespace std;
• int main() • int main()
• { • {
• int a=10; • char c='N';
• void *vp; • void *vp;
• vp=&a; • vp=&c;
• cout<<"void pointer"<<'\n'<<*(int*)vp; • cout<<void pointer<<'\n'<<*(char*)vp;
• return 0; • return 0;
• } • }