Data Structure
Data Structure
PSEUDO CODES:
CODES:
SAMPLE PROGRAM
OUTPUT:
MIDTERM LESSON 1:
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.
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 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.
• 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 is a non-empty collection of vertices and edges that satisfies certain requirements
Vertex – It is a simple object (also referred to as a node) that can have a name and can carry other
associated information.
Path − Path refers to the sequence of nodes along the edges of a tree. It is also a list of distinct vertices
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
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.
Subtree − Subtree represents the descendants of a node. These are nodes below the root.
Level of Nodes – it is the number of nodes in the path from the node to the root(not including itself).
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
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