0% found this document useful (0 votes)
3 views12 pages

Data Structure & Algorithm

The document is a lecture note on Data Structures and Algorithms, covering fundamental concepts such as data structures, data attributes, data types, and basic units of data. It explains linear and non-linear data structures, as well as sets and set operations, providing definitions, examples, and practical activities for better understanding. The content is structured into chapters with learning outcomes and assignments to reinforce the material.
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)
3 views12 pages

Data Structure & Algorithm

The document is a lecture note on Data Structures and Algorithms, covering fundamental concepts such as data structures, data attributes, data types, and basic units of data. It explains linear and non-linear data structures, as well as sets and set operations, providing definitions, examples, and practical activities for better understanding. The content is structured into chapters with learning outcomes and assignments to reinforce the material.
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

Mai Idris Alooma Polytechnic Geidam

PMB 1002 Geidam Yobe State

Lecture Note on

COM124: DATA STRUCTURES & ALGORITHM

Prepared by J.A Alanjiro

Computer Science Department , Mai Idris Alooma

Polytechnic Geidam
Chapter One

Introduction to Data Structures and Tools

General Objective

To understand the basic concepts of data structure and its associated tools.

Learning Outcomes

By the end of this lesson, You should be able to:

1.​ Define what a data structure is


2.​ Identify and describe data attributes (name, value, range, data types)
3.​ Understand basic data units (character, field, subfield, record, file)​

Data Structure:

Data structures are the fundamental building blocks of computer


programming. They define how data is organized, stored, and manipulated
within a program. Understanding data structures is very important for
developing efficient and effective algorithms.

What is Data Structure?

A data structure is a storage that is used to store and organize data. It is a


way of arranging data on a computer so that it can be accessed and updated
efficiently.

A data structure is not only used for organizing the data. It is also used for
processing, retrieving, and storing data. There are different basic and
advanced types of data structures that are used in almost every program or
software system that has been developed.
1.​ Linear Data Structure: Data structure in which data elements are
arranged sequentially or linearly, where each element is attached to
its previous and next adjacent elements, is called a linear data
structure. Example: Array, Stack, Queue, Linked List, etc.
2.​ Non-Linear Data Structure: Data structures where data elements
are not placed sequentially or linearly are called non-linear data
structures. In a non-linear data structure, we can’t traverse all the
elements in a single run only. Examples: Trees and Graphs.
3.​ Static Data Structure: Static data structure has a fixed memory size.
It is easier to access the elements in a static data structure.
Example: array.
4.​ Dynamic Data Structure: In dynamic data structure, the size is not
fixed. It can be randomly updated during the runtime which may be
considered efficient concerning the memory (space) complexity of
the code. Example: Queue, Stack, etc.

Data Attributes

Data attributes are the properties that describe a data element.

➢​ Name: The identifier for a piece of data (e.g., "age")


➢​ Value: The actual content or information ("25")
➢​ Range: The possible values the attribute can have (e.g., 1–120 for age)

Int Age = 20 ; // Declare a Memory location Named Age and Assigned it a Value of 20.
Data Type:

A data type refers to the type of value a variable has and what type of
operations can be applied on it without causing an error.

In any programming language, the data type defines which operations can
safely be performed to create, transform and use the variable in another
computation. Specifically, every piece of data has a type that tells the machine
how to interpret its value.

The kind of value stored

●​ Integer (e.g., 10)


●​ Float (e.g., 3.14)
●​ String (e.g., "Yobe")
●​ Boolean (e.g., true/false)

Example:​
A student record might look like:​
Name: "Amina", Age: 23, Grade: 4.2​
Each of these is a data attribute with specific types.

Basic Units of Data


The basic units of data describe how data is structured from smallest to
largest. These units are used in databases, data structures, and file systems.

Unit Description Example

Smallest unit a single letter,


Character 'A', '5', '#'
digit, or symbol
A single piece of data (made
Field "Name", "Age"
of characters)
A logical part of a field (used
Subfield in complex data like "First Name", "Last Name"
addresses or names)

A complete set of related


Record Name: Amina, Age: 23
fields representing one entity

A collection of related
File List of all students
records
A structured collection of
Database files organized for easy School database system
access
Example: In A phonebook (Contact List):

●​ Each name (record) contains a name (field), number (field), and


email (field)
●​ Multiple records make up the phonebook (file)

Practical Activity

Objective: Illustrate how fields, records, and files work using a classroom
attendance register.

Name Matric No Attendance

Amina Yusuf COM12401 Present

Musa Bello COM12402 Absent

Each row = Record​


Each column = Field​
The entire table = File​
Software: Excel , MS Access.

Assignment 1:

1.​ Why is it important to specify data types when writing programs?


2.​ Match the following types of data structures to their correct
descriptions in a Table Below:

a) Linear Data Structure 1.​ Elements are arranged in sequence, and each
one is connected to the next.

b) Non-linear Data 2.​ The size can grow or shrink during the
Structure execution of a program.

c) Static Data Structure 3.​ Elements are connected in a way that doesn't
follow a linear pattern, like branches.

​ 4.​ The size is fixed and defined before runtime


d) Dynamic Data
Structure

3. Explain in your own words what a data structure is. Why is it important in
computer programming?
Chapter Two:

General Objective

To understand the basic concepts of Graphs, Symbols and Relation.

Learning Outcomes

By the end of this lesson, You should be able to:

●​ Define symbols used in data structures.


●​ Explain how symbols represent relationships among data elements.
●​ Identify and interpret common relational symbols
●​ Describe the concept of relations in data structures.
●​ Define a graph and its components (vertices and edges).
●​ Differentiate between directed and undirected graphs.
●​ Describe key graph properties: routes, edges, and sequences.
●​ Apply graph concepts to real-world examples like city maps or
student-course systems.

Symbols

Symbols are characters or signs used to represent operations or relationships


between data items in data structures.

Examples:

●​ → (points to)​

●​ = (equal to)​

●​ ≠ (not equal to)​

●​ <, > (less than, greater than)​

Relations

Relations describe how data elements are connected or associated with one
another.

Example: In a student-course system:

●​ One student can register for many courses (one-to-many


relation).​

●​ Two students in the same class are related through their class
ID.​
Symbol Meaning Example

→ Points to (directional Course → Student


link)

= Equal to x=y

< Less than Age < 18

≠ Not equal Score ≠ 0

Graph

Graph is a non-linear data structure consisting of vertices and edges. The


vertices are sometimes also referred to as nodes and the edges are lines or
arcs that connect any two nodes in the graph. More formally a Graph is
composed of a set of vertices( V ) and a set of edges( E ). The graph is denoted
by G(V, E).

Graphs are widely used to represent networks, such as roads between cities,
computer networks, or social media connections.
Components of Graph Data Structure

1.​ Vertices: Vertices are the fundamental units of the graph. Sometimes,
vertices are also known as vertex or nodes. Every node/vertex can be
labeled or unlabelled.
2.​ Edges: Edges are drawn or used to connect two nodes of the graph. It
can be ordered pair of nodes in a directed graph. Edges can connect
any two nodes in any possible way.
3.​ Undirected Graph: A graph in which edges do not have any direction.
That is the nodes are unordered pairs in the definition of every edge.
4.​ Directed Graph: A graph in which edge has direction. That is the nodes
are ordered pairs in the definition of every edge.
Property Explanation

Routes Paths or sequences of connections between nodes

Edges The actual connection/link between two nodes

Sequence The order in which nodes or elements are arranged


or accessed

Directed Graph A graph where edges have direction (e.g., A → B,


one-way)

Undirected A graph where edges don’t have direction (e.g., A — B,


Graph two-way relationship)

Example:

City Road Network

●​ Each city = node


●​ Road = edge
●​ A one-way road from City A to B = directed edge
●​ A two-way road between A and B = undirected edge
●​ Travel routes = sequences of nodes

Assignment 2:

Draw a simple graph with 4 cities: Maiduguri, Geidam, Potiskum, Damaturu.


Use arrows to show travel routes (e.g., one-way vs. two-way roads). Identify
edges and nodes. Label which are directed.
Chapter Three 3:

Sets and Set Operations

General Objective

Understand the concept of sets, subsets, super sets, and operations on sets.

Learning Outcomes

By the end of this lesson, students should be able to:

1.​ Define sets


2.​ Describe elements of sets
3.​ Explain subsets, super sets, universal sets, and null sets
4.​ Perform set operations

Definitions

1.​ Set: A collection of distinct elements (e.g., A = {1, 2, 3})

There can be any number of items, be it a collection of whole numbers,

months of a year, types of birds, and so on. Each item in the set is known

as an element of the set. We use curly brackets while writing a set.

2.​ Subset: A set whose elements all belong to another set

3.​ Superset: A set that contains all elements of another set

4.​ Universal Set: Contains all possible elements for a particular context

5.​ Null Set: A set with no elements, denoted as {}

6.​ Elements of a Set: Elements or members are the terms or items present

in a set. They are enclosed in curly brackets and separated by commas.

Set Operations

●​ Union (A ∪ B): Combines elements from both sets

The Union of two sets means combining all the unique elements from both
sets.​
It includes everything from both sets, but duplicates are written only once.
Example:

Let’s say we have:

01.​Set A = {1, 2, 3, 4}
02.​Set B = {3, 4, 5, 6}

Union of A and B (A ∪ B) = {1, 2, 3, 4, 5, 6}

●​ Intersection (A ∩ B): Common elements

The intersection of two sets means the elements that are common to both
sets.​
It shows what both sets have in common.

Example:

I.​ Set A = {1, 2, 3, 4}


II.​ Set B = {3, 4, 5, 6}

Intersection of A and B (A ∩ B) = {3, 4}

Note: Only the elements present in both sets are included.

●​ Complement: Elements not in a given set

The complement of a set means all the elements that are in the universal set
but not in the given set.​
Example:

Let’s assume the Universal Set (U) is:

●​ U = {1, 2, 3, 4, 5, 6, 7, 8}​
And Set A = {2, 4, 6, 8}​
The complement of A (A′) is:
●​ A′ = {1, 3, 5, 7}

These are all the elements in U that are not in A.


Assignment 3:

1.​ Given the following sets:​


Set A = {2, 4, 6, 8}​
Set B = {4, 5, 6, 7}

a) Find the Union of A and B​


b) Find the Intersection of A and B​

2.​ If the Universal Set (U) = {1, 2, 3, 4, 5, 6, 7, 8} and Set A = {2, 4, 6, 8},​

○​ List the Complement of Set A.​

3.​ Write out five examples of real-life sets (Example: set of days in a week,
set of vowels in the English alphabet).

You might also like