8/4/2019 Data Structures Presentation
1/68
DataStructures
Engr. Gil R. delas Alas Jr.
CPE-Instructor
8/4/2019 Data Structures Presentation
2/68
a data structure is a particular way ofstoring and organizing data in a
computer. (http://en.wikipedia.org/wiki/Data_structure#Basic_principles
)
Common data structures include: array,linked list
, hash-table, heap, B-tree
,
red-black tree, trie.(http://en.wikipedia.org/wiki/Data_structure#Basic_principles)
8/4/2019 Data Structures Presentation
3/68
the term data structure refers to a schemefor organizing related pieces of information.http://www.webopedia.com
A data structure is a specialized formatfororganizing and storing data http://searchsqlserver.techtarget.com
a data structure may be selected or designed
to store data for the purpose of working on itwith various algorithms. http://searchsqlserver.techtarget.com
8/4/2019 Data Structures Presentation
4/68
The curiosity of our surroundings is the constant force thatdriveshumanityforward. Inanefforttobetterourselvesandour
future we studythe worldwe live in. Ourowninventionsdefine
the wayinwhichwe leadourlives,andwhatpeople webecome. Computershave nowbecome the centerofmany
culturesaroundthe world,astechnologyunitespeople inawaythathasneverbeenseenbefore,changingthe waywe vieweachother. Inthe lastdecade,the Internethasbecome amediumthatletspeople share theirideasandopinionswith
millionsofothers. We are veryclose toaworldwhere ignoranceisnolongeranexcuse. Computersare,andwillbe evenmore,
inthe centerofourlives.
-- "WorldAroundUs" byAlecSolway
8/4/2019 Data Structures Presentation
5/68
Common Types of Data StructureArray
ListsTrees
Heaps
Tries
8/4/2019 Data Structures Presentation
6/68
Data Types
is a classification identifying one of various
types of data that determines the possiblevalues for that type; the operations thatcan be done on that type; and the way thevalues of that type are stored.
Basic Data types:Integer,Float,Double,Char,String,Boolean.
8/4/2019 Data Structures Presentation
7/68
Integer
int height = 100;
int balance = -67;
Char
char menuSelection = 'q';
char userInput = '3'; signed char myChar = 100;
signed char newChar = -43
8/4/2019 Data Structures Presentation
8/68
Float/Double
float celsius = 37.623;
double fahrenheit = 98.415;
String
char strvar2[]="string can also be initialized
like this for the C++ Tutorial";
8/4/2019 Data Structures Presentation
9/68
ALGORITHM
an algorithm ( i/lm/) is aneffective method expressed as a finite
list[1] of well-defined instructions[2] forcalculating a function[3]. Algorithms areused for calculation, data processing,
and automated reasoning.http://en.wikipedia.org/wiki/Algorithm
8/4/2019 Data Structures Presentation
10/68
an algorithm is any set of detailedinstructions which results in a
predictable end-state from a knownbeginning.
An algorithm is a finite set of
instructions which, if followed,accomplish a particular task.
8/4/2019 Data Structures Presentation
11/68
HISTORY
Originally namedafter themathematician in 9th
century byAbuAbdullah Muhammadbin Musa al-Khwarizmi.
8/4/2019 Data Structures Presentation
12/68
Algorithm as Algorism
The word algorism originally referred only tothe rules of performing arithmetic usingArabicnumerals but evolved into algorithm by the18th century.
8/4/2019 Data Structures Presentation
13/68
Criteria
Analyze the problem
Is required to ensure that the problem is clearlydefined and understood.
Develop a solution
Selecting an exact set of steps.
8/4/2019 Data Structures Presentation
14/68
Code the SelectionSequence - It is the order in whichinstructions are executed by the program.
- It is a Straight forward
manner.
Selection - It provides thecapability to make choice between differentoperations, depending on the results of the
condition.
Iteration - Referred to as aLooping or a repetition.
8/4/2019 Data Structures Presentation
15/68
8/4/2019 Data Structures Presentation
16/68
PSEUDOCODE
Pseudocode is an artificial and informal language that
helps programmers develop algorithms. Pseudocode is a
"text-based" detail (algorithmic) design tool.
Pseudocode is a kind of structured english for describing
algorithms
8/4/2019 Data Structures Presentation
17/68
8/4/2019 Data Structures Presentation
18/68
Basic Flowchart Symbols
The Process Symbol represents
any process, function, or action
and is the most frequently used
symbol in flowcharting.
The Document Symbol is
used to represent any typeof hard copy input or output
(i.e. reports).
8/4/2019 Data Structures Presentation
19/68
Offpage Connector Symbols are used
to indicate the flowchart continues on
another page. Often, the page number
is placed in the shape for easy
reference.
The Input/Output Symbol represents
data that is available for input or
resulting from processing (i.e.customer database records)
8/4/2019 Data Structures Presentation
20/68
Comment Symbols are used when
additional explanation or comment is
required. This symbol is usually
connected to the symbol it is
explaining by a dashed line.
The Decision Symbol is a junction
where a decision must be made. A
single entry may have any number of
alternative solutions, but only one can
be chosen.
8/4/2019 Data Structures Presentation
21/68
The Connector Symbol represents the exit
to, or entry from, another part of the same
flowchart. It is usually used to break a flow
line that will be continued elsewhere. It's a
good idea to reference page numbers for
easy location of connectors.
Flow lines indicate the flow of
operation, that is, the exact sequence inwhich the instruction are executed.
8/4/2019 Data Structures Presentation
22/68
8/4/2019 Data Structures Presentation
23/68
8/4/2019 Data Structures Presentation
24/68
8/4/2019 Data Structures Presentation
25/68
8/4/2019 Data Structures Presentation
26/68
8/4/2019 Data Structures Presentation
27/68
8/4/2019 Data Structures Presentation
28/68
EXERCISE.
1. Write an algorithm that will debug a program.
2. Create an algorithm that will check a non-functioning lamp.
3. Create a flow chart For this pseudocode:
If student's grade is greater than or equal to 60
Print "passed
Else
Print "failed"
8/4/2019 Data Structures Presentation
29/68
4. Create a flowchart andpseudocode that will display thehighest of the 3 input numbers.
5. Create a flowchart andpseudocode that will display if theinput number is positive or negative.
8/4/2019 Data Structures Presentation
30/68
FUNDAMENTAL OF C++
BASIC STRUCTURE OF C++PROGRAMMING.
8/4/2019 Data Structures Presentation
31/68
8/4/2019 Data Structures Presentation
32/68
2 types of directive
#include
#define
-defining a constant
Ex. #define PI=3.1416
-defining a macro
Ex. #define cout c
#define NEWLINE '\n'
8/4/2019 Data Structures Presentation
33/68
Local and global declaration of variable
Local variable
Is a variable declared inside a block.
Ex.
8/4/2019 Data Structures Presentation
34/68
Global variable
A variable is declared outside the block.
Int x,y=5;
Main()
{
Z=x+y;
Cout
8/4/2019 Data Structures Presentation
35/68
main function : main()
It is also called a driver function since it is the first
function that will be executed once the program iscompiled.
There must have one and only one main() function.
8/4/2019 Data Structures Presentation
36/68
Program body
Input and Output operator
Output operator
Is represented as
8/4/2019 Data Structures Presentation
37/68
Input operator
It represented as a symbol of >>
Also known as get operator or extraction operator.
Reads data from the keyboard into the memoryduring program execution.
8/4/2019 Data Structures Presentation
38/68
Open brace
Is symbolizes as {
Determines the beginning of the function body andmay also denote the start of a certain block
Close brace
Is symbolizes as }
Determines the end of the function body and may
also signify the end of a certain block
Open and Close Brace
8/4/2019 Data Structures Presentation
39/68
Statement
Basic component of a function and usually
terminated by the terminator operator, the semi-
colon(;).
Ex.Z=x+y;
cout
8/4/2019 Data Structures Presentation
40/68
8/4/2019 Data Structures Presentation
41/68
OPERATORSRelational Operators
Greater than > If(x>y) True
Greater than
or equal to
>= If(x>=y) True
Less than < If(x
8/4/2019 Data Structures Presentation
42/68
OPERATORS
Logical Operator
Logical OR || If(x==y || x==5) TrueLogic AND && If(x==y && x==5) False
If x=5 and y=2
8/4/2019 Data Structures Presentation
43/68
OPERATORS
Combinational operator
Add to += x+=y; x=x+y; 7
Subtract to -= x-=y; x=x-y; 3
Multiply to *= x*=y; x=x*y; 10
Divide to /= x/=y; x=x/y; 2.5
Mode to %= x%=y; x=x%y; 1
If x=5 and y=2
8/4/2019 Data Structures Presentation
44/68
OPERATORS
Increment / Decrement
Pre-increment ++m
Post-increment m++
Pre-decrement --m
Post-decrement m--
If x=5 and y=2
Pre version performs theoperation(either by adding 1 orsubtracting by 1) on thesubject before the resulting
value is used in its surroundingcontext.
Post version performstheoperation after the objectcurrent value hasbeen used.
8/4/2019 Data Structures Presentation
45/68
1.#include
#include
main()
{ int x,y;
x=44;
y=++x;
cout
8/4/2019 Data Structures Presentation
46/68
#include
#include
main()
{//combine operator
int n=22;
cout
8/4/2019 Data Structures Presentation
47/68
Selection/ conditional statement
#include
#include
int x,y;
main()
{
coutx>>y;
if(x%y) cout
8/4/2019 Data Structures Presentation
48/68
#include
#include
int x,y;
main()
{
coutx>>y;
if(x%y) cout
8/4/2019 Data Structures Presentation
49/68
3. Nested if statement
8/4/2019 Data Structures Presentation
50/68
4. Else if statement
8/4/2019 Data Structures Presentation
51/68
5. Switch statement
8/4/2019 Data Structures Presentation
52/68
Combinational expressionoperator
8/4/2019 Data Structures Presentation
53/68
8/4/2019 Data Structures Presentation
54/68
8/4/2019 Data Structures Presentation
55/68
8/4/2019 Data Structures Presentation
56/68
8/4/2019 Data Structures Presentation
57/68
Functions1. Break();
Using break we can leave a loop even if the conditionfor its end is not fulfilled. It can be used to end an
infinite loop, or to force it to end before its naturalend. #include#include
using namespace std;
int main (){
int n;
for (n=10; n>0; n--) {
cout
8/4/2019 Data Structures Presentation
58/68
2. Continue statement
The continue statement causes the program to skip the rest of the loop
in the current iteration as if the end of the statement block had beenreached, causing it to jump to the start of the following iteration.
//continue loop example
#include
#include
using namespace std;
int main (){
for (int n=10; n>0; n--) {
if (n==5) continue;
cout
8/4/2019 Data Structures Presentation
59/68
3. Goto statement
goto allows to make an absolute jump to anotherpoint in the program. You should use this feature with
caution since its execution causes an unconditionaljump ignoring any type of nesting limitations.The destination point is identified by a label, which isthen used as an argument for the goto statement. Alabel is made of a valid identifier followed by a colon
(:).
8/4/2019 Data Structures Presentation
60/68
#include
using namespace std;
intmain () {
intn=10;
loop:cout
8/4/2019 Data Structures Presentation
61/68
// factorial calculator
#include
using namespace std;
longfactorial (longa)
{ if(a > 1)
return (a * factorial (a-1));
else return (1); }
intmain ()
{
longnumber;
cout > number;
cout
8/4/2019 Data Structures Presentation
62/68
// declaring functions prototypes
#include
using namespace std;voidodd (inta);
voideven (inta);
intmain ()
{
inti;
do {
cout > i;
odd (i); }
while (i!=0);
return 0;
}
voidodd (inta)
{ if((a%2)!=0)
8/4/2019 Data Structures Presentation
63/68
Array
array issimply a number ofmemory locations,eachofwhichcanstore anitemofdata ofthesame data type andwhichare all referencedthroughthe same variable name.
Howtodeclare anArray?
array_type variable_name[array_size];
8/4/2019 Data Structures Presentation
64/68
Example:
int Age [5] = {30, 22, 33, 44, 25};
int Age [5];
Age [0]=30;
Age [1]=22;
Age [2]=33;
Age [3]=44;
Age [4]=25;
8/4/2019 Data Structures Presentation
65/68
8/4/2019 Data Structures Presentation
66/68
8/4/2019 Data Structures Presentation
67/68
8/4/2019 Data Structures Presentation
68/68