SECTION 1: Basic Concepts and Notations, Arrays and Recursion
SECTION 1: Basic Concepts and Notations, Arrays and Recursion
SECTION 1: Basic Concepts and Notations, Arrays and Recursion
ESP: Given n courses, prepare a schedule of examinations for the n course subject to
the following conditions:
(a) examinations for courses with common students must be assigned
different time slots (or, equivalently no student should be made to take
more than one exam at a time, i.e. no conflicts)
(b) examinations must be scheduled using the minimum number of time
slots feasible
1. the structuring of higher level data representations (lists, trees, graphs, tables, etc)
from the basic information structures available at the level of the machine (bits,
bytes, words, etc.) that will faithfully represent the information (raw and processed
data) at the problem domain
2. the synthesis of algorithms( for searching, sorting, traversal, etc.) from the basic
operations provided at the level of the machine (addition, subtraction, comparison,
Section 1 Page 1 of 6
Jennifer Laraya-Llovido
Data Structures & Algorithms
Lists Searching
Trees Sorting
Tables Memory Management
PROBLEM MACHINE
DOMAIN Graphs Traversal DOMAIN
Etc. Etc.
SOLUTION DOMAIN
1. Data Type – refers to the kind of data that variables may hold or take on in a
programming language, and for which operations are automatically provided. For
example:
a. PASCAL: integer, real, Boolean and character
b. C: character, integer, floating point, double floating point
c. FORTRAN: integer, real, complex, logical and character
d. LISP: list or S-expression
2. Abstract Data Type or ADT – is a set of data elements with a set of operations
defined on the data elements.
Section 1 Page 2 of 6
Jennifer Laraya-Llovido
Data Structures & Algorithms
What is an algorithm?
An algorithm is a finite set of instructions which, if followed will accomplish a particular
task.
Example 3: Euclid’s Algorithm for finding the greatest common divisor of two
positive
integers m and n.
Section 1 Page 3 of 6
Jennifer Laraya-Llovido
Data Structures & Algorithms
Step 3. m ←33, n ← 3
Loop 3: Step 1. 33/3 = 11 remainder 0
Step 2. remainder is zero, stop; GCD = 3
To be able to perform any kind of operation on the elements of a data structure, we must
be able to access such elements. There are two methods to accomplish this:
A node is usually divided into named segments called fields. Node α has two
fields named INFO and LINK. The content of the INFO field is the string ‘CS’
while that of the LINK field is the integer 1000. To access these values, we use
the notation INFO(α) and LIN(α), respectively.
Now, consider the nodes shown below. Can you deduce an underlying
structure?
INFO LINK
3000 : CS 1000
1000 : IT 4000
4000 : BS Λ
When a field in this instance, the LINK field of a node contains the address of
another node, we say that the LINK field of the former contains a pointer to the
latter. Such a relationship can be graphically represented by an arrow emanating
from the former and directed to the latter node. Hence, an equivalent way of
representing the linked nodes shown above is as the linked list shown below:
Section 1 Page 4 of 6
Jennifer Laraya-Llovido
Data Structures & Algorithms
INFO LINK
α
CS IT BS Λ
The value 3000 is assigned to the pointer variable α which then effectively
becomes the pointer to the list. It is easy to see that the following relations are
true for this list.
β ← LINK(α)
LINK(α) ← LINK(β)
LINK(β) ← Λ
C01 RDA ALB NAC EDF BMG VLJ IVL LGM EGN KSO EST VIV
C02 MCA EDF SLF ADG BCG AAI RRK LGM RLM JGP LRQ WAR KLS DDY
C03 ABC BBD GCF ADG AKL BCL MIN JGP RSQ DBU IEY RAW ESZ
C04 ANA JCA CAB NAC GCF GLH VLJ LLM MAN PEP PQQ ERR SET MAV REW
C05 BBC EDD HSE ELG ISH JEI EMJ RRK TPL RER EPS AVU CDW ELY
C06 ALA MCA ABB BCF GLH AKL HGN RON JGP ALQ EPR ABT KEV YEZ
C07 CDC ISH ABI DHJ ESM FBM RMN PEP VIR JLS LOT MAV TEX
C08 AAA HLA BBD WRE ECG HLH DHJ RON TSO PQQ MBT REW BAX TRY BDZ
C09 MCA JCA BCF EGG AAI XTK CSM HLO RSP RER APR JET DBU WWW
C10 RDA BBB CLC ECG MNH EMJ JOK ARM NFM EGN RCN RSP LEQ YIR AVU
C11 ADB WDB BKC CLC SDE UKF BMG HRH BTK LGM QJP EPS KLS BST YNZ
Section 1 Page 5 of 6
Jennifer Laraya-Llovido
Data Structures & Algorithms
CO4
CO1
CO2
CO3
C11
CO6
CO7
CO5
CO9
C1O CO8
Color Vertices
Red C01, C03, C05
Green C02, C04, C10
Blue C06, C07, C11
Orange C08, C09
Section 1 Page 6 of 6
Jennifer Laraya-Llovido