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

Data Structure

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Data Structure

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

PRELIM LESSON1

INTRODUCTION TO DATA STRUCTURE


(Algorithm, Pseudo Codes, Flowchart)
Contents:
Definition of terms
Algorithm example
Pseudo codes
Example program
Output of the program
DEFINITION OF TERMS
Pseudo Codes – These are close to natural
Data: Collection of raw facts.
languages that serve as a textual
Data Structure: is representation of the presentation of a flowchart.
logical relationship existing between
Flowchart – It is a diagram that shows
individual elements of data.
step-by-step progression through a
procedure or system especially using
Algorithm – It is a finite set of
connecting lines and a set of conventional
instructions that specify a sequence of
symbols.
operations.
ALGORITHM :
1. Display “Enter your age”
2. User will input an age from the keyboard
3. Create the condition
4. Display the result

PSEUDO CODES:

Display the “Enter your age: “


Enter age from the keyboard
If age is equal or greater than 18, then
print “You are an adult”
else
print “You are still a minor”
SAMPLE PROGRAM

CODES:
SAMPLE PROGRAM
OUTPUT:
MIDTERM LESSON 1:

STACK DATA STRUCTURE

Contents:
Definition of terms
Example program
Output of the program
Stack Data Structure

Stack is a linear data structure which follows a particular order in which the operations are performed. The
order may be LIFO(Last In First Out) or FILO(First In Last Out).
METHODS OF STACK INTERFACE

Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow condition.

E element(): This method returns the head (the first element) of the Queue.

boolean offer(object): This is same as add() method.

E remove(): This method removes the head(first element) of the Queue and returns its value.

E poll(): This method is almost same as remove() method. The only difference between poll() and
remove() is that poll() method returns null if the Queue is empty.

E peek(): This method is almost same as element() method. The only difference between peek()
and element() is that peek() method returns null if the Queue is empty.
CODES:
:
OUTPUT:
MIDTERM LESSON 2

Queue Data Structure


WHAT IS QUEUE?

Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at

both its ends. One end is always used to insert data (enqueue) and the other is used to remove

data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be

accessed first.
Methods of Queue interface

• E element(): This method returns the head (the first element) of the Queue.

• boolean offer(object): This is same as add() method.

• E remove(): This method removes the head(first element) of the Queue and returns its value.

• E poll(): This method is almost same as remove() method. The only difference between poll() and
remove() is that poll() method returns null if the Queue is empty.

• E peek(): This method is almost same as element() method. The only difference between peek()
and element() is that peek() method returns null if the Queue is empty.
MIDTERM.LESSON 3

Tree Data Structure


TREE

Tree is a non-empty collection of vertices and edges that satisfies certain requirements

and Tree represents the nodes connected by edges.


Important Terms

Vertex – It is a simple object (also referred to as a node) that can have a name and can carry other

associated information.

Edge – it is a connection between two vertices.

Path − Path refers to the sequence of nodes along the edges of a tree. It is also a list of distinct vertices

in which successive vertices are connected by edges in the tree

Root – It is the defining property of a tree is that there is exactly one path between the root and each of

the other nodes in the tree. The node at the top of the tree is called root. There is only one root per tree and

one path from the root node to any node


Parent − Any node except the root node has one edge upward to a node called parent.

Child − The node below a given node connected by its edge downward is called its child node.

Leaf/Leaves/Terminal Nodes − The node which does not have any child node is called the leaf node.

NonTerminal Nodes. These are nodes that has a least one child.

Internal Nodes – Nonterminal nodes.

External Nodes – Terminal nodes.

Subtree − Subtree represents the descendants of a node. These are nodes below the root.

Forest – It is a set of trees.

Level of Nodes – it is the number of nodes in the path from the node to the root(not including itself).

Height – It is the maximum level among all nodes in the trees.

Path Length – It is the sum of the levels of all the nodes in the tree.
SEMI-FINAL LESSON 1:

Traversing Trees

Contents:
Definition of terms
Example program
Output of the program
TRAVERSING TREES
CODES :
CODES:
CODES:
CODES:
CODES:
Bubble Sort Algorithm

• Bubble Sort – is a sorting algorithm that works by repeatedly stepping through list that
need to be sorted comparing each pair of adjacent items and swapping them if they are
are in the wrong order
• The passing procedure is repeated until no swaps are required, indicating that the list is
sorted
Bubble Sort Codes
Example:
Bubble Sort
Examples
MERGE SORT
Codes:
Definition of Terms:

MERGE SORT
An efficient general purpose comparison based sorting algorithms
Divides the array into two
Works for any type of array
Works in consistent speed for all data sets
Requires more space
More efficient
MERGE SORT

• In computer science, merge sort is an efficient, general-purpose, and comparison-based


sorting algorithm. Most implementations produce a stable sort, which means that the
order of equal
• elements is the same in the input and output
• In computer science, merge sort (also commonly spelled as mergesort) is an
efficient, general-purpose, and comparison-based sorting algorithm. Most
implementations produce a stable sort, which means that the order of equal
elements is the same in the input and output.

FINAL LESSON 2:

HASH TABLES

Contents:
Definition of terms
Example program: (Add, Removing, Changing, Iterating Elements)
Output of the program
DEFINITION OF TERMS

Any non-null object can be used as a key or as a value. To successfully store and
retrieve objects from a hashtable, the objects used as keys must implement the
Hashtable hashCode method and the equals method.

Is a type of fast key lookup data structure that offers a flexible means of indexing
Mapping into its individual elements

Are control structures that allow sections of code to be executed repeatedly


Loops according to the controlling conditions of the loop
CODES:
OUTPUT:

You might also like