DS Unit 1 Notes
DS Unit 1 Notes
DS unit 1 Share
DS unit 1 50 / 50
data structure ↕
data structure is used to organize, process, retrieve and store data
DS make it easy for users to access and work with the data they need in
appropriate ways.
most importantly, data structures organize the information in such a way that it
is easy to understand for machines and as well as humans
The idea is to reduce the space and time complexities of different tasks.
it is important to choose a data structure that is suitable for your situation
because choosing an ill-suited data structure could result in slow runtimes or
unresponsive code.
5 factors to consider before choosing a data structure ↕
What kind of information will be stored?
How will that information be used?
Where should data persist, or be kept, after it is created?
What is the best way to organize the data?
What aspects of memory and storage reservation management
should be considered?
Use of data structures ↕
it is used to implement physical form of ADT
it is a crucial part of designing efficient software
They also play a critical role in algorithm design and how those algorithms are
used within computer programs.
some examples of how DS is used:
storing data: specifies the collection of attributes and corresponding
structures used to store records in a database management system.
managing resources and services: Core operating system (OS) resources and
services areenabled through the use of data structures
data exchange: define the organization of information shared
betweenapplications, such as TCP/IP packets.
ordering and sorting: using priority queues, programmers can manage items
organized according to a specific priority.
indexing: sophisticated data structures such as B-trees are used to index
objects, such as those stored in a database.
searching: binary search trees, B-trees or hash tables speed the ability to find
a specific sought-after item.
scalbility: used for allocating and managing data storageacross distributed
storage locations, ensuring scalability and performance.
charachteristica of ds ↕
Linear or non-linear: This characteristic describes whether the data items are
arranged in sequential order, such as with an array, or in an unordered
sequence, such as with a graph.
linear: has a pattern
non linear: does not have a pattern
Homogeneous or heterogeneous: This characteristic describes whether all data
items in a given repository are of the same type. One example is a collection of
elements in an array, or of various types, such as an abstract data type defined
as a structure in C or a class specification in Java.
homogeneous: of same type
heterogeneous: of different type
Static or dynamic: This characteristic describes how the data structures are
compiled. Static data structures have fixed sizes, structures and memory
locations at compile time. Dynamic data structures have sizes, structures and
memory locations that can shrink or expand, depending on the use.
static: size is already fixed
dynamic: we can freely add or delete items
types of linear data structures
array ↕
An array stores a collection of items at adjoining memory locations.
Items that are the same type are stored together so the position of each
element can be calculated or retrieved easily by an index.
Arrays can be fixed or flexible in length.
stack ↕
A stack stores a collection of items in the linear order that operations are
applied.
This order could be last in, first out (LIFO) or first in, last out (FILO).
queue ↕
A queue stores a collection of items like a stack;
however, the operation order can only be first in, first out.
linked list ↕
A linked list stores a collection of items in a linear order.
Each element, or node, in a linked list contains a data item, as well as a
reference, or link, to the next item in the list.
Types of non linear data structure ↔
tree ↕
A tree stores a collection of items in an abstract, hierarchical way.
Each node is associated with a key value, with parent nodes linked to child
nodes -- or subnodes.
There is one root node that is the ancestor of all the nodes in the tree.
Heap ↕
A heap is a tree-based structure in which each parent node's associated key
value is greater than or equal to the key values of any of its children's key
values.
two types of heap
Max-Heap: In a Max-Heap the key present at the root node must be greatest
among the keys present at all of its children.
Min-heap: Min-Heap the key present at the root node must be minimum among
the keys present at all of it’s children.
Graph ↕
A graph stores a collection of items in a nonlinear fashion.
Graphs are made up of a finite set of nodes, also known as vertices, and lines
that connect them, also known as edges.
These are useful for representing real-world systems such as computer
networks.
trie ↕
A trie, also known as a keyword tree, is a data structure that stores strings as
data items that can be organized in a visual graph.
Hash table ↕
A hash table -- also known as a hash map -- stores a collection of items in an
associative array that plots keys to values.
A hash table uses a hash function to convert an index into an array of buckets
that contain the desired data item.