0% found this document useful (0 votes)
3 views

lec 1 and 2

Uploaded by

ba.at.al.2924
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

lec 1 and 2

Uploaded by

ba.at.al.2924
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

DATA STRUCTURES

AND ALGORITHMS

DR. FATMA ELGENDY


Ministry of Higher Education ‫العلم‬ ‫العال والبحث‬ ‫وزارة التعليم‬
and Scientific Research ‫ي‬ ‫ي‬
‫العال للهندسة والتكنولوجيا‬
‫ي‬ ‫المعهد‬
Higher Institute of Engineering
and Technology, Kafrelsheikh ‫بكفر الشيخ‬

Electrical Engineering
‫قسم الهندسة الكهربية‬
‫وحدة ضمان الجودة‬ Department

Course Specification: Data Structures and Algorithms


1- Basic Information
Course Title Data Structures and Algorithms
Course Code EEC2104
Electronics Engineering and Electrical Communications + Computers and Control
Program
Engineering
Academic Year 2024 - 2025
Coordinator Dr. Fatma Elgendy
Teaching Staff Dr. Fatma Elgendy
Year/Branch Second Year Electrical Engineering

Semester First Term


Number of Weekly Lecture 3 x 14 42
Contact Hours Tutorial / Practical 2 x 14 28
Max Marks Final 100 Year Work 25 Oral/ Practical 25
Parent Department Electrical Engineering
Date of Approval 9 / 2024

2- Course Aims
The aims of this course are:
1. Familiarizing the students with algorithm definition and evaluation methods.
2. Mastering the common data structures, common sort and search algorithms.
3. Solving problems using data structures such as arrays, lists, stacks, queues, binary trees, binary
search trees, and graphs and writing programs for these solutions.

3- Program Learning Outcomes Covered by Course


Level A Level B Level C
B3: C1:PLO
A2: PLO2 B4: PLO15
PLO14 17

4- Course Learning Outcomes (CLOs)


1. Analyze and evaluate the behavior of algorithms in terms of time and memory complexity. (PLO 15)
2. Illustrate the standard types of data structure, their characteristics, and their
(PLO 14)
implementations.

1
3. Implement data structures for different applications. (PLO 2)

4. Analyze, develop, implement, evaluate, and test basic algorithms for sorting and searching. (PLO 2)
5. Choose the appropriate data structure and algorithm design method for a specific
(PLO 15)
application.
6. Design and apply algorithms using data structures for various real-life software problems. (PLO 17)

5- Course Contents
Data types and methods of representation - structures files - the representation of data structures
in the storage media and memory - lists - stacks - queues - linear and sequential memory - trees -
algorithms to search and order - and methods of modification and analysis - project .
Experiments (Computer Lab):
Lists implementation- Queues implementation- Trees implementation- Search algorithms for
Lists, Queues and Trees- Sorting algorithms for Lists, Queues and Trees.

Practical
Tutorial

Course Learning Outcomes (CLOs)


Lecture
Week

Course Content
1 2 3 4 5 6
Overview of Data Structures
1 3 2 0
Introduction to algorithm definition and complexity
2 3 2 0
Arrays and Lists.
3 3 1 1
Lab: Array implementation.
Arrays and Lists.
4 3 1 1
Lab: Array implementation.
Stacks and Queues
5 3 1 1
Lab: Stack implementation.
Stacks and Queues
6 3 1 1
Lab: Stack implementation.
Sort Algorithms
7 3 1 1
Lab: Sort algorithms
Mid-Term Exam 8
Sort Algorithms
9 3 1 1
Lab: Sort algorithms
Search Algorithms
10 3 1 1
Lab: Serach algorithm

2
Trees
11 3 1 1
Lab: Tree implementation
Trees
12 3 1 1
Lab: Tree implementation
Graph
13 3 1 1
Lab: Graph implementation
Graph
14 3 1 1
Lab: Graph implementation

6- Teaching and Learning Methods / CLOs Matrix


Course Learning Outcomes (CLOs)
Methods
1 2 3 4 5 6 7
Interactive Lecture
Practical / Applications/ Toturial
Problem solving
Self-Learning

7- Teaching and Learning Methods of Special Needs


Special Needs
> Arrange for note-taking assistance upon request, particularly following a case study, by providing an assistant
to help students with their lecture notes.
Struggling students
> Allocating part of the office hours for struggling students.

Talented / Outstanding students


> Encouraging students to collaborate with faculty members on research topics or design projects with the aim
of publishing their work in the departmental journal.

8- Student Assessment Methods/ CLOs Matrix


Mark

Schedule Course Learning Outcomes (CLOs)


Assessment Method Time Proporion
s

(week) 1 2 3 4 5 6
Written Exam (Final Term) 3hr 16 100 66.7%
Written Exam (Mid-Term) 90 m 8 15 10.0%
Oral / Practical Exam 30 m 15 25 16.7%
In class evaluation (quizzes) 5 3.3%
Self-Learning (Mini Projects) 5 3.3%
During the Term
0.0%
0.0%
Total Marks 150 100% 100%

9- List of References
- Course Notes
o Power Point of Instructor

3
o Lecture Notes

Essential Books:

1- Marcin Jamro,"C# Data Structures and Algorithms", Packt Publishing Ltd, 2018.

Recommended Books:
1. Michael McMillan, "Data Structures and Algorithms using C#", Cambridge University Press 2012.

Periodical Research:
https://www.ekb.eg/ar/home

10- Facilities Required for Teaching and Learning


>> Data show set >> MIC + Loud Speakers
>> Power Point software >> Liberary
>> PC or Laptop >> Lab
>> White board
>> Study hall

Course Coordinator Head of Department


Name (English) Dr. Fatma Elgendy Assoc. Prof. Rokaia Mounir
Signature Fatma Elgendy Rokaia Mounir
Date 9 / 2024

4
Chapter 1
Introduction to Data Structures
DATA STRUCTURE

• A data structure is a way for organizing and storing data in memory so that it can be used efficiently
and it will allow the most efficient algorithm to be used.
• A well-designed data structure allows a variety of critical operations to be performed, using as few
resources, both execution time and memory space, as possible.
• To develop a program of an algorithm, we should select an appropriate data structure for that algorithm.
• Algorithm + Data structure = Program
• A data structure as a logical concept that must address two fundamental concerns:
• 1. First, how the data will be stored.
• 2. Second, what operations will be performed on it.
TYPES OF DATA STRUCTURES

1. Primitive Data structure


• The primitive data structures are primitive data types that can hold a
single value.
• EX: int, char, float, double and string
2. Non-Primitive Data structure
• data structures that are created using the primitive data structures.
a. linear data structure
b. Nonlinear data structures
NON-PRIMITIVE DATA STRUCTURE

1. Linear data structure


• is a list of elements where one element follows the previous element.
• Elements in a linear data structure are normally ordered by position.
• Ex: array, List
2. Nonlinear data structures
• hold elements that do not have positional order with in the collection.
• Ex: trees, heaps, graphs
LINEAR DATA STRUCTURE

1. Direct Access data structures


• The most common example of a direct access collection is the array.
• An array elements are directly accessed via an integer index.

2. Sequential Access Data structures


• is a list that stores its elements in sequential order.
• We call this type of data structure a linear list.
• Linear lists are not limited by size when they are created
• Items in a linear list aren't accessed directly; they are referenced by their position.
NONLINEAR DATA STRUCTURE

1. Hierarchical Data Structure


2. Group Data Structure
HIERARCHICAL DATA STRUCTURE

• Hierarchical Data structure is a group of items divided into levels.


• An item at one level can have successor items located at the next lower level.
• One common hierarchical collection is the tree.
• A tree collection looks like an upside-down tree, with one data element as the root and the other data values
hanging below the root as leaves.
• The elements of a tree are called nodes, and the elements that are below a particular node are called the
node’s children.
• A sample tree is shown in Fig. 1.3.
GROUP DATA STRUCTURE

• A nonlinear collection of items that are unordered is called a group.


• The three major categories of group collections are sets, graphs, and networks.
• A set is a collection of unordered data values where each value is unique.
• Operations that can be performed on sets include union and intersection.
• An example of set operations is shown in Fig. 1.4.
• A graph is a set of nodes and a set of edges that connect the nodes.
• A sample graph of this problem is shown in Fig. 1.5.
• A network is a special type of graph where each of the edges is assigned a weight.
• The weight is associated with a cost for using that edge to move from one node to
another.
• Fig. 1.6 depicts a network of cities where the weights are the miles between the cities
(nodes).
ABSTRACT DATA TYPE (ADT)

• ADT is a logical description of how we view the data and the


operations that are allowed without regard to how they will be
implemented.
• The idea of ADT is encapsulating the details of the implementation.
ALGORITHM

• Algorithm is a method of representing the step by step procedure for solving a problem.
• It is a method of finding the right answer to a problem or to a different problem by breaking
the problem into simple cases.
• Algorithm is represented by pseudocode or flowchart
• Every algorithm must satisfy the following criteria:
❖ Input, Output, Definiteness, Finiteness and Effectiveness
PROBLEM SOLVING STEPS
PRACTICAL ALGORITHM DESIGN ISSUES

• The three basic design goals that one should strive for in a program are:
1. Try to save Time : (Time complexity).
2. Try to save Space: (Space complexity)
3. Try to save Face: by preventing the program from locking up or generating reams
of garbled data.
PERFORMANCE OF A PROGRAM

• The performance of a program is the amount of computer memory and time needed to run a program:
1.Time Complexity: is the amount of computer time it needs to run to completion.
2. Space Complexity is the amount of memory it needs to run to completion.
• The space need by a program has the following components:
a. Instruction space: Instruction space is the space needed to store the compiled version of the
program instructions.
b. Data space: Data space is the space needed to store all constant and variable values.
c. Environment stack space: The environment stack is used to save information needed to resume
execution of partially completed functions.
• Instruction Space: The amount of instructions space that is needed depends on factors such
as:
• The compiler used to complete the program into machine code.
• The compiler options in effect at the time of compilation
• The target computer.
• Data space has two components:
• Space needed by constants and simple variables in program.
• Space needed by dynamically allocated objects such as arrays and class instances.
ALGORITHM COMPLEXITY

• Algorithm complexity is a measure which evaluates the order of the count of


operations, performed by a given or algorithm as a function of the size of the input data.
• The complexity of an algorithm M is the function f(n) which gives the running time and/or
storage space requirement of the algorithm in terms of the size ‘n’ of the input data.
• Mostly, the storage space required by an algorithm is simply a multiple of the data size ‘n’.
• Complexity shall refer to the running time of the algorithm.
• The function f(n) gives the running time of an algorithm.
• The complexity function f(n) for certain cases are:
1. Best Case :The minimum possible value of f(n) is called the best case.
2. Average Case :The expected value of f(n).
3. Worst Case :The maximum value of f(n) for any key possible input.
• Example: searching in array
• Worst Case:To find the searched, we have to check all the elements in the array. the complexity is O(N)
• Best Case: we will have luck and we will find the element at first position. we have a constant complexity O(1),
because we make only one step and directly find the element.
• Average case: we can expect to check half the elements in the array until we find the one we are looking for.
complexity is O(N/2) = O(N)
ASYMPTOTIC NOTATIONS

• Asymptotic notations are the mathematical notations used to describe the running time of
an algorithm when the input tends towards a particular value or a limiting value.
• There are mainly three asymptotic notations: Theta notation, Omega notation and Big-O
notation.
• Theta Notation (Θ-notation) - average case
❖Theta notation encloses the function from above and below. Since it represents the upper and
the lower bound of the running time of an algorithm, it is used for analyzing the average case
complexity of an algorithm.
• Omega Notation (Ω-notation) - best case
❖Omega notation represents the lower bound of the running time of an algorithm. Thus, it provides the best
case complexity of an algorithm. For any value of n, the minimum time required by the algorithm is given by
Omega Ω(f(n)).
• Big-O Notation (O-notation) - worst case
❖Big-O notation represents the upper bound of the running time of an algorithm. Thus, it gives the worst case
complexity of an algorithm. It is widely used to analyze an algorithm as we are always interested in the worst
case scenario. For any value of n, the running time of an algorithm does not cross time provided by O(f(n)).
• Developers typically solve for the worst case scenario, Big-O, because you’re not expecting your algorithm
to run in the best or even average cases when calculating time complexity of an algorithm.
ORDER-OF-MAGNITUDE ANALYSIS AND BIG O
NOTATION

• If Algorithm A requires time proportional to f(n),Algorithm A is said to be order f(n),and it is


denoted as O(f(n)).
• The function f(n) is called the algorithm’s growth-rate function.
• Since the capital O is used in the notation, this notation is called the Big O notation.
• If Algorithm A requires time proportional to n2, it is O(n2).
• If Algorithm A requires time proportional to n, it is O(n).
TYPICAL ALGORITHM COMPLEXITIES
A COMPARISON OF ALGORITHM COMPLEXITIES
COMPLEXITY FUNCTIONS

• O(1): Time requirement is constant, and it is independent of the problem’s size.


• O(log2n): Time requirement for a logarithmic algorithm increases slowly as the problem size increases.
• O(n): Time requirement for a linear algorithm increases directly with the size of the problem.
• O(n*log2n): Time requirement for a n*log2n algorithm increases more rapidly than a linear algorithm.
• O(n2): Time requirement for a quadratic algorithm increases rapidly with the size of the problem.
• O(n3): Time requirement for a cubic algorithm increases more rapidly with the size of the problem than the
time requirement for a quadratic algorithm.
• O(2n): As the size of the problem increases, the time requirement for an exponential algorithm increases
too rapidly to be practical.
RULES FOR USING BIG-O:

• Ignoring constant factors: O(c f(n)) = O(f(n)), where c is a constant; e.g. O(20 n3) = O(n2)
• Ignoring smaller terms: If a<b then O(a+b) = O(b), for example O(n2 +n)= O(n2)
• n and log n are "bigger" than any constant, from an asymptotic view (that means for large
enough n). So if k is a constant, an O(n + k) algorithm is also O(n), by ignoring smaller terms.
Similarly, an O(log n + k) algorithm is also O(log n).
• Another consequence of the last item is that an O(n log n + n) algorithm, which is O(n(log n +
1)), can be simplified to O(n log n).
CALCULATING THE RUNNING TIME OF A
PROGRAM
• Example 1:
• Let’s consider a short piece of source code:

• If y, z are scalars, this piece of code takes a constant amount of time, which we write as O(1).
• O(1) means some constant, it might be 5, or 1 or 1000.
• Auxiliary Space: O(1)
• Example2:

• Time Complexity: O(1)


• Auxiliary Space: O(1)
• Example 3:
• Analysis of simple for loop

• This loop will run exactly n times, and because the inside of the loop takes constant time, the total running time is
proportional to n.
• Time Complexity: O(n).
• the code is said to have linear running time.
• Auxiliary Space: O(1)
• Example 4:
• Analysis for nested for loop

• The outer for loop executes n times, while the inner loop executes n times for every execution of the
outer loop.That is, the inner loop executes nxn = n2 times.
• so the running time of the code is,Time Complexity, : O(n2) steps.
• This piece of code is said to have quadratic running time.
• Auxiliary Space: O(1)
• Example 5:

• Time Complexity: O(log2(n))


Auxiliary Space: O(1)
• Example 6:
• Analysis of matrix multiply

• There are 3 nested for loops, each of which runs n times.


• The innermost loop therefore executes n*n*n = n3 times.
• The innermost statement, which contains a scalar sum and product takes constant O(1) time.
• So the algorithm overall takes,Time Complexity, O(n3) time.
• Auxiliary Space: O(1)
• Example 7:
• Time Complexity: O(n*m)
Auxiliary Space: O(n*m)

You might also like