15
1 | P a g e HUMAN COMPUTER INTERACTION II IT Elective 2 MODULE DATA STRUCTURES AND ALOGORITHM Author ARISTOTLE C. MAYORCA, MSIT FERDINAND M. FERNANDO

DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

  • Upload
    others

  • View
    25

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

1 | P a g e

HUMAN COMPUTER INTERACTION II IT Elective 2 MODULE

DATA

STRUCTURES

AND

ALOGORITHM

Author

ARISTOTLE C. MAYORCA, MSIT

FERDINAND M. FERNANDO

Page 2: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

Republic of the Philippines UNIVERSITY OF RIZAL SYSTEM

Province of Rizal

Course Guide

for

DATA STRUCTURE AND ALGORITHMS

BSIT Program 1st Semester, AY 2020 – 2021

Introduction Data Structures are the programmatic way of storing data so that data can be used

efficiently. Almost every enterprise application uses various types of data structures in

one or the other way. This tutorial will give you a great understanding on Data Structures

needed to understand the complexity of enterprise level applications and need of

algorithms, and data structures.

Hi..my name is ARISTOTLE C. MAYORCA, I am an IT

instructor at University of Rizal System Binangonan Campus and

I handled some of the major subject in BSIT and BSIS courses.

My Undergraduate course is Bachelor of Science in Computer

Science. I also earned a supplemental units at University of Rizal

System Morong campus and at the year 2017 I finished my

Masteral degree,with the course of Master of Science

Information Technology in Rizal Technological University, and I

have been a Computer Technician after I finished and pass the

National Certification NCII.

Page 3: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

(NISMED). Between 1987 and 1989, while earning BSE supplemental units and units in

the graduate school for MA in Industrial Ed., he was also a grantee of JICA-JOCV (Japan

International Cooperation Agency-Japan Overseas Cooperation Volunteer) training under

system Engr. Hiroshi Aruga of the University of Tokyo. I was the author of the BS

Computer Science course at the Tomas Claudio College (formerly TCMC) in the 1990s.

Currently an Assistant Professor at the College of Engineering URS Morong.

Course Objectives: General objectives

1. Analyze complex problems and identify and define the computing requirements needed to design an appropriate solution;

2. Apply computing and other knowledge domains to address real-world problems; 3. Design and develop computing solutions using a system-level perspective; 4. Utilize modern computing tools.

Specific Objectives: 1. Be able to discuss, explain and introduce Data structure and algorithms.

Familiarized the network to be used in the subject. 2. Be able to discuss, explain, learn and apply the different Fundamental Data

Structures like Arrays and linked Lists. 3. Apply techniques and methods on using Arrays and linked Lists. 4. Make use of a step-by-step approach applying arrays in different situations. 5. Identify the Characteristics and Terminologies of trees 6. Be able to discuss, explain and apply the how Graphs and Other Advanced Data

Structures works.

Pre-Requisite

ITE 5

I am Prof. Ferdinand M. Fernando, a graduate of BSECE

currently teaches different computer and electronics courses

in the ECE, CPE, and EE programs of the College of

Engineering in URS Morong Campus. I started teaching since

1986 in the then Rizal Technological and Polytechnic Institute

(now, URS). From 1989 up to 1991 I was the Computer

Courseware Specialist in UP-ISMED, now National Institute for

Science and Mathematics Education Development (NISMED).

Between 1987 and 1989, while earning BSE supplemental

units and units in the graduate school for MA in Industrial Ed.,

he was also a grantee of JICA-JOCV (Japan International

Cooperation Agency-Japan Overseas Cooperation Volunteer)

training under system Engr. Hiroshi Aruga of the University of

Tokyo. He was the author of the BS Computer Science course

at the Tomas Claudio College (formerly TCMC) in the 1990s.

Currently he is an Assistant Professor at the College of

Engineering URS Morong.

Page 4: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

Course Materials

Computers, pdf file, text books covers analysis and design of fundamental data

structures and engages students to have access to computer equipment with

certain requirements. ... that you have acquired a command of the general subject matter,

knowledge.

COURSE CONTENT

UNIT 1 - Introductions of Data Structure and Algorithm

Module 1. Introduction of Data Structure and Algorithm Analysis

Module 2. Fundamentals of Arrays

Module 3. Fundamentals of, Linked list and

Module 4. Fundamentals of Recursion

UNIT 2 – Introductions of Stacks, Queues, Heaps and Trees

Module 5. Fundamentals of Stacks Module 6. Fundamentals of Queues Module 7. Characteristics and Terminologies of Trees Module 8. Fundamentals of Heaps

UNIT 3 – Graphs and Sorting Algorithms

Module 9. Fundamentals and Graphs Representations

Module 10. Fundamentals of Sorting Algorithms

Activity Schedule

Welcome Activity and Course Orientation

Week 1 – Aug 24 – 28, 2020

Via Google Meet

Module 1

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Aug 25 - 28, 2020

To be submitted on Aug. 28 through google

class room

Module 2

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Aug 31 –Sept 4, 2020

Via Google Meet

Page 5: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

To be submitted on Sept.4 through google

class room

Module 3

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Sept 7 – 25, 2020

Via Google Meet on Sept. 10 To be submitted on Sept.25 through google

class room

Module 4

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Sept 28 - Oct 2, 2020

To be submitted on Oct 1-2 through google

class room

PRELIM EXAM

Module 5

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Oct 5 – Oct 9, 2020

Via Google meet

To be submitted on Oct 9 through google

class room

Module 6

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Oct 12 – Oct 16, 2020

Via Google meet

To be submitted on Nov. 15-16 through

google class room

Module 7

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Oct 19 – Oct 26, 2020

Via Google meet

To be submitted on Oct 29 through google

class room

Module 8

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Oct 28– Nov 4, 2020

Via Google meet

To be submitted on Nov. 5-6 through google

class room

MIDTERM EXAM Nov 9 -13, 2020

Module 9

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Nov 16 – Nov 27, 2020

Via Google meet

Page 6: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

To be submitted on Nov. 27 through google

class room

Module 10

Read and Discuss the Lectures

Do Activity’s

Answer the SAQ

Nov 30 – Dec 11, 2020

Via Google meet

To be submitted on Dec. 12-13 through

google class room

FINAL EXAM

Submission of Hands-on Activities

For Quizzes

There will be no special quizzes. For Hands on Activities

Activities should be submitted on the scheduled date of submission For Term Exams

Term Examination can be given to student who has valid reason for not taking the exam

Student caught cheating will automatically have a grade of 5.0 for that particular exam.

Failure to take term exams and final project will be marked as incomplete.

Grading System

Student’s progress, productivity and learning in information technology will be assessed and evaluated based on demonstrated performance, completion and quality of course assignments and activities that may include: exams, quizzes, homework assignments,

participation in class lectures, attendance and participation in laboratory sessions, team‐member or individual project development, and other assignments as specified by the Instructor.

Examination (Prelim/Midterm/Finals) - 40%

Quizzes - 30% Written and Hands-on Activities - 30% Total - 100%

Page 7: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

MODULE 6

Fundamentals of QUEUES

Objectives:

1. Define and contrast stacks and queues as abstract data types. 2. Demonstrate how to implement stacks and queues as arrays and linked data

structures. 3. Explain, with code examples, the algorithms for initializing, pushing, popping, and

checking for a full/empty stack. 4. Explain, with code examples, the algorithms for initializing, enqueueing,

dequeuing, and checking for a full/empty queue.

QUEUES

Like the stack, the queue is a list-like structure that provides restricted access to its

elements. Queue elements may only be inserted at the back (called an enqueue

operation) and removed from the front (called a dequeue operation). Queues oper-

// Abstract queue class

template <typename Elem> class Queue { private:

void operator =(const Queue&) {} // Protect assignment

Queue(const Queue&) {} // Protect copy constructor

public:

Queue() {} // Default

virtual ˜Queue() {} // Base destructor

// Reinitialize the queue. The user is responsible for

// reclaiming the storage used by the queue elements. virtual

void clear() = 0;

// Place an element at the rear of the queue. virtual

void enqueue(const Elem&) = 0;

// Remove and return element at the front of the queue. virtual

Elem dequeue() = 0;

// Return a copy of the front element. virtual

const Elem& frontValue() const = 0;

Page 8: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

// Return the number of elements in the queue. virtual int length() const = 0;

};

The C++ abstract class declaration for a queue.

ate like standing in line at a movie theater ticket counter.1 If nobody cheats, then

newcomers go to the back of the line. The person at the front of the line is the next to be

served. Thus, queues release their elements in order of arrival. Accountants have used

queues since long before the existence of computers. They call a queue a “FIFO” list,

which stands for “First-In, First-Out.” Figure 4.22 shows a sample queue ADT. This section

presents two implementations for queues: the array-based queue and the linked queue.

• A queue is an ordered list in which the first element added is the first element

retrieved or removed (First-In, First-Out).

• The first element in the queue is known as the head of the queue.

Graphical Representation

A queue can be graphically represented in a similar way to a list or stack, but with an

additional two-cell in which the first element points to the front of the list of all the elements in

the queue, and the second element points to the last element of the list. For instance, if we

insert the elements [3, 1, 4, 2] into an initially empty queue, we get:

v

3 1 4 2

Abstract Data Type “Queue”

On an abstract level, a queue can be constructed by the two constructors:

• EmptyQueue, the empty queue, and

• push(element, queue), which takes an element and a queue and returns a queue in which the

element is added to the original queue at the end.

For instance, by applying push(5, q) where q is the queue above, we get

Page 9: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

v

3 1 4 2 5

The two selectors are the same as for stacks:

• top(queue), which gives the top element of a queue, that is, 3 in the example, and

• pop(queue), which gives the queue without the top element.

And, as with stacks, the selectors only work for non-empty queues, so we again need a condi- tion which returns whether a queue is empty:

• isEmpty(queue)

• Example: A queue of customers: Lisa, Jennie, Jisoo, Rose

Lisa is the customer who has been waiting the longest, while Rose is the one who last

arrived. Lisa will be the first customer removed from the queue.

• Queues are used in any of the following:

o CPU and disk scheduling

o Serving requests on a single shared resource, such as a printer

Lisa

Jennie

Jisoo

Rose

Page 10: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

o Managing customers trying to get hold of a hotline.

• The methods of the Queue interface from the java.util package are used to

implement queues in Java. Since interfaces cannot be instantiated, LinkedList is

used to instantiate a Queue object.

• The methods of collections.deque are used to implement queues in Python.

The import statement shall be from collections import deque

• The list methods can also be used to implement queues in Python.

• The two (2) main queue operations are the following:

o Enqueue – adds an item into the queue

▪ Method in Java: offer()

Queue queue = new LinkedList(); queue.offer("Lisa");

▪ Method in Python: append() queue = deque([])

queue.append("Jennie")

▪ Dequeue – removes the head of the queue

▪ Method in Java: poll()

▪ Method in Python: popleft()

Other queue operations:

▪ Peek – retrieves the head of the queue

▪ Method in Java: peek()

▪ Syntax in Python: queue_name[0]

Test whether queue is empty

▪ For Java, use the isEmpty() method.

▪ For Python, use the ifnot condition, followed by the queue name and a

colon.

▪ Example:

▪ queue = deque([])

▪ if not queue:

▪ print("Queue is empty.")

Page 11: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

A queue has the following operations:

The queue() constructor constructs a new queue. The empty() method returns true if the queue is empty, code false otherwise. The front() method returns the first element at the front of the queue. The back() method returns the first element at the back of the queue. The push(e) method adds the element e to the back of the queue.

The pop() method removes the element at the front of the queue.

Page 12: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

Reference

Books

Karumanchi, N. (2017). Data structures and algorithms made easy. Hyderabad:

CareerMonk Publications.

TechDifferences (n.d.). Differences between array and linked list. Retrieved from

https://techdifferences.com/difference-between-array-and-linked-list.html

Pdf Files

csharp-data-structures-and-algorithms.pdf

dsa.pdf

C++3e20100119.pdf

Page 13: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

ACTIVITY

Try this out on paper first:

Question #1: Suppose the words in the sentence "Madam, I'm Adam." were

pushed one after the other onto the same queue, and then they were printed as

they were popped off. What would be printed?

Now, granted, this is only one example, but perhaps it's enough to make a prediction:

Question #2: What will the (eventual) program do in general to any sequence of

words?

Design

This is so similar to the stack problem, you're going to do all of the design for this one. You'll find that copying the design for Activity used in STACKS and changing a few words is all you need to do.

Question #3: What is the behavior of this program?

Question #4: What are the objects needed in the program?

Question #5: What are the operations needed in the program? Similar

to Experiment #1, you can ignore the old, familiar input/output operations.

Question #6: What is the algorithm for this program?

Write the program, compile it, and run it.

The Analysis

Compare your prediction with the actual outcome.

Question #1: How closely did your prediction match the actual outcome?

A queue is sometimes known as a FIFO container---First In, First Out. The first item you push onto a queue will be the first one out.

Question #1: How does FIFO explain the behavior you see from your program?

Page 14: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

Self-Assessment Questionnaire ( SAQ )

1. Inserting an item into the stack when stack is not full is called …………. Operation and deletion of item form the stack, when stack is not empty is called………..operation.

A) push, pop B) pop, push C) insert, delete D) delete, insert

2. ……………. Is a pile in which items are added at one end and removed from the other.

A) Stack B) Queue C) List D) None of the above

3. Which data structure allows deleting data elements from and inserting at rear? A) Stacks B) Queues C) Dequeues D) Binary search tree

4. A ……. is a data structure that organizes data similar to a line in the supermarket, where the first one in line is the first one out.

A) Queue linked list B) Stacks linked list C) Both of them D) Neither of them

5. Which data structure is used in breadth first search of a graph to hold nodes? A) Stack B) queue C) Tree D) Array

Page 15: DATA STRUCTURES AND ALOGORITHM · UNIVERSITY OF RIZAL SYSTEM Province of Rizal Course Guide for DATA STRUCTURE AND ALGORITHMS BSIT Program 1st Semester, AY 2020 – 2021 Introduction

Answer to Self-Assessment Questionnaire (ASAQ)

1. A 2. B 3. B 4. A 5. B