0% found this document useful (0 votes)
3 views5 pages

Basic Data Structures Overview

Uploaded by

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

Basic Data Structures Overview

Uploaded by

GOWRI KANNAN
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MODULE-I

 Review Of Basic Data Structures

1. Array

2. linked list and its variants

3. Stack

4. Queue

5. Trees

Variable

 Placeholder/Structure to store a basic unit of data.

Example

• 1 integer variable stores single integer data.

• 1 float variable stores single float data.

 Question is:

• In a computer, where is that value assigned to a


variable stored?

– In memory, possibly Random Access Memory


(RAM)

• But where exactly in memory?

– On some physical address in memory because,


» Memory is divided in physical locations
and,

» Each location has a particular address


associated with it.
EXAMPLE

• int a = 5;

• int b=10

• char c=’g’

• char n = ‘z’;

5
1000(a)

1001

g 1002(c)

1003

10 1004(b)

1005

1006

1007

z
1008(n)

1009

 Sometimes in our program there might be a need to store


multiple data of similar type.
E.g. Roll numbers of 5 students.
 2 solutions:
1. Create different variables each having a different
name.
int rollnum1, rollnum2, rollnum3, rollnum4, rollnum5
2. Create a collection of variables referred by a common
name.
int rollnum[5] This looks much better solution

Array Data Structure


 An array is a Finite, Ordered collection of Homogeneous data

elements stored at contiguous/continuous memory locations.

 The idea is to store multiple items of the same type together.

Properties:
 Finite:
 Contains only a limited (finite) number of elements.
 Ordered:
 All elements are stored one by one in continuous / contiguous
locations of computer memory.
 Homogeneous:
 All the elements of an array are of the same data type.
Example
 An array of integers to store the roll numbers of all students in a
class.
 An array of strings to store the names of all villagers in a village
 int num[5] = {11, 10, 20,30,56};

Finite same data type (Homogeneous)


int a=5 other variables
char n=’z’

5
1000(a)

1001

1002

11 1003(num
Ordered
)
10
1004

20
1005

30
1006

56
1007

z
1008(n)

1009

Common questions

Powered by AI

A linked list might be chosen over an array in scenarios where dynamic sizing is crucial, as linked lists allow for efficient insertions and deletions without the need to declare a fixed size upfront. Unlike arrays, linked lists do not require contiguous memory, making them suitable for applications where memory usage patterns fluctuate. However, accessing elements in linked lists is sequential and slower compared to the direct index-based access available in arrays, making arrays more appropriate for frequent access and manipulation of elements if the size is known in advance .

The homogeneous property of arrays ensures that all elements within the array are of the same data type. This uniformity simplifies data operations and management by ensuring consistency, which allows for generic and optimized algorithms to process the data efficiently. Homogeneity is particularly beneficial for numerical operations or array manipulations that leverage type-based optimizations, reducing type-checking overhead. However, it also limits the flexibility to store mixed data types within the same structure, potentially necessitating additional logic for more complex data scenarios .

Variables in a computer are stored in memory, specifically in Random Access Memory (RAM) at distinct physical addresses. Each address corresponds to a specific physical location in the memory device. Arrays are often preferred to store multiple items of the same type because they utilize contiguous memory locations, allowing for efficient access and manipulation of data through indexing. This ordering and homogeneity improve computational efficiency and program readability compared to handling multiple individual variables with separate addresses .

Using arrays offers the advantage of organizing data elements efficiently in contiguous memory locations, which allows for easy access and management through indexing, as well as more concise code. Arrays also enforce a single data type, promoting data consistency. However, arrays have fixed sizes, which limits their flexibility and can result in wasted memory if the array is not fully utilized. In contrast, using individual variables requires more manual management and can lead to cluttered code but offers greater flexibility in terms of varied data types and usage without predetermined size constraints .

The 'ordered' property of arrays ensures that data elements are stored sequentially in contiguous memory locations. This organization facilitates efficient data processing by enabling rapid access to elements via their index, supporting optimal traversal algorithms that leverage data locality and caching strategies. Computational complexity for accessing any element is reduced to constant time (O(1)), unlike data structures like linked lists, where access time is linear in relation to the number of elements. This sequential ordering simplifies tasks such as sorting, searching, and manipulating data, enhancing performance efficiency .

You might also like