Codementor Events

Data structure + Algorithm

Published May 19, 2021
Data structure + Algorithm

Data Structure - From Basic to Complex - Part 1

Program = data structure + algorithm

If we understand the data structure, we will complete 50% program or software.
Luckily, the algorithm can be apply on the data structre. So the chance to success is increased rapidly.

What is the data structure?

We used int, float, bool, double... They are called primitive types.
They are not enough for the program.

We need have place (memory or a variable) to store the collections of somethings such as Customer or Order.
We also need to use that thing to do something such as insert, push, pop, delete, remove,sort... in the fast way.

The data structure is created based on our purpose.
We need to store the customers that come to the bank and we want to serve them in queue where the first customer will be served first, the last customer will be served last.
For example:
The queue is in the bank is
Mr. C --> Mr. B ---> Mr. A
Mr. A is in the front of queue. Mr. A is being served.

So, there is a need to create the Queue data structre with the method:
Customer remove(): get the customer at the front of queue (called enqueue)
void insert(Customer cust); add the customer to end of queue (called dequeue)

That means the Queue is created with

  • Array of customers (*)
  • Methods to manipulate the (*)

Congratulation! We created the queue.

Next part: why the queue contains the Array of customers. Can we use the list or other data structure?

Discover and read more posts from Khoa Nguyen Thanh Dang
get started