Data Structures (ALL)
Data Structures (ALL)
Data Structures (ALL)
Contents:
General aspects regarding data structure {part done by Sora David &
Potîrniche Andreea}
Data structures classification {part done by Goian Andrei & Andrei Igor}
Structure
Example of the
array:
The numbers below the Hello is known
as an index. Think of an index of an
array as an address of a home. In that
Hello array, H lives in address 0, e
lives in address 1. The reason we start
the index at 0 is due to most
programming languages start an index
at 0 — like Python. To learn how data
structures like an array affect your
code, we have to look at operations.
The majority of data structures are applied
to these four operations:
Read: Checking out a data in a specific spot. For example, reading for “o” in the array above, the computer
knows to look in index 4.
Search: Finds a type of value within the data structure. For example, looking for numbers in the Hello array
would turn up with no findings.
Insert: Places another value in the data. For example, placing Hellow in the array above would add “w” in
index 5.
Delete: Removes a value in our data structure. For example, removing “H” from hello would be ello (side
note: deletion of a value h would actually involve another step of moving all the characters to left).
Reading is checking what value is in a particular index
Reading inside an array. The speed of reading is really fast, just one
step fast. The reason is to the computer knows index in the
array and takes a peek inside. When a computer does reading
on an array, it goes to the correct index due to:
The computer knows the index of each value.
An array stored in memory is read in a “block.” Think of it
like houses in a street of finding addresses.
Arrays start at 0, so the computer knows it only goes up
from there.
Searching in an array is looking for a particular type of
data and finding where it is in the index. Searching is done
in a pretty methodical way. The computer begins with
Searching
index 0 and looks onward until finding the value it is
looking for. In the worst case, if the computer wanted to
search within an array of 10 and the desired value is on
the 10th spot, then it would search all the way up to the
10th value. In other words, a 300 size array with the value
we want located in the 300th index, the computer would
take 300 steps to search for the value.
How fast insertion depends on where the value is being
Insertion
inserted. The fastest way for insertion in an array is
inserting in the end. Inserting in the beginning or
somewhere in the middle is a bit more complicated.
In the worst case of insertion in an array, inserting, in
the beginning, takes the most steps. The reason is once
the value is inserted in the beginning, the computer has
to move all other values to the right.
Any other value inserted in the middle just takes less
due to the values on the left not moved.
Deletion removes a value within an array. Deletion
Deletion is kind of like insertion in an opposite kind of way.
Instead of placing a value, deletion removes the
value and shifts the values to cover the gap left by
the deletion. Just like insertion, the best case speed
of deletion is at the end — 1 step. It removes the end
value without having to shift any other values.
The worst-case in deletion is at the beginning.
Once it deletes the first value, all the other values to
the right have to be shifted one to the left to cover
the empty space in the array.
The classification of data structure mainly consists of :
1. Primitive data structure
2. Non-primitive data structure
Classification of
data structure :
The primitive data structures are known as basic data
Primitive data
structures. These data structures are directly operated
upon by the machine instructions. Normally, primitive
structure : data structures have different representation on different
computers
Example of Integer Float
primitive data
structure :
Character Pointer
Integer : Float :
The integers are signed or unsigned Float refers floating point or real number.
whole numbers with the specified range It can hold a real number or a number
such as 5, 39, -1917, 0 etc. They have no having a fractional part like 3.112 or
fractional parts. Integers can be positive 588.001 etc. The decimal point signals
or negative but whether or not they can that it is a floating point number, not an
have negative values, it depends upon the integer. The number 15 is an integer but
integer types. 15.0 is a floating point number.
Character : Pointer :
It can store any member of the basic A pointer is but a variable-like name
character set. If a character from this set points or represents a storage location in
is stored in a character variable, its value memory (RAM). RAM contains many
is equivalent to the integer code of that cells to store values. Each cell in memory
character basically known as ASCII code. is 1 byte and has a unique address to
It can hold one letter/symbol like a, B, d identify it. The memory address is always
etc. Characters can also be of different an unsigned integer.
types.
The non-primitive data structures are highly developed
Non-Primitive complex data structures. Basically, these are developed
from the primitive data structure. The non-primitive data
data structure : structure is responsible for organizing the group of
homogeneous and heterogeneous data elements.
Example of Non-primitive data structure :
Lists:
Files :
Stack :
When we perform insertion or deletion operation on a stack, its
base remains unchanged but the top of the stack changes.
Insertion in a stack is called Push and deletion of elements from
the stack is known as Pop.
We can implement a
stack using 2 ways:
In this tutorial, you will learn how insertion sort works. Also, you will find
working examples of insertion sort in C, C++, Java and Python.
Insertion sort works in the similar way as we sort cards in our hand in a card
game.
We assume that the first card is already sorted then, we select an unsorted card. If
the unsorted card is greater than the card in hand, it is placed on the right
otherwise, to the left. In the same way, other unsorted cards are taken and put at
their right place.
A similar approach is used by insertion sort.
Insertion sort is a sorting algorithm that places an unsorted element at its suitable
place in each iteration
Suppose we need to sort the following array.
How
Insertion
Sort
Works?
Compare key Compare key with the first element. If
the first element is greater than key, then key is placed
in front of the first element. key, then key is placed in
front of the first
} }
Abstract Data
Types
The user of data type does not need to
know how that data type is implemented,
for example, we have been using Primitive
values like int, float, char data types only
with the knowledge that these data type
can operate and be performed on without
any idea of how they are implemented.
List ADT
Stack ADT
The head node and the data
nodes are encapsulated in the
ADT. The calling function can
only see the pointer to the
stack.
The stack head structure also
contains a pointer to top and
count of number of entries
currently in stack.
Queue ADT