Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
BY
ANDREI IGOR, GOIAN ANDREI, POTÎRNICHE ANDREEA, PUȘCUȚĂ RĂZVAN, SORA DAVID
Contents:
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
Reading is checking what value is in a particular
index 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.
Arraysstart at 0, so the computer knows it only
goes up from there.
Searching
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 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.
Insertion
How fast insertion depends on where the
value is being 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 :
Primitive
The primitive data structures are known as
basic data structures. These data structures
are directly operated upon by the machine
data instructions. Normally, primitive data structures
have different representation on different
structure : computers
Example of Integer Float
primitive
data
structure : Character Pointer
Integer : Float :
The integers are signed or Float refers floating point or real
unsigned whole numbers with the number. It can hold a real number
specified range such as 5, 39, - or a number having a fractional
1917, 0 etc. They have no part like 3.112 or 588.001 etc. The
fractional parts. Integers can be decimal point signals that it is a
positive or negative but whether floating point number, not an
or not they can have negative integer. The number 15 is an
values, it depends upon the integer but 15.0 is a floating point
integer types. number.
Character : Pointer :
Arrays : floating numbers or all characters. Values in an array are identified using
array name with subscripts. Single sub-scripted variables are known as a
one-dimensional array or linear array; two sub-scripted variables are
referred as a two-dimensional array.
One Dimenstional Array Two Dimensional Array
A list is a collection of a variable number of data
items. Lists fall in the non-primitive type of data
structure in the classification of data structure. Every
element on a list contains at least two fields, one is
used to store data and the other one is used for
storing the address of next element.
Lists:
Files :
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
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