Title Text

Title Text

PRE-PROGRAMMING

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?

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

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:

  1. It solves the problem at hand
  2. 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

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?

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

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?

exercise

SORTING algorithms

Sorting algorithms comparison

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.

QUEUE

A queue follows a specific order in which data is removed:

FIFO (First In, First Out).

STACK

A stack follows a specific order in which data is removed:

FILO (First In, Last Out).

GRAPHS

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

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,570