ALGORITHMS, PSEUDOCODE, AND DATA STRUCTURES
An algorithm can be defined as a finite series of sequential steps we must implement in order to solve a certain problem.
A cooking recipe is an algorithm.
The instructions to start a car make up an algorithm.
A computer program is an algorithm.
What is an algorithm?
Writing a computer program, is basically writing a set of sequential instructions for the machine to execute.
Algorithms in computer programming
A computer algorithm may be something as simple as the steps to sum all the numbers in an array, or the route finding algorithms used by Google Maps and similar apps.
There are two major criteria:
- It solves the problem at hand
- It does so in an efficient way
It's important to keep in mind that the efficiency of an algorithm depends on the problem we're trying to solve.
Asymptotic analysis compares algorithms independently of the programming language and hardware used.
What Makes A GOOd algorithm?
HOUSE DRAWING ALGORITHM
Let's try and translate what we just did into words, step by step.
house drawing algorithm Explained
We've implemented a simple algorithm for drawing a house, and then written the steps in a somewhat funny language.
But was it just for fun, or does it actually relate to our life as future programmers?
Pseudocode describes the steps of an algorithm in a language that any programmer can understand, independently of the programming language they're used to work in.
A programmer who needs to develop an algorithm will often start with a pseudocode description.
What is Pseudocode?
There are no specific rules to writing pseudocode, as it isn't an official language.
Generally, it uses keywords and structural conventions that are common to all programming languages, but omits language specific code.
It can be written in a lower or higher level manner.
Let's check a few concrete algorithms and write the pseudocode to describe them.
A FEW relevant ALGORITHMS
Given the set of numbers above, knowing absolutely nothing about them, how would you proceed to find the number 27?
Given the set of numbers above, knowing just that they are in order (from lowest to highest), how would you proceed to find the number 27?
Linear vs. Binary Search
Given the set of numbers above, if we wanted to put them in order, from smallest to highest, how could we proceed?
Sorting algorithms comparison
A data structure is a way to store and organize data in memory, so they can be accessed and modified in an efficient manner.
You've already worked with at least one type of data structures. Any guesses?
What is A data structure?
const namesArray = ['Mike', 'Will', 'Lucas', 'Dustin', 'Eleven'];
A variable can only store one item at a time.
An array is a way for us to store items at contiguous memory locations.
A queue follows a specific order in which data is removed:
FIFO (First In, First Out).
A stack follows a specific order in which data is removed:
FILO (First In, Last Out).
Graph is a collection of data that is linked within itself. The interconnected objects are represented by points (called vertices), and the links between them are termed edges.
A common use: social media friends suggestions.
A special kind of graph.
Data can be traversed with recursion to two algorithms: BFS (Breadth First Search) and DFS (Depth First Search).
Why Should I care?
Knowingly or not, directly or not, you'll be working with data structures every single day of your software developer life.
Special programs use a stack structure to keep track of the functions invocation in your program. This structure is termed a call stack.
The same programs use a tree structure to parse your code and execute it. This structure is called an Abstract Syntax Tree.
Algorithms, Pseudocode, and Data Structures
By Soraia Veríssimo