What is Data Structure?
Data Structures allows you to organize your data in such a way it enables you to store collections of data, relate them and perform operations on them accordingly.
Types of Data Structures
1.Built-in/Primitive data structures: They store data of only one type. They include:
a)List: Lists can have heterogeneous data types in them. They can be mutable that is they can be changed. We use Square brackets to create lists.
Example:
a=['apple','banana','pear']
#We can add another fruit into the lists through
a.append(orange)
print(a)
#When we run this in any IDE; a=['apple','banana','pear','orange']
b)Tuples : They are not mutable. They are faster than lists. We use regular brackets to create tuples.
b=(3,4,5)
print(b)
solution:(3,4,5)
c)Dictionary : They hold key value pairs. We use curly brackets to initialize dictionaries. Dictionaries are mutable.
c={1:'python',2:'java'}
print(c)
solution: {1:'python',2:'java'}
d)Sets: These are unordered collection of unique elements. We use curly brackets to initialize sets. Sets are mutable.
d = {2,3,4,2}
print(d)
solution: {2,3,4}
#This is because sets do not repeat same elements inside it.
2. User-defined/derived/non-primitive data Structures: They are data of more than one type. They include;
a)Stacks: The data that is entered last will be the first one to be accessed. They are built using array structure and have operations namely push which adds an element to the collection and pop which removes elements from a collection. They are used in applications such as recursive programming, reversing words etc.
b)Queues: This is a linear data structure based on the principle of first in first out. They are also built using an array structure and operations can be done on them. They are used in the application of traffic congestion management and in operating systems for job scheduling.
c)Trees: This is a non-linear data structure that has roots and nodes. Roots are where the data originates while nodes are any point where data is accessible to us. The node to proceed is the parent and the latter is the child. Trees are widely used in Html pages and are efficient for searching purposes.
d)Linked lists: These are liner data structures t are not stored concurrently but are linked together through pointers. The node of a list composes of data and a pointer. They are used in image viewing applications and music player applications.
e)Graphs: They are used to store data collection of points and edges. Many applications such as google maps and uber use graphs to find the least path in order to maximize profits.
f)Hashmaps: They are the same as what directions are in python. They are used to implement applications such as phonebooks and populate data.
What are Algorithms?
Algorithms are rules or instructions which are formulated in a finite sequential order to solve problems. They provide pseudocode for problems.
Important things to note when writing algorithms.
-Figure out what is the exact problem
-Determine where you need to start
-Determine where you need to stop
-Formulate the intermediate steps
-Review your steps
Elements of a good Algorithm
-Steps should be finite, clear, and understandable
-Clear and precise description of inputs and outputs
-The algorithm should be flexible
-The steps should make use of general programming fundamentals
Algorithm classes
There are three types;
i)Divide and Conquer - Divides the problem into subparts and solves the subparts separately.
ii)Dynamic programming - Divides the problem into subparts remembers the results of the sub-parts and applies them to similar ones.
iii)Greedy Algorithms - Involves taking the easiest step while solving a problem without worrying about the complexity of the future steps.
Tree Traversal Algorithms
There are three types of tree traversals:
i)In-order traversal: refers to visiting the left nodes followed by the root and then right nodes.
ii)Pre-ordered traversal: refers to visiting the root nodes followed by the left nodes and then right nodes.
iii)Post-order traversal: refers to visiting the left nodes followed by the right nodes and then the root node.
Sorting Algorithms
It is used to sort data in some given order. It can be classified into five steps.
i)Merge sort: The given list is first divided into smaller lists and compares to adjacent lists and records in the desired sequence.
ii)Bubble sort: is a comparison algorithm that first compares and sorts adjacent elements if they are not in the specified order.
iii)Insertion sort: Picks one element of the given list at a time and places it at the exact position where it is to be placed.
iv)Selection sort: Picks one element of a given list at a time and places it at the exact spot where it is placed.
v)Shell sort: allows you to sort elements apart from each other.
Searching Algorithms
Searching algorithms are used to search for or fetch elements present in some given dataset. There are many types of search algorithms; Linear search, Binary search, Exponential search, and interpolation search.
Algorithm analysis
a)A prior analysis: where all factors are assumed to be constant and do affect the implementation.
b)A posterior analysis: The actual values like time complexity or execution on time of an algorithm, and space complexity are gathered.
Thank you for taking your time to read 🤗🥳Happy learning😇🌟.
Top comments (2)
Very insightful and engaging. Thank you Daniel for sharing this useful information.
You're welcome boniface