0% found this document useful (0 votes)
4 views

dsa

Data structures are crucial for efficiently organizing and managing data in computer systems, impacting the performance of algorithms. They are categorized into primitive and non-primitive types, with linear and non-linear structures, each serving different purposes. Understanding the appropriate data structure enhances program efficiency and resource optimization.

Uploaded by

fazalyt090
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

dsa

Data structures are crucial for efficiently organizing and managing data in computer systems, impacting the performance of algorithms. They are categorized into primitive and non-primitive types, with linear and non-linear structures, each serving different purposes. Understanding the appropriate data structure enhances program efficiency and resource optimization.

Uploaded by

fazalyt090
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Why Data Structures?

Data structures (DS) are essential for organizing, managing, and storing data efficiently in
computer systems. They provide a way to perform operations like searching, inserting,
deleting, and updating data effectively. Properly chosen data structures enhance program
efficiency, reduce complexity, and optimize resource usage.

What is a Data Structure?

A Data Structure is a specialized format for organizing and storing data in a computer so that
it can be accessed and manipulated efficiently. It defines how data is collected, stored, and
related to each other, which directly impacts the performance of algorithms operating on the
data.

Types of Data Structures

1. Primitive Data Structures

These are the basic data types provided by the programming language. They are predefined
and directly operated upon by the machine instructions. Examples include:

 Int: Represents integers (e.g., 1, 2, -3).

 Float: Represents real numbers with decimal points (e.g., 3.14, -2.7).

 Char: Represents single characters (e.g., 'A', 'b', '$').

 Double: Similar to float but with double the precision, allowing for more accurate
representation of large or small decimal values.

2. Non-Primitive Data Structures

These are more complex data structures that are built using primitive data types. They are
divided into two categories:

Linear Data Structures

In linear data structures, elements are arranged sequentially, and each element has a single
successor and predecessor (except the first and last). Examples include:

1. Array

o A collection of elements stored in contiguous memory locations.

o Fixed size.

o Example: int arr[5] = {1, 2, 3, 4, 5};

2. Stack

o A collection of elements with Last In First Out (LIFO) behavior.

o Operations: push (insert), pop (remove).


o Example: Managing function calls in recursion.

3. Queue

o A collection of elements with First In First Out (FIFO) behavior.

o Types: Simple Queue, Circular Queue, Priority Queue.

o Example: Job scheduling in an operating system.

4. Linked List

o A collection of nodes, where each node contains data and a pointer to the next
node.

o Types: Singly Linked List, Doubly Linked List, Circular Linked List.

o Example: Dynamic memory allocation.

Non-Linear Data Structures

In non-linear data structures, elements are not arranged in a sequential order. They have
hierarchical or interconnected relationships.

1. Tree

o A hierarchical data structure with a root node and child nodes.

o Types: Binary Tree, Binary Search Tree (BST), AVL Tree, etc.

o Example: File systems.

2. Graph

o A collection of nodes (vertices) connected by edges.

o Types: Directed Graph, Undirected Graph, Weighted Graph.

o Example: Social networks, Google Maps.

3. Hash Tree (Merkle Tree)

o A tree structure where each leaf node contains the hash of a data block, and each
internal node contains the hash of its children.

o Example: Blockchain systems.

Static vs Dynamic Data Structures

1. Static Data Structures

o Fixed size, defined at compile time.

o Example: Arrays.

o Pros: Memory allocation is predictable and straightforward.


o Cons: Wastage of memory if not fully utilized or lack of flexibility for resizing.

2. Dynamic Data Structures

o Size can grow or shrink during runtime.

o Example: Linked Lists.

o Pros: Efficient use of memory and flexibility.

o Cons: Overhead of memory allocation/deallocation during runtime.

By understanding and applying the right data structure, you can solve computational
problems more efficiently and design algorithms tailored for specific tasks.

Stack :-
Key Points:

 Definition: A stack is a linear data structure that follows the Last In, First Out (LIFO) principle, meaning
the last element added is the first to be removed.

 Basic Operations:

o Push: Adds an element to the top of the stack.

o Pop: Removes the element from the top of the stack.

o Peek/Top: Retrieves the top element without removing it.

o isEmpty: Checks if the stack is empty.

 Applications:

o Expression Evaluation: Stacks are used to evaluate expressions, especially in compilers.

o Backtracking Algorithms: Utilized in algorithms like maze solving, where previous states are
stored.

o Function Call Management: In programming languages, stacks manage function calls and
local variables.

 Implementation: Stacks can be implemented using arrays or linked lists.

Notes:

 Understanding stack operations is fundamental for algorithm development and problem-solving in


computer science.

 Mastering stacks is essential for top tech jobs, as they are a foundational concept in data structures
and algorithms.

You might also like