Title Text
Title Text
PRE-PROGRAMMING
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1621058/images/8278139/Logo_Horizontal_White__Black_Background_.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1621058/images/8278150/Symbol_Negative__Black_Background_.jpg)
ALGORITHMS, PSEUDOCODE, AND DATA STRUCTURES
Title Text
Title Text
ALGORITHMS 101
Title Text
Title Text
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?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8337318/pasted-from-clipboard.png)
Title Text
Title Text
Writing a computer program, is basically writing a set of sequential instructions for the machine to execute.
Algorithms in computer programming
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8337482/Screenshot_2021-03-12_at_12.37.08.png)
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?
EXERCISE
HOUSE DRAWING ALGORITHM
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8338604/5D2CC60B-5CD3-40B4-96A3-AEA20435F858.jpeg)
Let's try and translate what we just did into words, step by step.
exercise
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?
NEXT
Title Text
Title Text
PSEUDOCODE
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?
HOUSE DRAWING ALGORITHM:
• Draw a 10cm vertical line.
• Aproximately 5cm parallel to the previous line, draw another one of the same size.
• Connect both lines with an horizontal line, starting from the bottom of each one
(...)
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.
pseudocode Syntax
Let's check a few concrete algorithms and write the pseudocode to describe them.
NEXT
Title Text
Title Text
A FEW relevant ALGORITHMS
Given the set of numbers above, knowing absolutely nothing about them, how would you proceed to find the number 27?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8337969/Screenshot_2021-03-12_at_14.51.47.png)
exercise
SEARCHIng algorithms
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?
exercise
SEARCHIng algorithms
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8338005/Screenshot_2021-03-12_at_15.01.01.png)
Linear vs. Binary Search
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8338270/Screenshot_2021-03-12_at_16.08.57.png)
Given the set of numbers above, if we wanted to put them in order, from smallest to highest, how could we proceed?
exercise
SORTING algorithms
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8337969/Screenshot_2021-03-12_at_14.51.47.png)
Sorting algorithms comparison
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8338311/Screenshot_2021-03-12_at_16.28.46.png)
Title Text
Title Text
Data structures
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?
ARRAY
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.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8345401/Screenshot_2021-03-15_at_11.08.50.png)
QUEUE
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8340095/B732731D-5C9F-4091-9132-7EB39A499162.jpeg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8340094/5668F3BA-8F41-4D5F-94AE-331290BAC95B.jpeg)
A queue follows a specific order in which data is removed:
FIFO (First In, First Out).
STACK
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8340099/58185776-84BE-4DA3-9671-9DD927487BAD.jpeg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8340100/EF9074E2-8CA5-4D24-B955-81541ACACCA9.jpeg)
A stack follows a specific order in which data is removed:
FILO (First In, Last Out).
GRAPHS
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8345604/Screenshot_2021-03-15_at_11.54.08.png)
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.
Trees
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1628261/images/8345590/Screenshot_2021-03-15_at_11.30.33.png)
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
Algorithms, Pseudocode, and Data Structures
- 1,743