0% found this document useful (0 votes)
19 views6 pages

DS Unit-1

Data structure notes created by me. These are shorts notes. You can prepare from these notes for you exam and write it as it is. These notes were created for MDU students but you can use it if helpful.

Uploaded by

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

DS Unit-1

Data structure notes created by me. These are shorts notes. You can prepare from these notes for you exam and write it as it is. These notes were created for MDU students but you can use it if helpful.

Uploaded by

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

Unit - 1

Q1-Data Structure
-Data structures refer to the methods and techniques used to organize and
store data in a computer system. BCA programs typically cover various types
of data structures such as arrays, linked lists, stacks, queues, trees, and
graphs. Students learn how to choose the appropriate data structure based
on the requirements of a specific problem or task. Understanding data
structures is fundamental for efficient algorithm design and optimization,
which are crucial aspects of computer science and programming.

Q2-Explain its Categories/Types-


-Primitive Data Structures:

• Integer: Represents whole numbers.


• Float: Represents decimal numbers.
• Character: Represents individual characters.
• Boolean: Represents true or false values.
• Non-Primitive Data Structures:
• Arrays: Ordered collection of elements of the same type.
• Linked Lists: Elements linked together, allowing dynamic size and
easy insertion/deletion.
• Stacks: Follows Last In, First Out (LIFO) principle; elements added
and removed from the same end.
• Queues: Follows First In, First Out (FIFO) principle; elements
added at the rear and removed from the front.
• Trees: Hierarchical structure with a root node and branches;
examples include binary trees.
• Graphs: Networks of nodes connected by edges, allowing more
complex relationships.
• Hash Tables: Uses a hash function to map data to a fixed-size
array, facilitating quick retrieval.

Q3-Application of DS
-Databases: Data structures like B-trees and hash tables are used for efficient
data storage and retrieval in databases.
• Operating Systems: Memory management, file systems, and
process scheduling involve the use of data structures like stacks, queues, and
linked lists.
• Compiler Design: Abstract Syntax Trees (AST) are employed in
compilers for parsing and analysing code.
• Networking: Graphs are used to represent and analyze network
topologies, and queues manage data flow.
• Artificial Intelligence: Graphs and trees are used in algorithms
like decision trees and neural networks.
• Graphics: Data structures like matrices and arrays are essential
for representing images and graphics.
• Web Development: Dynamic data structures like linked lists and
trees are used in various web applications for efficient data management.
• Search and Sorting Algorithms: Data structures play a vital role in
optimizing search and sorting algorithms, improving overall system
performance.

Q4-What is String
-a "string" is a sequence of characters. It can include letters, numbers,
symbols, and spaces. Strings are often used to represent text and are a
fundamental data type in many programming languages. In most languages,
strings are enclosed within double quotation marks (e.g., "Hello, World!").
Operations on strings include concatenation (joining two strings), substring
extraction, and various methods for manipulating and analyzing text. Strings
are essential for tasks involving text processing, user input, and
communication with external systems.

Q5-Operations of String
-Concatenation: Combining two or more strings. For example, "Hello" + " " +
"World" results in "Hello World".
• Length: Finding the number of characters in a string. The length
of "Hello" is 5.
• Substring: Extracting a portion of a string. For instance, extracting
"lo" from "Hello".
• Indexing: Accessing individual characters in a string using their
position (index). In "Hello", 'H' is at index 0.
• Searching: Finding the position of a specific substring within a
string.
• Comparison: Comparing two strings to check if they are equal or
which one comes first lexicographically.
• Modification: Changing the case of characters (uppercase to
lowercase or vice versa).
• Splitting: Dividing a string into substrings based on a specified
delimiter.
• Trimming: Removing leading and trailing whitespaces from a
string.
• Replacing: Substituting occurrences of one substring with
another within a string.

Q6-Explain Pattern Matching Algorithm


-Pattern Matching is a fundamental algorithmic problem that involves finding
a specific pattern within a larger text or sequence. This problem has
numerous applications in fields such as text processing, data mining,
bioinformatics, and more. Several algorithms address this problem efficiently,
and one common approach is the Knuth-Morris-Pratt (KMP) algorithm. Here's
an overview of the KMP algorithm:
Knuth-Morris-Pratt (KMP) Algorithm:
•Preprocessing (Building the LPS Array):
•Construct the Longest Proper Prefix which is also a Suffix (LPS) array for the
pattern.
•LPS[i] represents the length of the longest proper prefix that is also a suffix
of the pattern substring ending at position i.
•Search:
•Traverse through the text while matching characters with the pattern.
•If a mismatch occurs at position j in the pattern, use information from the
LPS array to determine the next position to compare.
•Move the pattern by (j - LPS[j]) positions to the right, where LPS[j] is the
length of the longest proper prefix that is also a suffix of the pattern substring
ending at position j.

Example:
Consider the pattern "ABABCAB" and its LPS array:
Pattern Index 0 1 2 3 4 5 6
Pattern A B A B C A B
LPS 0 0 1 2 0 1
Q7-Explain Time & Space Complexity of an Algorithm.
-Time Complexity:
Time complexity of an algorithm represents the amount of time it takes to
run as a function of the size of the input. It provides an estimate of the
number of basic operations (such as comparisons, assignments, or arithmetic
operations) an algorithm performs based on the input size.
Notation commonly used to describe time complexity:
•Big O (O): Represents the upper bound of the growth rate. It describes the
worst-case scenario.
•Omega (Ω): Represents the lower bound of the growth rate. It describes the
best-case scenario.
•Theta (Θ): Represents both the upper and lower bounds, indicating a tight
range of possible growth rates.
For example, an algorithm with time complexity O(n) means that the running
time grows linearly with the size of the input.

Space Complexity:
Space complexity of an algorithm represents the amount of memory space
required by the algorithm in relation to the input size. It includes the space
required by the input data, the space required by the algorithm itself, and any
auxiliary space needed for intermediate computations.
Similar to time complexity, space complexity is also described using big O
notation. For example, an algorithm with space complexity O(n) means that
the amount of memory space required grows linearly with the size of the
input.
Understanding time and space complexity is crucial for evaluating and
comparing the efficiency of different algorithms. It helps in selecting the most
suitable algorithm for a given problem based on factors like input size and
available memory.

Extra Unit-1
8-Linear & Non-Linear DS
-Linear Data Structure:

Elements are arranged in a sequential manner, where each element has a


unique predecessor and successor, except for the first and last elements.
Traversal is straightforward, moving in a single direction.
Examples include arrays, linked lists, stacks, and queues.
Non-Linear Data Structure:
Elements are not arranged in a sequential order. They may have multiple
predecessors and successors.
Traversal involves a hierarchical or interconnected structure.
Examples include trees and graphs.

9-Homogeneous & Non Homogeneous Ds


-Homogeneous Data
Structure:

All elements of the data structure are of the same type.


Elements have similar data types and structure.
Examples include arrays and linked lists where each element holds data of
the same type.

-Non-Homogeneous Data Structure:

Elements of the data structure can be of different types.


Elements may vary in data types, sizes, or structures.
Examples include structures, records, or objects where each element can
contain different types of data.

10-Static and Dynamic DS

-Static: Fixed size, known at compile-time.


Dynamic: Variable size, can change during runtime.

Memory Allocation:
Static: Memory is allocated during compile-time.
Dynamic: Memory is allocated during runtime, often using pointers.

Flexibility:
Static: Cannot be resized once created.
Dynamic: Can grow or shrink dynamically.

Examples:
Static: Arrays, static arrays.
Dynamic: Linked lists, dynamic arrays, queues, trees.
Memory Management:
Static: Memory management is simpler as the size is fixed.
Dynamic: Requires more complex memory management, dealing with
allocation and deallocation during runtime.

Efficiency:
Static: Can be more efficient in terms of memory usage for fixed-size
structures.
Dynamic: Offers flexibility but may have slightly more overhead due to
dynamic memory allocation.

You might also like