100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Module 2 Datastructure

Rating
-
Sold
-
Pages
39
Grade
A+
Uploaded on
18-09-2024
Written in
2024/2025

Module 2 Datastructure

Institution
Bsc. Computer Science
Course
Bsc. Computer science











Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Bsc. Computer science
Course
Bsc. Computer science

Document information

Uploaded on
September 18, 2024
Number of pages
39
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Content preview

9/18/24, 2:25 Module 2
PM Datastructure




Linear Arrays

 An Array is a data structure used to collect multiple data elements of the
same data type into one variable.
 The elements of the array can be referenced using a subscript or index
which cocsist of consecutive numbers (0 to n-1).
 Elements of the array are stored in successive memory locations.
 UB(Upper Bound) – Largest Index
 LB(Lower Bound) – Smallest Index
 Length= UB-LB+1




Declaring Arrays
An array is declared as

datatype arrayname[size];
Eg: int a[10];



Initialization of arrays
We can initialize array elements at the time of declaration.

Syntax

datatype arrayname[size] = {list of values};




eg: int a[3]={10,4,6};

int b[5]={1,2}; means int[b]={1,2,0,0,0};
int a[]={1,2,3,4,5};
int a[3]={};----------All elements will be initialized zero.




about:blan 1/39
k

,9/18/24, 2:25 Module 2
PM Datastructure




We can assign values to individual elements of arrays using assignment operator.
Eg: a[5]=10;




Representation of array in memory
All the data elements of an array are stored at contiguous locations in the main memory. The
name of the array represents the base address or the address of the first element in the main
memory. Each element of the array is represented by proper indexing.




In the above image, we have shown the memory allocation of an array arr of size 5. The
base address of the array is 100 bytes. It is the address of arr[0]. Here, the size of the data
type used is 4 bytes; therefore, each element will take 4 bytes in the memory.



Calculating address of array element


The starting address of array is called base address.

The address of a particular array element is calculated using the formula
Address of A[I] = B + W * (I – LB)
I = Subset of element whose address to be
found, B = Base address,
W = Storage size of one element store in any array(in byte),
LB = Lower Limit/Lower Bound of subscript(If not specified assume zero).
Example: Given the base address of an array A[1300.......1900] as 1020 and the
size
of each element is 2 bytes in the memory, find the address of
A[1700]. Solution:




about:blan 2/39
k

,9/18/24, 2:25 Module 2
PM Datastructure




about:blan 3/39
k

, 9/18/24, 2:25 Module 2
PM Datastructure




Insertion at End
INSEND(INT A[10], INT N, INT ITEM)
1. Start
2. Set A[N] = ITEM
3. Set N=N+1
4. Return


Insert at a particular position
INSMID(INT A[10], INT N, INT ITEM)
1. Start
2. Set i=N-1
3. Repeat while i>=pos-1
A[i+1] = A[i]
Set i=i+1
4. End While
5. Set A[pos -1 ] = ITEM
6. Set N=N+1
7. Return




Let's take an array of 5
integers. 1, 20, 5, 78, 30.
If we need to insert an element 100 at position 2, the execution will be,




about:blan 4/39
k
$7.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
EXAMSHAVEN1

Also available in package deal

Thumbnail
Package deal
Bsc. Computer science (BCS2B02)
-
22 2024
$ 249.28 More info

Get to know the seller

Seller avatar
EXAMSHAVEN1 Stanford University
View profile
Follow You need to be logged in order to follow users or courses
Sold
2
Member since
1 year
Number of followers
0
Documents
873
Last sold
5 months ago
A+ GRADE FOR NURSING EXAMS

Success is the sum of small efforts - repeated day in and day out. I am here to help in the precise way possible. Day in day out I will be updating you \'all with the latest exams not only in nursing but also in other areas. Don\'t forget to check out my store and recommend it to a friend. I will be uploading LATEST TESTBANKS TOO.

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions