CSE 2001 - Data Structures and Algorithms
CSE 2001 - Data Structures and Algorithms
and Algorithms
Introduction to Data Structures
&
Arrays
Contents
1. Introduction to Data Structures
2. Types and Concepts of Arrays
3. Stack
3.1 Concepts and Representation
3.2 Stack operations
3.3 Stack implementation using array
3.4 Applications of Stack.
2
Contents
4. Queues Representation of queue
4.1 Queue Operations
4.2 Queue implementation using array
4.3 Types of Queue
4.4 Applications of Queue
3
1. Introduction to Data Structures
Definition
• A data structure is a specific way of storing and organizing data in
a computer so that it can be used efficiently.
Example Data Structures: Arrays, Linked Lists, Stacks, Queues,
Trees, Graphs.
Purpose
• Data structures are used to efficiently manage large amounts of
data for various operations such as traversal, insertion, deletion,
and searching.
4
Introduction to Data Structures- Types
5
Introduction to Primitive Data Structures
Primitive data structures
• Most basic data types that serve as the building blocks for more complex data
structures.
• They are directly supported by the underlying hardware of a computer and are
used to represent simple values.
Characteristics
• Fixed Size: They generally occupy a fixed amount of memory.
• Direct Access: They allow direct manipulation by the processor.
• Low-Level Operations: Operations on primitive data types are usually very fast.
6
Introduction to Primitive Data Structures
Examples:
Integer: int
Float: float
Character: char
Boolean: boolean
7
Non-Primitive Data Structures
• Non-primitive data structures are more complex data types that are derived from primitive
data structures.
• They allow for the organization and management of data in a more sophisticated way
• Making it easier to handle large amounts of data and perform operations efficiently
Characteristics
Dynamic Size: Many non-primitive data structures, like linked lists and trees, can grow or
shrink in size dynamically.
Efficient Memory Usage: Non-primitive data structures can be more memory-efficient than
primitive arrays, especially for dynamic operations.
Complex Operations: They support more complex operations like sorting, searching, and
hierarchical data organization.
8
Linear Data Structures
Name Description Types Key Operations
Arrays A collection of elements, all of the same Access, Insertion,
type, stored in contiguous memory Deletion, Traversal.
locations.
Linked A linear collection of elements called Singly Linked List, Insertion, Deletion,
Lists nodes, where each node points to the Doubly Linked List, Traversal
next node in the sequence. Circular Linked List
Stacks A linear data structure that follows the Push (Insert), Pop
Last In, First Out (LIFO) principle. (Delete), Peek (Access
top element)
Queues A linear data structure that follows the Simple Queue, Circular Enqueue (Insert),
First In, First Out (FIFO) principle Queue, Priority Queue, Dequeue (Delete), Front
Deque (Access front element).
9
Non-Linear Data Structures
Name Description Types Key Operations
Trees A hierarchical data structure consisting Binary Tree, Binary Insertion, Deletion,
of nodes connected by edges, with a Search Tree, AVL Tree, Traversal (Inorder,
single node as the root. Heap Preorder, Postorder)
Graphs A collection of nodes (vertices) Directed Graph, Traversal (BFS, DFS),
connected by edges, used to represent Undirected Graph, Shortest Path,
relationships between pairs of objects. Weighted Graph. Connectivity.
10
Abstract Data Types (ADTs)
Definition
An Abstract Data Type (ADT) is a model for data types where a data type is defined by its
behavior (semantics) from the point of view of a user, particularly in terms of possible values,
possible operations on data of this type, and the behavior of these operations.
Components
Declaration of Data: The types of data that can be stored in the ADT (e.g., integers, floats,
characters).
Declaration of Operations: The operations that can be performed on the data (e.g., insertion,
deletion, search, etc.).
11
Arrays
• is a data structure consisting of a collection of elements, each
identified by at least one array index or key.
• used to store multiple values in a single variable instead of
declaring separate variables for each value.
12
Arrays -Characteristics
SL Characteristics Description
1 Fixed Size Arrays have a fixed size, meaning the number of elements must be known at
the time of creation.
2 Homogeneous Elements All elements in an array are of the same data type.
3 Indexed Access Elements can be accessed using an index, starting from 0
4 Contiguous Memory Array elements are stored in contiguous memory locations
13
Arrays- Operations
SL Operations Descriptions
1 Access Retrieve an element using its index
2 Insertion Add an element at a specific index (shifting elements if necessary).
3 Deletion Remove an element from a specific index (shifting elements to fill the gap).
4 Update Modify the value of an element at a specific index.
5 Traversal Visit each element sequentially
14
import java.util.Arrays;
class HelloWorld {
public static void main( String args[] ) {
// Retrieve an item from an array
int myArray[] = new int[]{1,2,3};
System.out.println(myArray[0]); // Outputs 1
// clearing an array
myArray = null;
System.out.println(Arrays.toString(myArray)); // Outputs null
}
}
15