Saturday, September 14, 2024

Data Structure and Algorithm

No DSA? (->nullptr) Ahead! 

-Guided by- Mrs. Sampada A. Kulkarni    


Did you open the IDE to start implementing a data structure only to find out that it's just a "Hello World!" program? I did, too. Let's populate our array with some actual data structures! 

A data structure is a way of organizing a collection of meaningful information. This organization can involve creating objects, performing operations on those objects, allocating the objects, and much more... 

ARRAY : 



Non-primitive, linear, sequential, and static data structure. You might be wondering how to remember all these classifications.
    



An array is a Data structure consisting of a collection of elements that can be identified by an index. An array's index starts from 0 to n-1, where n is the length of the array. An array is homogenous(i.e. stores only one kind of data).

Exploring beyond the limits has been my best experience until now. Let's do the same.


-1 index Of Array

 

You may have heard of the array's -1 index. It is not accessible. Do you know how it is used in programming, especially in DSA?

-1 Index Can be used as follows when traversing the array or searching for some element. :

  1. The end of an array.
  2. A null value.
  3. A special marker for an algorithm.
Understanding the -1 index concept is crucial in various algorithms and data structures, such as: 

Binary Search: -1 can indicate the absence of a target element.
Dynamic Programming: -1 can represent an invalid state.
Graph Algorithms: -1 can mark the absence of a connection.

Remember, there's no -1 position in an array, but the -1 index can hold significant meaning in the right context!

LINKED LIST :


It is Non-Primitive, Linear, Non-Sequential and Dynamic. Every element contains two parts: the data and the address of the next component.

In programming language, we call the second part the pointer towards the next element. Hence, the arrow is the representation of this pointer.

A node in a linked list typically consists of two parts:
1. Data: The actual value or information stored in the node.
2. Next Pointer (or Reference): A pointer or reference to the next node in the list.
A null pointer is given to the last element of the list.
This allows for efficient insertion and deletion of nodes at any position in the list.
Have you ever wondered if there's a way to create a linked list that never ends? A list that goes on forever, without a terminating node? Sounds like a paradox, right? But, bear with me, and let's explore this mind-bending concept.

Never Ending Linked List :


In theory, a never-ending linked list is possible. Imagine a circularly linked list, where the last node points back to the first node, creating a loop. This way, there is no terminating node, and the list appears endless.

Image courtesy by: https://quescol.com/wp-content/uploads/2021/02/Circular-Linked-List.png

These two data structures are used to create many big and complex data structures like .. Stack, Queue, Tree and Graph.

Combining Arrays and Linked Lists:

1. Enables creation of complex data structures like stacks, queues, trees, and graphs.
2. Binary search trees can be implemented using linked lists for efficient searching, insertion, and deletion.
3. Graphs can be represented using adjacency lists (linked lists of edges).

And that's a wrap, folks! Arrays and linked lists are just the beginning of our DSA journey. By mastering these fundamental data structures, you'll unlock the secrets of efficient data organization and manipulation.




Stack and it's Implementation in day to day Life!

  Peek() Applications!   - Guided By Mrs. Sampada Kulkarni This time let us continue the journey of exploring more into them and findi...