A data structure is a naming convention for storing and organizing data. An algorithm, on the other hand, is a set of instructions for solving a certain issue. We can develop efficient and optimized computer programs by learning data structures and algorithms. Some of these data structures include lists, dictionaries, tuples, sets, queues, stacks, linked lists, among others. Lists, tuples, sets, and dictionaries are the four types of built-in data structures.
Lists.
A list is defined by square brackets and contains comma-separated data. The list is ordered and mutable. It can include a variety of data kinds. An example is:
grades = ['A','B','C','D',āEā]
The allocated index can be used to access list items. The starting index of a list in Python is 0 and the ending index is N-1 (if there are N entries).
Tuples.
A tuple is another example of a container. It's an immutable ordered sequence of items data type. Because you can't add or delete members from tuples, or arrange them in a certain order, they're immutable. Tuples are created in Python by inserting a sequence of values separated by a 'comma', with or without the use of parenthesis for data grouping.
Sets.
A set is an unordered and mutable collection of distinct items. It can help us swiftly delete duplicates from a list. Sets are mostly used for membership checks and removing duplicate items.
Dictionaries.
A dictionary is a data structure that is both mutable and unordered. It allows for the storage of two objects (i.e. keys and values). Python Dictionary indexing is done with the aid of keys. These can be of any hashable type, i.e. an object that does not change over time, such as strings, integers, tuples, and so on. Dictionaries are created using curly braces {}. E.g:
Dict = {'Name': 'Students', 1: [1, 2, 3, 4]}
Linked Lists.
A linked list is a linear data structure in which the entries are not kept in memory in the same order. A linked list's items are connected via pointers. A pointer to the first node of a linked list is used to represent it. The head is the initial node in the chain. The value of the head is NULL if the linked list is empty. A linked list is made up of two parts: data, and the pointer to the next node.
Top comments (0)