Home
About Us Privacy Policy
 

APPLICATION OF DATA STRUCTURES IN PROGRAMMING

ADVERTISEMENT

Intermediate Data Structures



What are Data Structures in Computer Science, and why are they used?

Data structures are a technique of organizing data into a prespecified arrangement for efficient processing. Efficiency could be in favor of disk space or RAM, or execution performance.

Before any further explanation, lets us have a look at an example. Suppose you want to sort three numbers in ascending order stored in three different variables. Here is one way to do it.

a = 1
b = 0
c = 2

# Store sorted values
x = None
y = None
z = None

# First check for a
if a < b and a < c:
    x = a
    if b < c:
        y = b 
        z = c
    else:
        y = c 
        z = b

# Then Check for B
elif b < a and b < c:
    x = b
    if a < c:
        y = a 
        z = c
    else:
        y = c
        z = a

# Then check for C
elif c < a and c < b:
    x = c 
    if a < b:
        y = a 
        z = c
    else:
        y = c
        z = a

print(x, y, z)

0 1 2

As you can observe, the solution is hard to follow, understand, and repetitive. It might give results for three variables, but what will happen when sorting thousands or millions of values. It's almost impossible to write programs using the above approach. Instead, we require a better way of managing data. Hence, we need Data Structures.

Data structures are a technique of organizing data into a prespecified arrangement for efficient processing.


ADVERTISEMENT

Different Data Structures

These are some of the different data structures in computer science:

  • Stack
  • Queue
  • Array
  • Linked List
  • Binary Tree
  • Binary Search Tree
  • Heap
  • Hashing
  • Graph
  • Matrix

Covering data structures is beyond learning Python, as it is not a Python concept but a computer science concept.

You can read about data structures from external sources .


ADVERTISEMENT

Data Structures supported in Python.

As we have learned, Data structures are imperative in structuring and processing data with maximum efficiency. Python provides several in-built data structures for processing data.

Python's in-built data structures:

We will explore data structures in Python in detail separately.

Here are five widespread usages of data structures.

  • Databases
  • File Systems
  • Mathematical Computing
  • Sorting Data
  • Categorizing Data
  • Instant Data Lookup, a.k.a, lookup tables

Data structures allow for optimal resource usage such as disk space or RAM, or computational performance.

# Using Lists to sort numbers

numbers = [1, 2, 0, 5, 4, 3, 9, 7, 8, 6]
no_of_elements = len(numbers)
for i in range(0, no_of_elements ):
    for j in range(0, no_of_elements ):
        if numbers [i] < numbers[j]:
            temp = numbers[i]
            numbers[i] = numbers[j]
            numbers[j] = temp
print(numbers)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

As illustrated in the above example, we could sort numbers efficiently using Lists, an in-built data structure in Python.


ADVERTISEMENT

Conclusion

In this chapter, we learned about data structures, their importance while developing large, maintainable systems while keeping the data organized and improving processing efficiency.


ADVERTISEMENT



All product names, logos, and brands are property of their respective owners.