Nekode
Data structure and algorithm

Intro

Learn basic data structure & algorithm

Rifki ahmad fahrezi

Rifki ahmad fahrezi

What is algorithm

Algorithm is a collection of commands or instructions about how to solve a problem.Not just a bunch of command, an algorithm must be sequential and the tasks given must be clear and calculated. To design an algorithm you can use flowchart and pseudocode.

Flowchart

A flowchart is a diagram that shows every step or command in a process. Each type of step can be represented by a specific shape connected with an arrow sign.

Flowchart symbols

For example here is the flowchart of how to make a coffee.

Flowchart symbols

Pseudocode

Pseudocode is a representation of an algorithm that uses everyday language. It is much easier to implement if you do not have any background knowledge of programming. Pseudocode acts as a bridge that complements the flowchart and real code. Using a flowchart provides basic guidelines when implementing an algorithm into real code.

Here is the same example of an algorithm for making coffee, but now using pseudocode.

BEGIN
    PRINT "Go to kitchen"
    
    PRINT "Add coffee powder to a cup"
    
    IF hot_water_available THEN
        PRINT "Pour water into the cup"
    ELSE
        PRINT "Boil water"
    ENDIF
    PRINT "Pour water into the cup"

    PRINT "Stir well"

    IF want_sugar_milk THEN
        PRINT "Add sugar/milk"
    ENDIF

    PRINT "Coffee is ready"
END

What is data structure

A data structures is a special technique used to manage and store data in a computer in such a way that we can perform operations on the stored data.

Data is an information, and algorithm is a rule and instruction that change data into something that can be used into a program, There is alot type of data structures in programming language, here is the basics:

Array

Array is a collection of data that can be have the same type or different, array stored in the same memory location that next to each other. An item of array known as element, Array element can be acces with index that ussualy start with 0, here's an example of array in javascript

const array = [1,2,3,4,5]
 
//  0,1,2,3,4 -> index
// [1,2,3,4,5] -> array
 
// access an element of array
console.log(array[3]) // -> 4

Stack

A stack is a linear data structure that follows the LIFO (Last-In-Fist-Out) method, or the last inserted element it also the first element that removed. Stack has five methods that can do the data manipulation, that is:

  1. push() : Add element to the very top of an array.
  2. peek() : See the highest element or the last inserted element.
  3. isEmpty() : Check if stack is empty.
  4. size() : To know the size of the stack.
  5. pop() : To remove the highest element or last element that inserted before.

Here is demo to know how stack works

Queue

A Queue is a data structure that follows FIFO (First-In-First-Out) method, where the first interted element is also the first element that removed. Here is methods that can performs data manipulation in Queue:

  1. enqueue() : Add element to the very top of an array.
  2. peek() : See the deepest element or the first inserted element.
  3. isEmpty() : Check if Queue is empty.
  4. size() : To know the size of the Queue.
  5. enqueue() : To remove the deepest element or first element that inserted before.

Here is demo to know how queue works

Hash tables

A hash table is a data structure that stores key-value pairs for fast lookups. For example, in a national ID system, each person's unique ID number (key) maps to their personal details (value), such as their name, address, and date of birth. This allows efficient retrieval of information using the ID number as the lookup key.

Learn more about hash table here

Linked list

A linked list stores a collection of items in a linear order. Each item in a linked list is called a node, and each node contains data and a link (or reference) to the next node in the list. The nodes are connected to each other through these references, forming a chain-like structure. Each node contains a pointer that links to the next node in the sequence.

example linked list

Learn more about Linked list here

On this page