Professional Documents
Culture Documents
Analysis
Lecture 4
Data
Data and information are an essential part in computer science, and various
implementations are being made to store in different ways.
Data are just a collection of facts and figures, or you can say data are values or a
set of values that are in a particular format.
Our data must be organized in a particular way, so that we can access and
manipulate it.
WHAT ARE DATA STRUCTURES?
In computer science, a data structure is a particular way of storing
and organizing data in a computer so that it can be used efficiently.
When we deal with data, How we store, organize and group our data
together matters for example: when trying to find a word in a
dictionary its quick and efficient because its sorted
Categories of Data Structures
The data structure can be subdivided into major types:
Graphs
Trees
Arrays
Array is a container which can hold a fixed number of items and these items should be of
the same type.
When compared to a List(dynamic Arrays), Python Arrays stores the similar type of
elements in it. While a Python List can store elements belonging to different data types in
it.
The following are important terms to understand the concept of Array:
Element − Each item stored in an array is called an element.
Index − Each location of an element in an array has a numerical index, which is used to
identify the element.
Example: [7,5,6,-5,50,800] array of integers
[“cat”, ‘’dog”, “sheep”] array of strings
To initialize a Python Array
1. Using for loop and Python range() function to initialize an array with a default
value.
Python for loop would place 0(default-value) for every element in the array
between the range specified in the range() function.
To initialize a Python Array
myarray=[]
print(myarray)
Output:
[0, 0, 0]
To initialize a Python Array
2. Direct method to initialize a Python array
While declaring the array, we can initialize the data values using the following command:
array-name = [default-value]*size
myarray = [0] * 3
print(myarray)
Output : [0, 0, 0]
myarray = ['P'] * 5
print(myarray)
Output : ['P', 'P', 'P', 'P', 'P']
Stack
A stack is a linear data structure that stores items in a LAST IN FIRST OUT = LIFO
Step 4: add data elements to the stack, where the top is pointing
Step 5: success
Pop Operation on Stack
Step 1: check if the stack is either empty or not
Step 3: if the stack is not empty, approach the data element at which the top is
pointing
Step 5: success
Peek Operation on Stack
Step 1: check if the stack is either empty or not
Step 3: if the stack is not empty, approach the data element at which the top is
pointing
Step 5: success
Applications of Stack
Queue
Linked List