Basic Concepts of Data Structures
Basic Concepts of Data Structures
Structures
Data Structure
Data
Record
File
Database
Other Terminology
➢Group Items - Data items which have
subordinate data items are called Group
item
➢Attribute and Entity - An entity represents
the class of certain objects. it contains
➢various attributes. Each attribute
represents the particular property of that
entity
Why do we need Data
Structure?
• It gives different level of organizing data
• It explains how data can be stored and
accessed
• It provides operation on group of data,
such as adding an item, inserting an item,
sorting items, deleting an item, and
updating items
Why do we need Data
Structure?
• It provides a mean to manage huge
amount of data efficiently
• It provides fast searching and sorting
a data
Goals of Data Structure
0 1 2 3 4
Num 26 7 67 50 66
Advantages Disadvantages
Linear: Linked-list
• A linked list is a data structure in which
each data element contains a pointer or
link to the next element in the list. Through
linked list, insertion and deletion of the data
element is possible at all places of a linear
list. Also in linked list, it is not necessary to
have the data elements stored in
consecutive locations. It allocates space for
each data item in its own block of memory.
Linear: Linked-list
• Thus, a linked list is considered as a chain
of data elements or records called nodes.
Each node in the list contains information
field and a pointer field. The information
field contains the actual data and the
pointer field contains address of the
subsequent nodes in the list
Linear: Linked-list
Advantages Disadvantages
Linear: Stacks
• A stack is a linear data structure in which
insertion and deletion of elements are
done at only one end, which is known as
the top of the stack. Stack is called a last-
in, first-out (LIFO) structure because the
last element which is added to the stack is
the first element which is deleted from the
stack.
Linear: Stacks
Figure 5. Stacks
Stacks
Advantages Disadvantages
Linear: Queues
• A queue is a first-in, first-out (FIFO) data
structure in which the element that is
• inserted first is the first one to be taken
out. The elements in a queue are added at
one end called the rear and removed from
the other end called the front. Like stacks,
queues can be implemented by using
either arrays or linked lists
Linear: Queues
Figure 6. A Queue
Non-linear: Graphs
• A graph is also a non-linear data structure.
In a tree data structure, all data elements
are stored in definite hierarchical structure.
In other words, each node has only one
parent node. While in graphs, each data
element is called a vertex and is
connected to many other vertexes through
connections called edges
Non-linear: Graphs
Figure 7. A Graph
Non-linear: Trees
• A tree is a non-linear
data structure in which
data is organized in
branches. The data
elements in tree are
arranged in a sorted
order. It imposes a
Figure 8. A Tree
hierarchical structure on
the data elements.
Static or Dynamic Data Structure
Static Dynamic
• Fixed • Size of
• No changes in structure is not
memory space fixed
• Change of
data structures
in runtime
Operations in Data Structures
• Top-down
• Bottom-up
Algorithm Complexity
Space Time
Complexity Complexity
Example Algorithm
Step 1 − START
Step 2 − Declare three integers a, b and c
Step 3 − Define values of a and b
Step 4 − Add values of a and b
Step 5 − Store output of step 4 to c
Step 6 − Print c
Step 7 − STOP
Algorithm that computes two
integer values a and b
Step 1 − START Step 1 – START
Step 2 − Declare three Step 2 - Declare three
integers a, b and c
integers a, b and c
Step 3 − Define values of
a and b Step 3 - Define values
Step 4 − Add values of a
of a and b
and b Step 4 – c a+b
Step 5 − Store output of Step 5 –Print c
step 4 to c
Step 6 - STOP
Step 6 − Print c
Step 7 − STOP
Why to design an algorithm?
Solution1
Solution 4
Example 1
• Solve for the area of a rectangle?
What to
choose?
ALGORITHM ALGORITHM
1 2
Try this!
• Create a Python program that
computes the area of a circle
Practice Problem
• Design an algorithm and the
corresponding flowchart for adding the test
scores as given below if the number is
even:
26,49,98,87,62,75
• Translate the algorithm to a Python
program (using Google Colab)
• Save your source codes to GitHub
REFERENCE
• S, Gowrishankar; A, Veena (2019)
Introduction to Python Programming
• Soltys, Michael (2018) An introduction to
the analysis of algorithms