DATA STRUCTURES BY SHALIGRAM
DATA STRUCTURES BY SHALIGRAM
Data Raw facts, observations or symbols without interpretation
Representation Technique: Numbers, characters, text, images, audio, video, binary values
Ex: 25, Student, 85
Identifies individual values, tokens and symbols
Information Processed or organized data that has meaning in a particular context
Representation Technique:Tables, records, graphs, reports, databases, JSON/XML
Ex: Student scored 85 marks
Establishes relationships and context among data elements
Knowledge Information combined with rules, experience, relationships and interpretation
Representation Technique:Knowledge graphs, ontologies, rules, semantic networks, concept maps
Ex: 85 marks indicates good academic performance
Identifies concepts, relationships, entities and rules
Wisdom Application of knowledge and experience to make appropriate decisions
Representation Technique:Decision models, recommendations, policies, expert systems
Ex: The student should be encouraged to participate in advanced courses
DATA
↓
( Processing + Context )
↓
INFORMATION
↓
(Interpretation + Relationships + Rules )
↓
KNOWLEDGE
↓
(Experience + Reasoning + Decision Making )
↓
WISDOM
Data Processing: Data processing converts raw facts into an organized or usable form.
Typical operations:
Data collection
Data entry
Data validation
Data cleaning
Sorting
Searching
Classification
Filtering
Calculation
Aggregation
Storage
Example:
Raw Data: 45, 67, 89, 72, 55
↓ Data Processing
Sorted Data: 45, 55, 67, 72, 89
Average: 65.6
Information Processing : Information processing gives context and meaning to processed data.
Typical operations:
Summarization
Comparison
Correlation
Interpretation
Categorization
Visualization
Report generation
Pattern identification
Example:
Average Student Marks = 65.6 , Class Average = 58
↓ Information Processing
Student performance is above the class average.
Knowledge Processing : Knowledge processing uses information together with rules, relationships, concepts and reasoning to derive new knowledge or make decisions.
Typical operations:
Knowledge representation
Semantic analysis
Rule application
Logical reasoning
Inference
Classification
Prediction
Recommendation
Decision-making
Knowledge discovery
Example:
Information:Student average = 65.6. and Class average = 58
+
Knowledge Rule:
IF student performance > class average
THEN performance = "Above Average"
↓ Knowledge Processing
Inference:
Student performance = Above Average
RAW DATA
↓
DATA PROCESSING
↓
PROCESSED DATA
↓
INFORMATION PROCESSING
↓
MEANINGFUL INFORMATION
↓
KNOWLEDGE PROCESSING
↓
KNOWLEDGE + INFERENCE
↓
(DECISION / RECOMMENDATION)
In Semantic Analysis : This distinction is particularly important in Natural Language Processing (NLP):
Data Processing→ text cleaning, tokenization, normalization, stemming
Information Processing→ extracting entities, keywords, relationships and facts
Knowledge Processing→ understanding meaning, semantic relationships, reasoning, inference and answering questions
For example:
"Ravi scored 85 marks in Data Structures."
Data: Ravi, 85, Data Structures
Information: Ravi scored 85 marks in Data Structures.
Knowledge: Ravi has demonstrated strong performance in Data Structures, assuming an appropriate performance rule or benchmark.
Inference: Ravi may be suitable for an advanced Data Structures activity.
A data type defines the kind of value that a variable can store, the amount of memory required to store it, the range of possible values, and the operations that can be performed on it
Primitive data types are the basic built-in types provided by a programming language.
char
Character / small integer
1 byte
−128 to 127 or 0 to 255
'A'
Characters, symbols, text
int
Integer
4 bytes
−2,147,483,648 to 2,147,483,647
100
Counting, indexing, IDs
short
Small integer
2 bytes
−32,768 to 32,767
250
Memory-efficient integers
long
Large integer
4/8 bytes
Implementation-dependent
100000L
Large integer values
float
Decimal / real number
4 bytes
Approx. ±3.4 × 10³⁸
3.14f
Scientific calculations
double
High-precision decimal
8 bytes
Approx. ±1.7 × 10³⁰⁸
3.14159
High-precision calculations
_
Bool
Logical value
Implementation-dependent
0 or 1
1
True/false conditions
void
No value
—
No value
void Functions with no return value
*Sizes and exact ranges can vary by C implementation. The ranges above are common for modern systems.
C provides modifiers that change the size or range of integer types:
signed
unsigned
short
long
Examples:
unsigned int age;
short int marks;
long int population;
unsigned char code;
For example, a typical unsigned int has a range:
0 to 4,294,967,295
Non-primitive data types are constructed from primitive types and are generally used to represent collections or complex structures of data.
Array -Collection of elements of the same data type
int marks[10];
Storing multiple values
Structure-Collection of different data types under one name
struct Student
Records/entities
Union-Different members share the same memory location
union Data
Memory-efficient representation
Pointer-Stores the address of another variable
int *p;
Dynamic memory, linked structures
String-Sequence of characters terminated by '\0'
char name[20];
Text processing
C also supports:
struct
union
enum
typedef
Example:
struct Student {
int rollNo;
char name[50];
float marks;
};
Here, Student represents a complex data entity containing different kinds of values.
In semantic analysis, data types help determine whether values and operations are meaningful and valid.
For example:
int age = 20;
float marks = 85.5;
char grade = 'A';
The semantic analyzer determines:
age → integer
marks → floating-point value
grade → character
Whether assignments are type-compatible
Whether operators are applicable
Whether function arguments match parameter types
Whether expressions produce valid results
Example:
int x;
float y;
x = y;
The semantic analysis phase checks the type compatibility between x and y.
Thus, data types provide the semantic meaning and constraints of values, making them fundamental to type checking, expression evaluation, symbol-table construction, and semantic analysis.
A Stack is a linear data structure in which elements are inserted and deleted from one end only, called the TOP. It follows the LIFO (Last In, First Out) principle.
Example: Stack of plates.
Possible Operations:
Push: Insert an element onto the TOP of the stack.
Pop: Remove an element from the TOP of the stack.
Peek/Top: View the TOP element without removing it.
isEmpty: Check whether the stack is empty.
isFull: Check whether the stack is full in an array-based implementation.
Size: Find the number of elements in the stack.
Display/Traverse: View all elements of the stack.
Search: Find a specified element in the stack.
Clear: Remove all elements from the stack.
#define MAX 100
typedef struct {
int data[MAX];
int top;
} Stack;
void push(Stack *s, int value);
int pop(Stack *s);
int peek(const Stack *s);
int isEmpty(const Stack *s);
int isFull(const Stack *s);
void display(const Stack *s);
A Queue is a linear data structure in which elements are inserted at the REAR and deleted from the FRONT. It follows the FIFO (First In, First Out) principle.
Example: People standing in a ticket queue.
Possible Operations:
Enqueue: Insert an element at the REAR of the queue.
Dequeue: Remove an element from the FRONT of the queue.
Front/Peek: View the first element without removing it.
Rear: View the last element in the queue.
isEmpty: Check whether the queue is empty.
isFull: Check whether the queue is full in an array-based implementation.
Size: Find the number of elements in the queue.
Display/Traverse: View all elements of the queue.
Search: Find a specified element.
Clear: Remove all elements from the queue.
#define MAX 100
typedef struct {
int data[MAX];
int front;
int rear;
} Queue;
void enqueue(Queue *q, int value);
int dequeue(Queue *q);
int frontElement(const Queue *q);
int rearElement(const Queue *q);
int isEmptyQueue(const Queue *q);
int isFullQueue(const Queue *q);
void displayQueue(const Queue *q);
void initCircularQueue(Queue *q);
void enqueueCircular(Queue *q, int value);
int dequeueCircular(Queue *q);
int frontCircular(const Queue *q);
int rearCircular(const Queue *q);
int isEmptyCircular(const Queue *q);
int isFullCircular(const Queue *q);
void displayCircular(const Queue *q);
Priority Queue
A Priority Queue is a queue in which each element is associated with a priority, and elements are processed according to priority.
typedef struct {
PriorityElement data[MAX];
int size;
} PriorityQueue;
void initPriorityQueue(PriorityQueue *pq);
void insertPriority(PriorityQueue *pq, int value, int priority);
int deletePriority(PriorityQueue *pq);
int peekPriority(const PriorityQueue *pq);
int isEmptyPriority(const PriorityQueue *pq);
int isFullPriority(const PriorityQueue *pq);
void displayPriority(const PriorityQueue *pq);
void initDeque(Queue *dq);
void insertFront(Queue *dq, int value);
void insertRear(Queue *dq, int value);
int deleteFront(Queue *dq);
int deleteRear(Queue *dq);
int getFront(const Queue *dq);
int getRear(const Queue *dq);
int isEmptyDeque(const Queue *dq);
int isFullDeque(const Queue *dq);
void displayDeque(const Queue *dq);
A Sparse Matrix is a matrix in which most elements are zero and only a small number of elements are non-zero. Special representations are used to save memory and processing time.
Example:
0 0 5
0 0 0
7 0 0
can be represented as
Row Column Value
0 2 5
2 0 7
A complete triplet representation generally also stores the matrix dimensions and number of non-zero elements.
#define MAX_TERMS 100
typedef struct {
int row;
int col;
int value;
} Term;
typedef struct {
int rows;
int cols;
int terms;
Term data[MAX_TERMS];
} SparseMatrix;
Possible Operations:
Create: Create and store a sparse matrix.
Represent: Represent the matrix using triplet, tuple, or other compact forms.
Insert: Add a non-zero element at a specified position.
Delete: Remove a non-zero element or make an element zero.
Update: Modify the value of an existing element.
Access/Search: Find the value at a specified row and column.
Display: Display the sparse matrix in normal or compact form.
Transpose: Convert rows into columns and columns into rows.
Fast Transpose: Perform an efficient transpose using compact representation.
Addition: Add two sparse matrices.
Subtraction: Subtract one sparse matrix from another.
Multiplication: Multiply sparse matrices where dimensions are compatible.
Count Non-Zero Elements: Determine the number of non-zero elements.
Convert Representation: Convert between normal matrix and sparse/compact representation.
Operation
Initialize void initSparse(SparseMatrix *s);
Create void createSparse(SparseMatrix *s);
Insert void insertSparse(SparseMatrix *s, int row, int col, int value);
Delete void deleteSparse(SparseMatrix *s, int row, int col);
Update void updateSparse(SparseMatrix *s, int row, int col, int value);
Search int searchSparse(const SparseMatrix *s, int row, int col);
Access int getSparse(const SparseMatrix *s, int row, int col);
Display void displaySparse(const SparseMatrix *s);
Transpose void transposeSparse(const SparseMatrix *s, SparseMatrix *t);
Fast Transpose void fastTranspose(const SparseMatrix *s, SparseMatrix *t);
Addition int addSparse(const SparseMatrix *a, const SparseMatrix *b, SparseMatrix *c);
Subtraction int subtractSparse(const SparseMatrix *a, const SparseMatrix *b, SparseMatrix *c);
Multiplication int multiplySparse(const SparseMatrix *a, const SparseMatrix *b, SparseMatrix *c);
Count Non-Zero int countNonZero(const SparseMatrix *s);
Clear void clearSparse(SparseMatrix *s);
A List is a linear data structure in which elements are arranged in a sequential order. Lists may be implemented using arrays or linked nodes.
Example:
10 → 20 → 30 → 40
General List Operations:
Create: Create a new list.
Insert: Add an element at the beginning, end, or a specified position.
Delete: Remove an element from the beginning, end, or a specified position.
Traverse: Visit and process all elements.
Search: Find a specified element.
Access/Retrieve: Obtain an element at a specified position.
Update/Replace: Modify an existing element.
Size/Length: Find the number of elements.
isEmpty: Check whether the list is empty.
Sort: Arrange elements in ascending or descending order.
Reverse: Reverse the order of elements.
Merge: Combine two lists.
Concatenate: Join one list after another.
Clear: Remove all elements from the list.
Copy: Create a duplicate of a list.
An Array List stores list elements in contiguous memory locations.
Operations:
Create
Insert
Delete
Search
Traverse
Access by index
Update
Sort
Reverse
Merge
Concatenate
Find size
An Unordered List is a list in which elements are not arranged according to any specific order or sorting criterion. Elements can be stored in the order in which they are inserted.
Example:
30 → 10 → 40 → 20
Possible Operations:
Insert at beginning
Insert at end
Insert at a specified position
Delete an element
Search for an element
Traverse the list
Access an element
Update an element
Find size
Reverse the list
Sort the list when required
Merge or concatenate lists
Clear the list
An Ordered List is a list in which elements are maintained in a specific order, usually ascending or descending according to their values or a defined key.
Example:
10 → 20 → 30 → 40
Possible Operations:
Ordered Insert: Insert an element at its correct sorted position.
Delete: Remove an element while maintaining the order.
Search: Search for an element; efficient searching may be possible depending on implementation.
Traverse: Visit elements in their sorted order.
Access: Retrieve an element at a specified position.
Update: Modify an element and restore the required order if necessary.
Find Minimum: Retrieve the smallest element.
Find Maximum: Retrieve the largest element.
Find Size: Determine the number of elements.
Merge: Combine two ordered lists while maintaining the order.
Clear: Remove all elements.
Important: In an Ordered List, every insertion, deletion, or update should preserve the defined ordering criterion.
void initList(ArrayList *list);
int isEmptyList(const ArrayList *list);
int isFullList(const ArrayList *list);
int listSize(const ArrayList *list);
void insertBeginning(ArrayList *list, int value);
void insertEnd(ArrayList *list, int value);
void insertAtPosition(ArrayList *list, int position, int value);
int deleteBeginning(ArrayList *list);
int deleteEnd(ArrayList *list);
int deleteAtPosition(ArrayList *list, int position);
int searchList(const ArrayList *list, int key);
int getElement(const ArrayList *list, int position);
void updateElement(ArrayList *list, int position, int value);
void displayList(const ArrayList *list);
void reverseList(ArrayList *list);
void sortList(ArrayList *list);
void clearList(ArrayList *list);
An Unordered List contains elements that are not maintained according to any particular sorting order.
Example:
30 → 10 → 40 → 20
void insertUnordered(ArrayList *list, int value);
int deleteUnordered(ArrayList *list, int value);
int searchUnordered(const ArrayList *list, int key);
void updateUnordered(ArrayList *list, int position,int value);
void displayUnordered(const ArrayList *list);
void reverseUnordered(ArrayList *list);
void sortUnordered(ArrayList *list);
void mergeUnordered(const ArrayList *a, const ArrayList *b, ArrayList *result);
int listSize(const ArrayList *list);
void clearUnordered(ArrayList *list);
An Ordered List maintains its elements according to a specified order, generally ascending or descending.
Example: 10 → 20 → 30 → 40
void insertOrdered(ArrayList *list, int value);
int deleteOrdered(ArrayList *list, int value);
int searchOrdered(const ArrayList *list, int key);
void updateOrdered(ArrayList *list,int position, int value);
int findMinimum(const ArrayList *list);
int findMaximum(const ArrayList *list);
void displayOrdered(const ArrayList *list);
void mergeOrdered(const ArrayList *a, const ArrayList *b, ArrayList *result);
void clearOrdered(ArrayList *list);
Unlike an unordered list: insertOrdered(&list, 25);
The function automatically determines the appropriate position so that the list remains ordered.