[go: up one dir, main page]

0% found this document useful (0 votes)
31 views17 pages

Weekly Session - Session - 3

The document discusses arrays including how to declare, initialize, and perform operations like searching, insertion, and deletion in arrays. It covers the time complexity of these operations in unsorted arrays and advantages and disadvantages of arrays. Example problems on 1D and 2D arrays are also provided.

Uploaded by

yt Hehkke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views17 pages

Weekly Session - Session - 3

The document discusses arrays including how to declare, initialize, and perform operations like searching, insertion, and deletion in arrays. It covers the time complexity of these operations in unsorted arrays and advantages and disadvantages of arrays. Example problems on 1D and 2D arrays are also provided.

Uploaded by

yt Hehkke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Weekly Session

Coding
Class - 3
10/11/21
Array

Array is a collection of items of same data type stored at


contiguous memory location.
How to declare an Array

datatype arrayName[array size];


(example) int arr[10];
int - > datatype of the array
arr -> name of the array
10 -> size of the array
How to initialise an Array

● int arr[5] = {10, 20, 30, 40, 50};

● int arr[ ] = {10, 20, 30, 40, 50};


● int arr[5];
int i = 0;
while(i <= 5){
cin>>arr[i];
i++;
}
SEARCH OPERATION IN AN
ARRAY
INSERTION IN AN ARRAY
DELETION IN AN ARRAY
Searching, Insertion and Deletion
Time Complexity in an Unsorted
Array
Search : O(n)
Insert : O(1)
Delete : O(n)
Advantages

● In an array, accessing an element is very easy by using the


index number.
● The search process can be applied to an array easily.
● 2D Array is used to represent matrices.
● For any reason a user wishes to store multiple values of
similar type, then the Array can be used and utilized
efficiently.
Disadvantages

● Array has fixed size.


● Insertion and deletion takes time.
● Array is Contiguous block of memory.
Simple problems of 1D-Array

Question 1:

Take Inputs from User and Store Them in an Array.


Display Sum and Average of Array Elements Using for
Loop.
Simple problems of 1D-Array

Question 2:

Write a C++ program to find the largest element of a


given array of integers.
Simple problems of 1D-Array

Question 3:

Write a C++ program to separate 0s and 1s from a


given array of values 0 and 1.
Simple problems of 1D-Array

Question 4:

Write a C++ program to find and print all unique


elements of a given array of integers.
Simple problems of 1D-Array

Question 5:

Write a program to print all the LEADERS in the array.


An element is leader if it is greater than all the
elements to its right side. And the rightmost element is
always a leader.
For example, in the array {16, 17, 4, 3, 5, 2}: leaders are 17, 5 and 2.

Let the input array be arr[] and size of the array be size.
Simple problems of 2D-Array

Question 1:

Write a program to perform addition and multiplication


of two matrices.
CONGRATULATIO
NS30% of the Weekly
Now you have completed
Sessions!!!

Keep Doing and Attend All the Classes.

Consistency is the key to programming.

You might also like