Advanced Data Structures
DVANCED DATA STRUCTURES WITH C++
SOFTWARE ENGINEERING
HND
(YEAR 2 – FIRST SEMESTER)
DEPARTMENT OF SOFTWARE ENGINEERING
BY
Mr. CONSTANTINE N. MBUFUNG
We learn by doing
Mr. Constantine N. Mbufung Tel: 678659025 Page 1
Advanced Data Structures
Course Overview
A data structures course is a foundational course in computer science that introduces students to
various ways of organizing and sorting data. It covers fundamentals data structures and their
applications in algorithm design and problem-solving. In this course student will learn topics such as
Arrays, linked Lists, Stack and Queues, Trees and Graphs.
Course Objectives:
- Understanding data structures: Gain a deep understanding of various data structures and their
properties
- Algorithm design: Learn to design efficient algorithms using appropriate data structures.
- Problem-solving: develop problem-solving skills by applying data structures to solve real-world
problems
- Performance analysis: Analyze the time and space complexity of algorithms using different data
structures.
Prerequisites
- Programming skills: Proficiency in a programming language (e.g C++, Java, Python) is required to
implement and analyze data structures.
- Basic algorithms: A foundational understanding of algorithms and problem-solving techniques is
helpful
After completing this course, students will be well-prepared to tackle more advanced topics in computer
science and software engineering. Students will develop the skills necessary to design efficient and
scalable algorithms for various applications
TEXTBOOKS
- C++ Data Structures and Algorithms" by Aditya Y. Bhargava
- Data Structures and Algorithms in C++: The Science of Programming" by Adam Drozdek
- Data Structures and Algorithms in C++" by Mark Allen Weiss
REFERENCE BOOKS:
1. Data structures and Algorithms in C++, Michael T.Goodrich, R.Tamassia and .Mount, Wiley
student edition, John Wiley and Sons.
2. Data structures and Algorithm Analysis in C++, Mark Allen Weiss, Pearson Education. Ltd., Second
Edition
Mr. Constantine N. Mbufung Tel: 678659025 Page 2
Advanced Data Structures
COURSE OUTLINE
Weeks Unit Sub topics
1 Introduction to Data Structures What are Data Structures
Characteristics of Data Structure
Applications of Data Structures
Types of Data Structures
Installation of IDE + Compiler
2 Files and Arrays File data structures
Common file data structures
Arrays
Array implementation in C++
3 Linked List Singly Linked list
Doubly Linked List
Circular Linked List
4 Stack and Queue Stack ADT
- Array Implementation
- Linked List Implementation
Queue ADT
- Array Implementation
- Linked List Implementation
Circular Queue
5-6 Searching techniques Linear Search
Binary Search
7-8 Sorting techniques Bubble Sort
Selection Sort
Inserting Sort
Quick Sort
Merge Sort
9 - 10 Graphs and Trees Graphs:
- Basic terminology
- Representation of graphs
- Graph traversal methods
Binary Search Trees:
- Basics
- Binary tree traversals
- Binary Search Tree
- AVL Trees
- B-Trees
- B+ Tre
11 Hash Tables Hash Table Representation
Rehashing
Mr. Constantine N. Mbufung Tel: 678659025 Page 3
Advanced Data Structures
Introduction:
Data Structures are fundamental building blocks in computer science that organize and store data in a
way that enables efficient access and manipulation. They provide a framework for representing
information and relationships between elements.
Data Structure: A data structure is a specialized format for organizing and storing data. General data
structure types include the array, the file, record, table, tree, and so on. Any data structure is designed
to organize data to suit a specific purpose so that it can be accessed and worked with in appropriate
ways.
Abstract Data Type:
In computer science, an abstract data type (ADT) is a mathematical model that defines a set of
operations that can be performed on a data type without specifying the underlying implementation
details.
Key Characteristics of ADTs:
- Specification: an ADT defines the operations that can be performed on the data type, but not
how they are implemented.
- Implementation-independent: The implementation of an ADT can vary, as long as it adheres to
the specified interfaces
- Abstraction: ADTs provide a level of abstraction, hiding the underlying details of the data
structure.
- Modularity: ADTs can be used as building blocks to create more complex data structures.
Examples of ADTs:
Stack: A LIFO (Last-In-First-Out) data structure with operations like push (add an element) and
pop (remove an element).
Queue: A FIFO (First-In-First-Out) data structure with operations like enqueue (add an element)
and dequeue (remove an element).
List: A linear data structure with operations like insert, delete, search, and traversal.
Tree: A hierarchical data structure with a root node and branches.
Graph: A non-linear data structure representing connections between nodes.
By using ADTs, programmers can focus on the behavior of the data type rather than its implementation
details, leading to more modular, reusable, and maintainable code.
Mr. Constantine N. Mbufung Tel: 678659025 Page 4
Advanced Data Structures
Data Structures
Built-in Data Structures User Defined Data Structures
Integer Float Character Pointer
Lists Arrays Files
Linear Lists Non-Linear Lists
Stacks Queues Trees Graphs
FILE DATA STRUCTURES
File Data Structures are specific ways to organize and store data within a file on a computer system.
They define the arrangement and relationships between data elements, allowing for efficient access,
manipulation, and storage.
Common File Data Structures:
1. Text Files:
o Structure: Data is stored as a sequence of characters, often separated by delimiters (e.g.,
spaces, commas, tabs).
o Applications: Storing plain text documents, configuration files, log files.
o Advantages: Simple to create and read, human-readable.
o Disadvantages: Less efficient for large datasets, limited data types.
2. Binary Files:
o Structure: Data is stored in binary format, directly representing the underlying data types.
o Applications: Storing images, audio, video, and other complex data.
o Advantages: Efficient storage and retrieval, can support a wider range of data types.
o Disadvantages: Not human-readable, requires specific software to interpret.
3. Database Files:
o Structure: Organized into tables, rows, and columns, using a relational database model.
o Applications: Storing structured data, such as customer information, inventory, and
financial records.
Mr. Constantine N. Mbufung Tel: 678659025 Page 5
Advanced Data Structures
o Advantages: Efficient data management, powerful query capabilities, data integrity.
o Disadvantages: Can be complex to set up and manage.
4. Hierarchical Files:
o Structure: Organized in a tree-like structure, with parent-child relationships.
o Applications: Storing hierarchical data, such as directory structures or XML files.
o Advantages: Efficient for hierarchical data, easy to navigate.
o Disadvantages: Can be less flexible for complex relationships.
5. Network Files:
o Structure: Represents connections between nodes (data elements).
o Applications: Storing graph-based data, such as social networks or geographical maps.
o Advantages: Efficient for representing relationships between data elements.
o Disadvantages: Can be complex to manage for large datasets.
Array Data Structure
An array is a collection of elements of the same data type, stored in contiguous memory locations. It
provides a way to organize and access multiple values under a single name.
Key Properties of arrays:
- Elements: The individual values stored in an array
- Index: An integer value used to access a specific element in an array Indexing of an array start
from 0.
- Size: the total number of elements in an array. Once an array is declared nits size remains
constant throughout the program
- Type: the data type of the elements stored in the array
Types of arrays:
- One-dimensional arrays: These arrays store a single row of elements
- Multidimensional arrays: These arrays store multiple row of elements
Need of Array Data Structures
Arrays are a fundamental data structure in computer science. They are used in a wide variety of
applications including:
Mr. Constantine N. Mbufung Tel: 678659025 Page 6
Advanced Data Structures
- Storing collections of related data for processing e.g an array of student grades or a list of
product prices.
- Implementing Algorithms: many algorithms, such as sorting and searching algorithms, use arrays
as a fundamental data structure.
- Representing data in tables and matrices
- Creating dynamic data structures: Arrays can be used as building blocks for more complex such
as linked lists, stacks and trees
Array Operations
Common operations performed on arrays include:
- Traversal: Visiting each element of an array in a specific order (e.g Sequential, reverse)
- Insertion: Adding a new element to an array at a specific index
- Deletion: Removing an element from an array at a specific index.
- Searching: Finding the index of an element in an array
Array Declaration in C++
In C++, we can declare an array by simply specifying the data type first and then the name of an array
with its size.
data_type array_name[Size_of_array];
Example
int arr[5];
- int: It is the type of data to be stored in the array. We can also use other data types such as
char, float, and double.
- arr: It is the name of the array.
- 5: It is the size of the array which means only 5 elements can be stored in the array.
Mr. Constantine N. Mbufung Tel: 678659025 Page 7
Advanced Data Structures
Initialization of Array in C++
We can initialize an array in many ways in C++.
1. Initialize Array with values in C++
Syntax:
DataType ArrayName[Size] = Values
e.g
int arr[5] = {1, 2, 3, 4, 5}
The values enclosed in curly braces ‘{}’ are assigned to the array
2. Initialize Array with values and without size in C++
e.g int arr[] = {1, 2, 3, 4, 5}
we have initialize the array with values but we have not declared the length of the array,
therefore, the length of an array is equal to the number of element inside the curly braces.
3. Initialize Array after Declaration (Using Loops)
e.g
for (int i = 0; i < N; i++) {
arr[i] = value;
}
We have initialized the array using a loop after declaring the array. This method is used when we
want to take input from the user or we want to assign elements one by one to each index of the
array.
4. Initialize an array partially in C++
int partialArray[5] = {1, 2}
we have declared an array with size 5 and values 1 and 2 are stored at inex 0 and 1 respectively
while the rest of the indices ,0 is stored
5. Initialize the array with zero in C++
int zero_arr[5] = { 0}
6. Using Pointers: e.g char *myArray[] = {"Hello", "world", "!"};
Accessing an element of an Array in C++
Elements of an array can be accessed by specifying the name of the array, then the index of the
element enclosed in the array subscript operator []. For example, arr[i].
Mr. Constantine N. Mbufung Tel: 678659025 Page 8
Advanced Data Structures
Updating Array Elements
To update an element in an array, we can use the index which we want to update enclosed within the
array subscript operator and assign the new value.
arr[i] = new_value
Traverse an Array in C++
Size of an Array in C++
In C++, we do not have the length function like in python or Java but we can calculate the size of an array using
sizeof() operator. We find the size occupied by the whole array in the memory and then divide it by the size of the
type of element stored in the array.
Mr. Constantine N. Mbufung Tel: 678659025 Page 9
Advanced Data Structures
dataType size = sizeof(arrayName) / sizeof(arrayName[index])
Multidimensional Arrays in C++
Arrays declared with more than one dimension are called multidimensional arrays. They are represented
using rows and columns. Each element is accessed using two indices
DataType ArrayName[size1][size2]….[sizeN];
Syntax for 2D array
dataType arrayName[n][m]
where, n is the Number of rows and m is the number of columns
C++ program to illustrate 2D array implementation
Mr. Constantine N. Mbufung Tel: 678659025 Page 10
Advanced Data Structures
3D Arrays
Examples: int array[3][3][3];
Mr. Constantine N. Mbufung Tel: 678659025 Page 11
Advanced Data Structures
Associative Arrays in C++ will be treated under Map/Dictionaries
Mr. Constantine N. Mbufung Tel: 678659025 Page 12