A COMPARATIVE STUDY OF VARIOUS SORTS OF DATA STRUCTURES

Page 1

e-ISSN: 2582-5208 International Research Journal of Modernization in Engineering Technology and Science Volume:03/Issue:05/May-2021 Impact Factor- 5.354 www.irjmets.com

A COMPARATIVE STUDY OF VARIOUS SORTS OF DATA STRUCTURES Aryan Singh Chauhan*1 *1Independent, Computer Science & Engineering, Prayagraj, Uttar Pradesh, India.

ABSTRACT There are many subjects in computer science from simple basic programming, web development, data science to popular AI/ML. But the one thing still acts as a foundation of computer science, Data Structures are widely used in every field which is still popular and the ever-green field of computer science attracted much research. This research paper intends to compare some commonly used data structures used to this date. And raising some aspects like time and space complexities of the data structures mentioned below. And understanding the concept of data structures. Keywords: Data Structures, Computer Science, Space Complexities, Time Complexities, Linear Structure, NonLinear Structure.

I.

INTRODUCTION

Data Structures is a specific way of organizing, managing, and storing data in Computer(Memory) to retrieve data efficiently. More specifically, A data structure is a group of values, relationships among them, and operations applied to the data. Numerous data structures have been developed by now this includes arrays, binary trees, binary search trees, heaps, hash, queue, linked lists, double linked lists, matrix, graph, and so on. Every data structure is different because every structure stores data at distinct time and memory allocation techniques. There are 2 primary sorts of data structures: 1.Linear: These are the categories of data structures that store data linearly, in memory. Here the thought is to minimize the space and time complexities of various jobs. Some common linear data structures include Array, Linked Lists, Stack & Queue. 2.Non-Linear: These data structures don’t store data in a very set sequence i.e. it does not have a collection within a sequence of connection of all its elements and every element can have multiple ways to connect to other elements. These carry multi-level storage and often cannot be transferred in one go.

II.

METHODOLOGY

So for comparison, our methodology will consist of: Introduction of All Data Structures Representation It will be subdivided into 2 sections: 1. Declaration in C 2. Memory Representation Time Complexities of various Operations

III.

MODELING AND ANALYSIS

Array An array is a finite set of zero-indexed contiguous memory locations. The main idea here is to keep many items of the same type together. Based on the language array can be of 2 types: 1.Homogenous (Which can only store the same type of data)ex: C, Java, Swift 2.Heterogenous (Can Store The Values of Different Data Types)ex: Python, JavaScript. Making it easier to calculate the position of every element by adding a value to an initial value i.e. each element in the array can be accessed through an index key. Important terms in an array are: www.irjmets.com

@International Research Journal of Modernization in Engineering, Technology and Science

[3011]


e-ISSN: 2582-5208 International Research Journal of Modernization in Engineering Technology and Science Volume:03/Issue:05/May-2021 Impact Factor- 5.354 www.irjmets.com ● Element- Item stored in an array. ● Index- The location of the element in the array. Array Representation: Declaration: int array[x] = { foo, faa, bar, xyz, ...}; int(data type) array(array name) [x](array size) =(assignment operator) { foo, faa, bar, xyz, ...}(element) Memory Allocation:

Time Complexities of various operations: For the size of the array be n: Accessing Time: O(1) [Possible because elements are stored in contiguous location] Search Time: O(n) for sequential search: O(log n) for binary search [if array is categorize] Insertion Time: O(n)[Worst case happens when insertion takes place at the beginning of the array and requires shifting of every element] Deletion Time: O(n)[Worst case: deletion takes place at the beginning of the array] 2.2 Stack: A stack or LIFO(Last-In-First-Out) or FILO(First-In-Last-Out) is an Abstract Data Type(ADT). It is commonly used nowadays in many programming languages. Serving as a finite set of elements with two main operations: Push(Inserts element to collection), and Pop(deletes element to the collection which was last inserted). It is derived from many real-world situations. Example: Remove a card or plate from a pile. Moreover, Stack ADT lets all data operations at one end. Stack Representation: Declaration: struct Stack { int top; unsigned capacity; int* array; }; struct Stack* createStack(unsigned capacity) { struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack)); stack->capacity = capacity; stack->top = -1; stack->array = (int*)malloc(stack->capacity * sizeof(int)); return stack; www.irjmets.com

@International Research Journal of Modernization in Engineering, Technology and Science

[3012]


e-ISSN: 2582-5208 International Research Journal of Modernization in Engineering Technology and Science Volume:03/Issue:05/May-2021 Impact Factor- 5.354 www.irjmets.com } Memory Allocation:

Time Complexities of various operations: Push(Insertion): O(1) Pop(Deletion): O(1) Access Time: O(n)[Worst Case] *No running of loop used in testing for the following Time Complexities 2.3 Linked List: It is a sequence of data structures connected via links stored with value in a node. In layman’s terms, A linked list comprises the node where each node contains a data field and a pointer to the element. Linked Lists helps us to overcome some limitations of arrays including the fixed sizes of arrays. Some recent advancements in linked lists are: 1.Doubly Linked List: Here instead of going linearly this allows us to go back and forth between nodes. 2.Circular Linked List: This allows us to connect to all nodes forming a circle meaning unlike, single and double linked lists this does not have any tail(end) node. Linked-List Representation: Declaration: struct Node { int data; struct Node* next; }; Memory Allocation:

Time Complexities of various operations: For Single-Linked Lists: Insertion of the element: O(1) [Assuming the current position and is the position where we intend to add an element] Accessing time of Element: O(n) Searching time of Element: O(n) Deletion of the element: O(1)[Assuming we know the address of the node prev. Node to be deleted] 2.4 Binary Tree www.irjmets.com

@International Research Journal of Modernization in Engineering, Technology and Science

[3013]


e-ISSN: 2582-5208 International Research Journal of Modernization in Engineering Technology and Science Volume:03/Issue:05/May-2021 Impact Factor- 5.354 www.irjmets.com Is a non-linear (tree) data structure. As the name suggests Binary(2), is a ‘rooted tree’ and contains nodes which at max can have 2 successive(children) and edges. Binary trees are the building blocks of other treebased data structures. A binary tree has the benefits of an ordered array and linked list as search is as quick as in sorted array and insertion and deletion operation are fast as a linked list. A binary tree contains 3 parts: 1.Data 2.Pointer to Left Child 3.Pointer to Right Child Binary Tree Representation: Declaration: struct node { int data; struct node *leftChild; struct node *rightChild; }; Memory Representation:

Time Complexities of various Operations: Tree Transversal: O(n) 2.5 Graph It is a non-linear ADT (Abstract Data Type) based on the principles of graph theory. It consists of Vertices(Nodes) connected through Edges. More formally, a graph is a graphical representation of a cluster of objects where some objects are connected by edges(links). A graph can be directed or undirected. A graph is generally searched using DFS(Depth-First-Search): to look at children and BFS(Breadth-First-Search): to look at siblings. Graph Representation: Declaration: struct AdjListNode { int dest; struct AdjListNode* next; }; struct AdjList { struct AdjListNode *head; www.irjmets.com

@International Research Journal of Modernization in Engineering, Technology and Science

[3014]


e-ISSN: 2582-5208 International Research Journal of Modernization in Engineering Technology and Science Volume:03/Issue:05/May-2021 Impact Factor- 5.354 www.irjmets.com }; struct Graph { int V; struct AdjList* array; }; Memory Representation:

Time Complexities of various operations: Adjacency List: Add Vertex(Insertion): O(1) Add Edge(Insertion): O(1) Remove Vertex(Deletion): O(|E|) Remove Edge(Deletion): O(|V|) Adjacency Matrix: Add Vertex(Insertion): O(|V|²) Add Edge(Insertion): O(1) Remove Vertex(Deletion): O(|V|²) Remove Edge(Deletion): O(1)

IV.

RESULTS AND DISCUSSION

Data Structure

Advantages

DisAdvantages

Array

Easy Access of element through Index Number

Size in Fixed

Easy to implement. Stack

Linked List

Binary Tree

www.irjmets.com

Less Space Complexity due to no need for pointers

Is not Dynamic.

Dynamic Size.

Random Access Not Allowed.

Ease of Insertion/Deletion

Not Cache Friendly

A flexible way of holding and moving Data. Faster Insertion and deletion than Arrays & Linked Lists

Many pointers left NULL and thus useless

@International Research Journal of Modernization in Engineering, Technology and Science

[3015]


e-ISSN: 2582-5208 International Research Journal of Modernization in Engineering Technology and Science Volume:03/Issue:05/May-2021 Impact Factor- 5.354 www.irjmets.com Graph

Makes Large Data Simple to work with

V.

Large Memory Complexity

CONCLUSION

So here we talked about five commonly used data structures along with their Comparison, Time Complexities, and their Representation. Concluded that Array(Linear) is good for accessing data, the stack is easy to implement and less same complex. Then we discussed linked list which is better in some easy than array due to its dynamic size and ease of insertion/deletion. Then we moved towards non-linear data structures and discussed Binary Trees and Graphs. In Binary trees, we discussed its function and benefits. Then in graphs, we found that it helps us by making large data simple to work with.

VI. [1] [2] [3] [4] [5]

REFERENCES

Data Structures Geeks-For-Geeks Data Types and Data Structures Mark Mc Donnel Data Structures and Algorithms Tutorials Point Graph ADT Wikipedia Algorithms & Data Structures Free Code Camp.

www.irjmets.com

@International Research Journal of Modernization in Engineering, Technology and Science

[3016]


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.