0% found this document useful (0 votes)
2 views63 pages

DataStructures ErasmusCourse Report

The document outlines an individual assignment for a data structures course at Riga Technical University, detailing various programming tasks related to data structures such as arrays, stacks, queues, linked lists, binary search trees, and graphs. It includes definitions, classifications, and applications of these data structures, along with bibliographic references for further reading. The assignment emphasizes practical implementation through programming exercises and theoretical understanding of data structure concepts.

Uploaded by

abdulaziz - sh
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)
2 views63 pages

DataStructures ErasmusCourse Report

The document outlines an individual assignment for a data structures course at Riga Technical University, detailing various programming tasks related to data structures such as arrays, stacks, queues, linked lists, binary search trees, and graphs. It includes definitions, classifications, and applications of these data structures, along with bibliographic references for further reading. The assignment emphasizes practical implementation through programming exercises and theoretical understanding of data structure concepts.

Uploaded by

abdulaziz - sh
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

RIGA TECHNICAL UNIVERSITY

Faculty of Computer Science and Information Technology Institute of Applied Computer


Systems

“Data Strcture Indvidual Assignmnet”

TASK OF INDIVIDUAL WORK

"DE0918 - Data Structures and Algorithms”

Asst: Prof, Padmaraj Nidagundi

Student Name: Abdul Azeez, Shabaneh


Student Card No: 260ADB044

2026
INDEX

1. Assignment 3

1. a) Write a 3 programs to show how we use array. Error! Bookmark not defined.

2. Explain about data structure Error! Bookmark not defined.

4. Bibliography 9

2
First Assignment

a)Write a program to implement an integer array with operations: insert,


delete, search, and display.

Program :

3
Output :

4
• b) Write a program to implement a character array (string) with similar
operations: insert, delete, search, and display.

5
Output

6
Definition and Classification of Data Structures
Definition
A data structure is a systematic way of organizing, storing, and managing data in a computer
so that it can be accessed, modified, and processed efficiently. It defines how data elements are
arranged in memory and the operations that can be performed on them, such as insertion,
deletion, searching, and traversal. Proper use of data structures helps improve program
performance, reduce complexity, and optimize the use of memory (Sahni & Horowitz, 2005).

7
Classification
Data structures are primarily classified into two main categories:
• Linear Data Structures: These are structures where data elements are arranged in a
sequential or linear order. Every element is attached to its previous and next adjacent
elements, making them easy to traverse using simple loops. Common examples include
arrays, linked lists, stacks, and queues.
• Non-Linear Data Structures: In these structures, data elements are not arranged
sequentially; instead, they form a hierarchical relationship between elements. Accessing
data can be arbitrary or hierarchical, which is often more complex to navigate than linear
structures. Examples include trees and graphs.

8
Bibliography

1. Goodrich, M. T., Tamassia, R., & Goldwasser, M. H. (2014). Data Structures and
Algorithms in Java. Wiley.
2. Nidagundi, P. (2025). DIP203/DE0918 - Data Structures and Algorithms Lecture Materials.
Riga Technical University.
3. Sahni, S., & Horowitz, E. (2005). Fundamentals of Data Structures. Computer Science
Press.

9
Second Assignment

A) Implement a stack using an array with push, pop, and peek operations.

10
Output

B )Implement a stack using a linked list with the same operations.

11
12
Output

Concept of a Stack (LIFO) and Applications


Definition
A stack is a linear data structure that follows the Last-In, First-Out (LIFO) principle. This
means that the last element added to the stack is the first one to be removed. It can be visualized
as a physical stack of plates where you can only add or remove the top plate.
Key Operations
• Push: Adds an element to the top of the stack.
• Pop: Removes and returns the top element from the stack.
• Peek (or Top): Returns the top element without removing it from the structure.
Applications
According to Sahni & Horowitz (2005), stacks are essential for:
• Function Calls: Managing active subroutines in computer memory.
• Undo Mechanisms: Tracking history in software like word processors.
• Expression Evaluation: Converting and solving mathematical notations (e.g., Infix to
Postfix).
• Backtracking: Navigating paths in maze-solving or search algorithms.
13
Bibliography
Jasic, J. (2024). Application of stack data structure in application development. Journal of
Applied Science, Information and Computing.
Nidagundi, P. (2025). DIP203/DE0918 - Data Structures and Algorithms Lecture Materials.
Riga Technical University.
Sahni, S., & Horowitz, E. (2005). Fundamentals of data structures. Computer Science Press.

14
Third Task

1. Implement a queue using an array with enqueue, dequeue, and peek operations.

15
Output:

16
2. Implement a queue using a linked list with the same operations.

17
18
Output:

19
Concept of a Queue (FIFO) and Real-Life Use Cases
Definition
A queue is a linear data structure that operates on a First-In, First-Out (FIFO) principle.
This means that the first element added to the queue will be the first one to be removed.
Elements are always added to the back (rear) of the queue and removed from the front.
Key Operations
• Enqueue: Adding an element to the back of the queue.
• Dequeue: Removing an element from the front of the queue.
• Peek: Viewing the front element without removing it.
Real-Life Use Cases
• Physical Lines: Waiting in line at a supermarket or a train station; the first person
in line is served first.
• Printers: When multiple documents are sent to a printer, they are placed in a
queue and printed in the exact order they were received.
• Operating Systems: CPU task scheduling, where processes wait in a queue to be
executed by the processor.
• Call Centers: Customer service systems where incoming callers are placed in a
holding queue until an agent is available.

20
Bibliography
1. Stallings, W. (2014). Operating Systems: Internals and Design Principles. Pearson.
2. Kurose, J. F., & Ross, K. W. (2017). Computer Networking: A Top-Down Approach. Pearson.

Forth Assignment

21
1. Implement a singly linked list with operations: insert at head, insert at
tail, delete a node, and display.

22
23
24
Output:

25
Description of Singly Linked Lists and Advantages
Description
A singly linked list is a linear data structure where elements are not stored in contiguous
memory locations. Instead, each element (called a node) is a separate object. Every node
consists of two core components: the data itself, and a reference (or pointer) linking it to the
next node in the sequence. The list starts with a "head" node, and the very last node points to a
null value, which indicates the end of the list.

Advantages Over Arrays


While arrays are highly useful for direct access, singly linked lists offer several distinct
advantages:
• Dynamic Sizing: Arrays have a fixed memory size that must be declared upfront,
whereas linked lists have a variable size. The amount of memory used by a linked list
can easily fluctuate over time as elements are dynamically allocated when needed.
• Efficient Memory Utilization: Arrays require contiguous blocks of memory, which can
lead to wasted space if the array is not full. In contrast, the memory utilized by a linked
list can be dispersed throughout the system, using available space far more efficiently.
• Insertion and Deletion Operations: Adding or removing an element from an array often
requires shifting all subsequent elements to close the gap or make room. In a linked list,
these operations are significantly faster because they only require updating the reference
pointers of the adjacent nodes, without moving any actual data.

Bibliography
Afteracademy. (2026). Types of Linked List and Operation on Linked List. Retrieved from
[Link]

26
Fifth Task
1. Implement a BST with insert, search, and in-order traversal.

27
28
Output:

29
Concept of a Binary Search Tree (BST) and Applications
Definition
A Binary Search Tree (BST) is a hierarchical, non-linear data structure. It operates as a binary
tree with a strict additional constraint: for any given node, all values in its left subtree are less
than the node's value, and all values in its right subtree are greater than the node's value. This
specific ordering makes operations like searching, insertion, and deletion highly efficient.
Applications in Searching
Because of the left-less, right-greater property, searching for a value in a BST behaves similarly
to a binary search algorithm. Instead of checking every single element sequentially (which takes
O(n) time), the search space is halved at each step down the tree. If the target value is less than
the current node, the algorithm completely ignores the right subtree, resulting in an efficient
average time complexity of O(log n).

Applications in Sorting
BSTs are inherently tied to sorting. When you traverse a BST using the in-order traversal
method (visiting the left child, then the root, then the right child), it naturally processes and
outputs the stored elements in strictly sorted ascending order. This property is the foundation
of the Tree Sort algorithm, where elements are simply inserted into a BST and then extracted
via in-order traversal to achieve a sorted dataset.

30
Bibliography
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms
(3rd ed.). MIT Press.

31
Sixth Task
1. Implement a graph using an adjacency matrix and perform
BFS and DFS.

32
33
Output:

34
2. Implement a graph using an adjacency list and perform BFS
and DFS.

35
36
Output:

37
Concept of Graphs and Their Applications
Definition
A graph is a non-linear data structure consisting of a finite set of vertices (or nodes) and
a set of edges that connect these vertices. Graphs are used to represent complex
networks where elements have arbitrary relationships, rather than sequential or strictly
hierarchical ones.

Directed vs. Undirected Graphs


• Undirected Graph: The edges have no direction. If an edge connects Vertex A and
Vertex B, you can travel in both directions (like a two-way street). The relationship is
mutual.
• Directed Graph (Digraph): The edges have a specific direction, represented by arrows.
An edge from Vertex A to Vertex B means you can go from A to B, but not necessarily
from B to A (like a one-way street).
Real-Life Applications
• Social Networks: Representing users as vertices and friendships as undirected edges
(e.g., Facebook) or follower relationships as directed edges (e.g., Instagram/X).
• GPS and Mapping: Representing cities or intersections as vertices and roads as edges
(with weights for distance or traffic) to find the shortest path.
• Computer Networks: Routing data packets between routers and switches.
• Web Search Engines: The internet is a massive directed graph where web pages are
vertices and hyperlinks are directed edges (used by algorithms like Google's PageRank).

Bibliography
Sedgewick, R., & Wayne, K. (2011). Algorithms (4th ed.). Addison-Wesley Professional.

38
Seventh Task

Implement a hash table in your program:

39
Output:

40
Hash Tables
A hash table is a data structure that maps keys to values for highly efficient data retrieval. It
operates by utilizing an array of buckets or slots where the keys and their corresponding
expected values can be stored and found. When implemented correctly, hash tables provide an
average time complexity of $O(1)$ for search, insert, and delete operations.

Hash Functions
A hash function is the underlying mathematical algorithm used by a hash table. It takes an input
key and converts it into a specific integer index. This index dictates exactly which bucket in the
array the value should be stored in. A good hash function distributes keys uniformly across the
array to minimize instances where multiple keys result in the same index.
41
Collision Handling Techniques
A collision occurs when the hash function generates the exact same index for two different
keys. There are two primary techniques to resolve this:
• Chaining: In this method, each bucket in the hash table acts as a linked list. When a
collision occurs, the new key-value pair is simply appended as a new node to the list at
that specific index.
• Open Addressing: Instead of using lists, this scheme ensures all elements are stored
directly within the array itself. When a collision occurs, the algorithm searches for the
very next available, empty slot in the array. Common methods for finding this next slot
include linear probing, quadratic probing, and double hashing.

Bibliography
1. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms
(3rd ed.). MIT Press.
2. Nidagundi, P. (2025). DIP203/DE0918 - Data Structures and Algorithms Lecture Materials.
Riga Technical University.

Eighth Task
1. Implement an array-based list with basic operations.
42
Output:

43
2. Implement a binary tree with basic operations to illustrate
non-linear data structures.

44
45
Output:

46
Linear vs. Non-Linear Data Structures

Linear Data Structures


In linear data structures, data elements are arranged in a sequentially ordered fashion, with
explicit connections between each element and its immediate predecessor and subsequent
element.
• Access & Traversal: Because the data is sequential, accessing and traversing the
elements is relatively simple and can usually be done using standard loops (like for or
while).
• Memory: Depending on the structure (like an array), memory is often contiguous,
though in structures like linked lists, it may be dispersed.
• Examples: Arrays, Stacks, Queues, and Linked Lists.

Non-Linear Data Structures


Non-linear data structures do not arrange elements sequentially; instead, they create a
hierarchical or interconnected relationship among the data elements.

47
• Access & Traversal: Access to data is arbitrary or hierarchical, which means navigation
requires more complicated traversal algorithms (like Depth-First or Breadth-First
search) rather than simple loops.
• Memory: Memory is dispersed throughout various nodes rather than stored in a single
contiguous block.
• Examples: Trees and Graphs.

Bibliography:
1. Nidagundi, P. (2025). DIP203/DE0918 - Data Structures and Algorithms Lecture Materials.
Riga Technical University.
2. Sahni, S., & Horowitz, E. (2005). Fundamentals of Data Structures. Computer Science
Press.

48
Ninth Task
1. Write a program that uses primitive data types to perform
basic calculations.

Output:

49
2. Write a program using non-primitive data structures like
arrays or lists to store and manipulate multiple values.

50
Output:

51
Primitive vs. Non-Primitive Data Structures

Primitive Data Structures


Primitive data structures are simple structures that are directly controlled by machine
instructions.
• Nature: They consist of the basic, built-in types provided by the programming language,
such as int, float, char, and boolean.
• Memory & Access: They have a fixed memory size depending on the data type. Because
they are basic, they provide faster and more direct access to the data.
• Operations: The operations performed on them are known as atomic operations, which
include basic arithmetic (addition, subtraction) and logical comparisons.

Non-Primitive Data Structures


Non-primitive data structures are more sophisticated structures derived from primitive data
types.
• Nature: They are designed to store large amounts of connected or related data elements.
Examples include Arrays, Lists, Stacks, Queues, Trees, and Graphs.
• Memory & Access: Unlike primitive types, their memory size might fluctuate over time
(variable size) depending on how many elements are stored. Access to the data is often
indirect, possible only through references or pointers.
• Operations: They are capable of carrying out complex, composite operations like
sorting, searching, traversing, and dynamic memory allocation.

Bibliography:
1. Nidagundi, P. (2025). DIP203/DE0918 - Data Structures and Algorithms Lecture Materials.
Riga Technical University.
2. Sahni, S., & Horowitz, E. (2005). Fundamentals of Data Structures. Computer Science
Press.

52
Tenth Task:
1. Write a program to demonstrate an O(n) algorithm (linear
search).

Output:

53
2. Write a program to demonstrate an O(n²) algorithm (bubble
sort).

54
Output:

Concept of Big-O Complexities


Big-O notation is used in computer science to express an algorithm's performance or complexity
in terms of time and space. It provides an upper bound on how the processing time or memory
space requirements grow as the size of the input data increases.
Understanding Big-O is crucial for scalability, optimal resource utilization, and choosing the
right algorithm for a specific task.

55
• O(n) - Linear Time: The running time grows linearly with the input size. If you double
the number of elements, the algorithm takes roughly twice as long. A linear search is
the classic example, as it checks each element one by one.
• O(n^2) - Quadratic Time: The running time grows quadratically with the input size. If
you double the number of elements, the algorithm takes four times as long. Bubble sort
is a standard example of this because it uses nested loops to compare adjacent elements.

Bibliography:
Nidagundi, P. (2025). DIP203/DE0918 - Data Structures and Algorithms Lecture Materials.
Riga Technical University.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms
(3rd ed.). MIT Press.

56
Eleventh Task
1. Implement a problem using an array (e.g., storing student
marks) and explain why it is suitable.

Output:

57
2. Implement the same problem using a linked list and compare
the advantages/disadvantages.

58
Output:

59
Strategies for Selecting the Most Suitable Data Structure
Selecting the correct data structure requires analyzing the specific needs of the software and
weighing trade-offs between time complexity, space complexity, and ease of
implementation.

Key Strategies:
1. Understand the Problem and Operations: * Identify the most frequent operations your
program will perform.
o If random access is required frequently, arrays or hash tables are ideal.
o If the program requires constant insertions and deletions, linked lists or balanced
trees are more efficient.
2. Analyze Performance Requirements (Time Complexity):
o Evaluate the Big-O time complexity for crucial functions. For example, a Hash
Table offers $O(1)$ access time, making it excellent for fast lookups, while a
Binary Search Tree provides $O(\log n)$ but keeps data sorted.
3. Evaluate Memory Constraints (Space Complexity):
o Determine if memory is limited. Arrays have minimal memory overhead,
whereas Linked Lists require extra memory for pointers.
4. Consider Scalability:

60
o Choose structures that can grow with the anticipated data volume. Dynamic
structures (like Linked Lists or dynamic arrays) prevent memory overflow when
dataset sizes are unpredictable.
5. Ease of Implementation:
o Sometimes, the simplest structure that meets the performance requirements is
the best choice to maintain clean, readable, and easily debuggable code.

Bibliography:
1. Nidagundi, P. (2025). DIP203/DE0918 - Data Structures and Algorithms Lecture Materials.
Riga Technical University.
2. Skiena, S. S. (2020). The Algorithm Design Manual (3rd ed.). Springer.

61
Twelfth Task:
The Importance of Learning Data Structures: A Software
Engineering Perspective

Data structures are the absolute foundation of effective algorithms and system designs, making
them essential to programming and computer science. A software application's ability to store,
retrieve, and alter data efficiently is essential to creating reliable and effective software.
Acquiring a deep knowledge of data structures is not merely for passing tests or interviews, but
is essential for establishing a strong basis for a future in technology.

Why Learning Data Structures is Crucial for Programmers?


Mastering these concepts provides programmers with several distinct advantages:
• Effective Data Management: Appropriate data architectures provide effective data
storage, guaranteeing optimal memory usage and making data quickly accessible for
tasks like indexing, sorting, and searching.
• Advanced Problem Solving: Gaining knowledge of data structures improves problem-
solving abilities and promotes thinking in terms of abstract data kinds, which facilitates
the modeling of challenging real-world issues.
• System Scalability: Applications can grow by effectively managing enormous datasets
and handling high transaction volumes when data structures are used properly.
• Improved Code Quality: Code readability and maintainability are dramatically
increased when the appropriate data structure is used, which simplifies logic, increases
modularity, and facilitates debugging.
• Career Advancement: Data structure knowledge is essential for technical interviews,
with employers such as Google, Microsoft, and Amazon placing a strong emphasis on
a candidate's ability to solve data structure issues.

Real-World Applications of Specific Data Structures


Different tasks require different tools, and data structures are utilized across almost all facets
of modern computing:
• Trees: Trees behave like a hierarchical structure to show relationships, heavily used in
file systems, organizational structures, and syntax compiler trees. In web development,
62
they are used to render DOM trees in HTML. Databases also use specific trees, like B-
trees, to manage large amounts of data while preserving speed.
• Graphs: Graphs represent various types of relationships and are foundational for
modeling transportation systems and networks. Modern social networks utilize graphs
extensively to describe user connections.
• Hash Tables: Because they map keys and values to each other for rapid lookups , search
engines rely heavily on hash tables for indexing the internet.
• Queues: Operating systems use these first-in, first-out linear structures for system
software tasks like process scheduling.

The Impact of Proper Choice on Program Efficiency


Algorithms and data structures are tightly related; the effectiveness of an algorithm can be
greatly impacted by the selection of a suitable data structure. If a programmer chooses a linear
structure for a massive database, operations will bottleneck. Conversely, searching algorithms
work significantly better and faster when paired with balanced trees or hash tables.
This directly ties into Big-O complexity, which dictates how well an algorithm will scale.
Understanding these complexities helps programmers select algorithms that make optimal use
of computational resources, ensuring that programs run within acceptable limits of memory and
processing power. Ultimately, determining the best algorithm requires taking into account the
input size and performance constraints specific to the task at hand.

Bibliography
Tutorials Point. (2026). Data Structures and Algorithms. Retrieved from
[Link]
GeeksforGeeks. (2026). Arrays in Java. Retrieved from
[Link]
Groner, L. (2016). Learning JavaScript Data Structures and Algorithms. Packt Publishing
Ltd.

63

You might also like