Introduction to Data Structures and Algorithms


The data structure is a method of collecting and organizing data to perform operations on it effectively. Data Structure is the process of rendering data elements in terms of some relationship to improve organization and storage. For example, we have some information about a programmer named "Happy" who is 23 years old. In this case, "Happy" is the String data type, and 23 is the integer data type.


If you're familiar with Object-Oriented programming concepts, you'll recognize that a class does the same thing: it collects various types of data under a single entity. The only difference is that data structures provide techniques for efficiently accessing and manipulating data.


Data Structures are structures programmed to store ordered data so that we can perform various operations on it quickly. It represents data knowledge to be held in memory. Therefore, it should be designed and implemented to reduce complexity while increasing efficiency.


If you're familiar with Object-Oriented programming concepts, you'll recognize that a class does the same thing: it collects various types of data under a single entity. The only difference is that data structures and algorithms provide techniques for efficiently accessing and manipulating data.



What is an Algorithm?


An algorithm is a finite set of instructions or logic written to perform a specific predefined task. The core logic (solution), expressed either as an informal high-level description as pseudocode or using a flowchart, is defined as an algorithm.


Every Algorithm must have the following characteristics:


1. Input- The Algorithm should receive 0 or more inputs from outside sources.

2. Output- At least one output should be obtained.

3. Definiteness- Each Algorithm step should be well-defined and unambiguous.

4. Finite- The Algorithm should have a finite number of steps.

5. Correctness- Each Algorithm step must produce a valid result.


If an algorithm takes less time to execute and consumes less memory space, it is said to be efficient and fast. The following properties are used to assess an algorithm's performance:


1. Time Complexity

2. Space Complexity



Types of Data Structures


As previously stated, anything that can store data is referred to as a data structure; thus, they are classifieds into two major categories:


1. Primitive Data Structures

2. Non-Primitive Data Structures



Which are stated below:


1. Primitive Data Structures


Integers, floats, Booleans, Chars, and so on are all data structures. Therefore, they are referred to as Primitive Data Structures.

1. Integers

2. Floats

3. Booleans

4. Chars, etc


2. Non-Primitive Data Structures


The List of Non-Primitive Data Structures is stated below:

1. Linked List

2. Tree

3. Graph

4. Stack

5. Queue



Non-Primitive Data Structures


I. Linked List: 


A linked list is a type of linear data structure in which the elements are not stored in consecutive memory locations. Instead, a linked list's components are connected using pointers, as shown in the image below:


Linked List
Linked List



2. Tree :


A data structure is a specialized method of organizing and storing data in a computer to be used more effectively. Stacks, linked lists, and queues are data structures that can be arranged in sequential order. A linked data structure, for example, is made up of nodes that are connected by links or points.


Similarly, the tree data structure is a type of hierarchical data organized in the form of a tree. It is made up of a central node, structural nodes, and sub-nodes that are linked together by edges. We can also say that a tree data structure comprises roots, branches, and leaves that are all connected to one another.


A tree is a nonlinear and hierarchical data structure consisting of nodes, each of which stores a value and a list of references to other nodes (the "children").


Tree Data Structure
Tree Data Structure


3. Graph:


A graph is a nonlinear data structure made up of nodes and edges. The nodes are also known as vertices, and edges are lines or arcs that connect any two nodes in the graph. There are various types of graphs in data structures. A Graph can be defined more formally as,


Graphs data structures
Graphs Data Structures



4. Stacks:


A stack data structure is an Abstract Data Type (ADT) found in almost all programming languages. It is called a stack because it behaves like a real-world stack, such as a deck of cards or a pile of plates.



Stacks Data Structures
Stacks Data Structures



5. Queue:


A queue is a linear structure in which operations are performed in a specific order, which is First In, First Out is the order (FIFO). For example, any queue of consumers for a resource in which the consumer who arrived first is served first is an example of a queue. The distinction between stacks and queues is in the removal process. In a stack, we remove the most recently added item, but in a queue, we remove the least recently added item.


Queue Data Structure
Queue Data Structures

Post a Comment

0 Comments