DATA STRUCTURES
NAME: C. NIKHIL KUMAR
ROLL NUMBER: 22J21A0535
CLASS: CSE-A
SUBJECT : PYTHON
▪ Data structures in Python are containers that allow you to
store and organize data in a particular format.
▪ They provide efficient ways to perform operations such as
insertion, deletion, retrieval, and modification of data. Python
provides several built-in data structures, including:
✓ LISTS:
▪ Lists are ordered collections of items that can be of different
data types. They are mutable, meaning you can modify the
elements they contain.
▪ Lists are defined using square brackets ([]), and you can
access elements by their index.
▪ Example of creating python list:
List = [1, 2, 3, “GFG”, 2.3]
Print(List)
Output
[1, 2, 3, “GFG”, 2.3]
▪ List elements can be accessed by the assigned index. In python
starting index of the list, sequence is 0 and the ending index is N-1.
✓ TUPLES:
▪ Tuples are similar to lists, but they are immutable, meaning
their elements cannot be modified once defined.
▪ They are defined using parentheses (()) and can be accessed
using indexing.
▪ In python, tuples are created by placing a sequence of values
separated by ‘comma’ with or without the use of parentheses
for grouping of the data sequence.
▪ Example:
Tuple = (‘Geeks’ , ’For’)
print(“nTuple with the use of String:”)
print(Tuple)
Output:
(‘Geeks’ , ‘For)
✓ SETS:
▪ Sets are unordered collections of unique elements. They do not
allow duplicate values.
▪ Sets are defined using curly braces ({}) or the `set()` function.
You can perform set operations like union, intersection, and
difference.
SET IMPLEMENTATION:
✓ DICTIONARIES:
▪ Dictionaries are key-value pairs, where each value is associated
with a unique key. They are also known as associative arrays or
hash maps.
▪ Dictionaries are defined using curly braces ({}) with key-value
pairs separated by a colon (:).
▪ Indexing of python dictionary is done with the help of keys.
These are of any hashable type i.e. an object whose can never
change like strings, numbers, tuples, etc.
✓ ARRAYS:
▪ Arrays are used to store a fixed-size sequence of elements of the
same data type.
▪ Unlike lists, arrays can only contain elements of a single type. In
Python, arrays are available through the `array` module.
✓ LINKED LISTS:
▪ Linked lists are a dynamic data structure composed of nodes,
where each node contains data and a reference (or link) to the
next node in the sequence.
▪ Linked lists are not built-in Python data structures, but you can
implement them using classes and objects.
• A linked list is represented by a pointer to the first node of the
linked list. The first node is called the head. If the linked list is
empty, then the value of the head is NULL. Each node in a list
consists of at least two parts:
➢Data
➢Pointer (Or Reference) to the next node
✓ STACK:
▪ A stack is a Last-In-First-Out (LIFO) data structure, where
elements are added or removed from the top.
▪ Python provides an implementation of stacks using lists or you
can create your own using the `deque` class from the
`collections` module.
✓ QUEUE:
▪ A queue is a First-In-First-Out (FIFO) data structure, where
elements are added at the rear and removed from the front.
▪ Python provides implementations of queues using lists or you
can use the `Queue` class from the `queue` module.
QUEUE:
STRING
➢Python strings are arrays of bytes representing Unicode
characters.
➢In simpler terms, a string is an immutable array of characters.
➢Python does not have a character data type, a single character
is simply a string with a length of 1.
❖ PYTHON STRINGS OPERATIONS
String = "Welcome to NikhilArts"
print("Creating String: ")
print(String)
# Printing First character
print("nFirst character of String is: ")
print(String[0])
# Printing Last character
print("nLast character of String is: ")
print(String[-1])
❑OUTPUT:
Creating string:
Welcome to NikhilArts
First character of string is :
W
Last character of string is :
s
BINARY TREE
oA tree is a hierarchical data structure that looks like the
below figure –
o A binary tree is a tree whose elements can have almost two
children.
tree ---- j <-- root /  f k /   a h z <-- leaves
o Since each element in a binary tree can have only 2 children, we
typically name them the left and right children.
• Binary Tree node contains the following parts.
➢ Data
➢Pointer to left child
➢Pointer to the right child
Data structures in python

Data structures in python

  • 1.
    DATA STRUCTURES NAME: C.NIKHIL KUMAR ROLL NUMBER: 22J21A0535 CLASS: CSE-A SUBJECT : PYTHON
  • 2.
    ▪ Data structuresin Python are containers that allow you to store and organize data in a particular format. ▪ They provide efficient ways to perform operations such as insertion, deletion, retrieval, and modification of data. Python provides several built-in data structures, including:
  • 3.
    ✓ LISTS: ▪ Listsare ordered collections of items that can be of different data types. They are mutable, meaning you can modify the elements they contain. ▪ Lists are defined using square brackets ([]), and you can access elements by their index.
  • 4.
    ▪ Example ofcreating python list: List = [1, 2, 3, “GFG”, 2.3] Print(List) Output [1, 2, 3, “GFG”, 2.3] ▪ List elements can be accessed by the assigned index. In python starting index of the list, sequence is 0 and the ending index is N-1.
  • 5.
    ✓ TUPLES: ▪ Tuplesare similar to lists, but they are immutable, meaning their elements cannot be modified once defined. ▪ They are defined using parentheses (()) and can be accessed using indexing.
  • 6.
    ▪ In python,tuples are created by placing a sequence of values separated by ‘comma’ with or without the use of parentheses for grouping of the data sequence. ▪ Example: Tuple = (‘Geeks’ , ’For’) print(“nTuple with the use of String:”) print(Tuple) Output: (‘Geeks’ , ‘For)
  • 7.
    ✓ SETS: ▪ Setsare unordered collections of unique elements. They do not allow duplicate values. ▪ Sets are defined using curly braces ({}) or the `set()` function. You can perform set operations like union, intersection, and difference.
  • 8.
  • 9.
    ✓ DICTIONARIES: ▪ Dictionariesare key-value pairs, where each value is associated with a unique key. They are also known as associative arrays or hash maps. ▪ Dictionaries are defined using curly braces ({}) with key-value pairs separated by a colon (:).
  • 10.
    ▪ Indexing ofpython dictionary is done with the help of keys. These are of any hashable type i.e. an object whose can never change like strings, numbers, tuples, etc.
  • 11.
    ✓ ARRAYS: ▪ Arraysare used to store a fixed-size sequence of elements of the same data type. ▪ Unlike lists, arrays can only contain elements of a single type. In Python, arrays are available through the `array` module.
  • 12.
    ✓ LINKED LISTS: ▪Linked lists are a dynamic data structure composed of nodes, where each node contains data and a reference (or link) to the next node in the sequence. ▪ Linked lists are not built-in Python data structures, but you can implement them using classes and objects.
  • 13.
    • A linkedlist is represented by a pointer to the first node of the linked list. The first node is called the head. If the linked list is empty, then the value of the head is NULL. Each node in a list consists of at least two parts: ➢Data ➢Pointer (Or Reference) to the next node
  • 15.
    ✓ STACK: ▪ Astack is a Last-In-First-Out (LIFO) data structure, where elements are added or removed from the top. ▪ Python provides an implementation of stacks using lists or you can create your own using the `deque` class from the `collections` module.
  • 17.
    ✓ QUEUE: ▪ Aqueue is a First-In-First-Out (FIFO) data structure, where elements are added at the rear and removed from the front. ▪ Python provides implementations of queues using lists or you can use the `Queue` class from the `queue` module.
  • 18.
  • 19.
    STRING ➢Python strings arearrays of bytes representing Unicode characters. ➢In simpler terms, a string is an immutable array of characters. ➢Python does not have a character data type, a single character is simply a string with a length of 1.
  • 20.
    ❖ PYTHON STRINGSOPERATIONS String = "Welcome to NikhilArts" print("Creating String: ") print(String) # Printing First character print("nFirst character of String is: ") print(String[0]) # Printing Last character print("nLast character of String is: ") print(String[-1]) ❑OUTPUT: Creating string: Welcome to NikhilArts First character of string is : W Last character of string is : s
  • 21.
    BINARY TREE oA treeis a hierarchical data structure that looks like the below figure – o A binary tree is a tree whose elements can have almost two children. tree ---- j <-- root / f k / a h z <-- leaves
  • 22.
    o Since eachelement in a binary tree can have only 2 children, we typically name them the left and right children. • Binary Tree node contains the following parts. ➢ Data ➢Pointer to left child ➢Pointer to the right child