A data structure is a way of organizing and storing data in a computer so that it can be accessed and used efficiently.
data structures types:
Arrays: Arrays are used to store a collection of elements of the same data type in contiguous memory locations.
They are commonly used in programming languages to store lists of data such as names, numbers, and dates. For example, an array can be used to store the scores of students in a class.
Stacks: Stacks are used to store a collection of elements that follow the Last-In-First-Out (LIFO) principle.
Queues: Queues are used to store a collection of elements that follow the First-In-First-Out (FIFO) principle.
They are commonly used in programming languages to implement scheduling algorithms and event handling systems.
For example, when a user requests a print job, it is added to the print queue.
Linked lists: Linked lists are used to store a collection of elements that are connected through a series of nodes.
They are commonly used in programming languages to implement dynamic data structures such as stacks and queues.
For example, when a new element is added to a linked list, a new node is created and linked to the previous node.
Trees: Trees are used to store hierarchical data such as file systems and organization charts.
They are commonly used in programming languages to implement search algorithms and database indexing systems.
Graphs: Graphs are used to store relationships between objects such as social networks and road maps.
They are commonly used in programming languages to implement routing algorithms and recommendation systems.
Hash tables: Hash tables are used to store key-value pairs such as usernames and passwords.
They are commonly used in programming languages to implement associative arrays and database indexing systems.
time complexity of data structures:
(Please check the image included in this post)
how to calculate time complexity of program:
To calculate the time complexity of a program, you need to analyze the number of operations that are performed by the program as a function of the input size.
The time complexity is usually expressed using Big O notation, which gives an upper bound on the number of operations required to perform an operation on the data structure .
Identify the algorithm used in the program.
Determine the number of operations performed by the algorithm for a given input size.
Express the number of operations as a function of the input size.
Simplify the function using Big O notation.
For example, letβs say you have a program that sorts an array of n elements using bubble sort. The algorithm has a worst-case time complexity of O(n^2)
This means that if you double the size of the input array, the number of operations required to sort it will increase by a factor of four.
Top comments (0)