Data Structure And Algorithm - Choosing The Right Data Structure

Hello friends,

In the previous article, we have gone through the most common types of data structure. If you want to refer- You may go at,

Today we are going to extend to understand how we can choose the right data structure along with related concepts.

Background

  • No single data structure works well for all purposes, and so it is important to know the strengths and limitations of them
  • It must be rich enough in structure to represent the relationship between data elements
  • The structure should be simple enough that one can effectively process the data when necessary

Stack

Collection with access only to the last element inserted, follows Last in first out

Properties & Method

  • insert/push
  • remove/pop
  • top
  • make empty

Data Structure & Algorithm- Choosing the right Data Structure

Queue

Collection with access only to the item that has been inserted first, follows Last in last out or first in first out

Properties & Method

  • Enqueue
  • Dequeue,
  • Front

Data Structure & Algorithm- Choosing the right Data Structure

Linked List

A Flexible structure, because can grow and shrink on demand.

Elements can be Inserted, Accessed, and Deleted at any position.

Data Structure & Algorithm- Choosing the right Data Structure

Tree

A Tree is a collection of elements called nodes.

One of the nodes is distinguished as a root, along with a relation that places a hierarchical structure on the nodes.

Data Structure & Algorithm- Choosing the right Data Structure

Graph

A Graph is a pictorial representation of a set of objects where some pairs of objects are connected by links.

The interconnected objects are represented by points termed as vertices (ex: A, B, F, etc.) and the links that connect the vertices are called edges (ex: AB, AF, AJ, FB, BJ, BJ, etc.)

Data Structure & Algorithm- Choosing the right Data Structure

Measuring the Data Structure

Time Complexity

Running time or the execution time of operations of data structure must be as small as possible.

Space Complexity

Memory usage of a data structure operation should be as little as possible.

Examples

  • Worst Case - ex: O(n2), O(n3)
  • Average Case - ex: O(log n)
  • Best Case ex: O(n), O(1)

Summary

In today’s article, we started with understanding that each data structure has its unique use case and some of the qualifiers of good data structure. Later we have gone through bit more details about them to help you understand when to use what. Towards the end, we covered on how the efficiency of these data structures are measured.

Hope this article was useful to you. You can let me know for any comment and feedback.

References


Similar Articles