0% found this document useful (0 votes)
211 views10 pages

REVIEWER OF DSA Midterm

FIFO (first in, first out) is a queue data structure where the oldest entry is processed first. A queue is open at both ends, with one end used for inserting data and the other for removing data. New data is added at one end and removed from the other end, following the FIFO principle.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
211 views10 pages

REVIEWER OF DSA Midterm

FIFO (first in, first out) is a queue data structure where the oldest entry is processed first. A queue is open at both ends, with one end used for inserting data and the other for removing data. New data is added at one end and removed from the other end, following the FIFO principle.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

- an acronym for first in, first out (the first in is

the first out) is a method for organizing the manipulation


of a data structure (often, specifically a data buffer) where
the oldest (first) entry, or "head" of the queue, is processed
first.

- is an abstract data
(EXSAMPLE OF FIFO)
• is the structural representation of logical relationships structure, somewhat similar to Stacks. Unlike stacks, a
between elements of data. queue is open at both its ends. One end is always used to
• The building blocks of a program. insert data (enqueue) and the other is used to remove data
• A way to store and organize data in order to facilitate (dequeue). Queue follows First-In-First-Out
the access and modifications. methodology, i.e., the data item stored first will be
• The method of representing of logical relationships accessed first.
between individual data elements related to the
solution of a given problem.

stands for P- Parentheses, E- Exponents, M- - These are the basic data structures and are directly
Multiplication, D- Division, A- Addition, and S- operated upon by the machine instructions, which is in a
Subtraction. primitive level
- used to mention the order of operations to be Includes: byte , short , int , long , float , double ,
followed while solving expressions having boolean and char.
multiple operations.
https://www.cuemath.com/numbers/pemdas/

- is an abbreviation for last in, first out. It is a


method for handling data structures where the first
element is processed last and the last element is processed
first.

- is a LIFO (last in, first out) list. means


suppose 3 elements are inserted in stack i.e. 10,20,30. 10
is inserted first & 30 is inserted last so 30 is first deleted
from stack & 10 is last deleted from stack. this is an LIFO https://www.w3schools.com/java/java_data_types.asp#:~:text=Primitive%20data%20types%20%2D%2
0includes%20byte,these%20in%20a%20later%20chapter)
list (Last In First Out).

- It is a more sophisticated data structure emphasizing on


structuring of a group of homogeneous (same type) or
heterogeneous (different type) data items
Includes: String, Arrays and Classes (you will learn
more about these in a later chapter)
b. We may be interested to know in advance that
whether sufficient memory is available to run the
program.
c. There may be several possible solutions with
different space requirements. d. Can be used to
estimate the size of the largest problem that a
program can solve.

- (the input number, or its number of bits,


length of input string, number of cells in an input array,
etc.).
is step-by-step finite sequence of
instructions, to solve a well-defined computational ▪ difficult: input by input analysis
problem. To solve any complex real-life problem. ▪ easier: by input size analysis
▪ Larger input size, more time and space (usually),
✓ A set of rules that precisely defines a sequence of
▪ Large input size analysis (most algorithms run
operations.
quickly on small input; inefficiencies are
✓ Any set of detailed instructions which results in a
magnified)
predictable end-state from a known beginning.
1. Define the problem - relative
2. To design the algorithm to solve the problem efficiency for large input sizes.
Three steps in refinement process:
Mathematical Model - Informal Algorithm
Definition: f(n) is in O(g(n)), denoted f(n) E O(g(n)), if
Formal Language – Pseudo-Language Program order of growth of f(n) < order of growth of g(n) (within
constant multiple), i.e., there exist positive constant c and
Data Structure - Java Program
non-negative integer n0 such that

f(n) < c g(n) for every n > n0


• Finiteness • 0(1) Constant
• Definiteness • O (lg n) Logarithmic
• Clearly specified/expected output • O(n) Linear
• Clearly specified input • O (n lg n) Superlinear
• Effectiveness • O (n2) Quadratic
The choice of a particular algorithm depends on following • O (n3) Cubic
performance analysis and measurements: • O (2n) Exponential
• O (n!) Factorial
an algorithm or a program is
Review
the amount of time it needs to run to completion. The
exact time will depend on the implementation of the Ex: Constant // Ans: O(N5)
algorithm, programming language, optimizing the
capabilities of the compiler used, the CPU speed, other Ex: Linear //
hardware characteristics/specifications and so on.

- Analysis of space
complexity of an algorithm or program is the amount of
memory it needs, to run to completion. Ex: Quadratic //
Some of the reasons for studying space complexity are:
a. If the program is to run on multi User system, it may
be required to specify the amount of memory to be
allocated to the program.
Call ... with (parameters)
Do Until...Enddo Call
Call Case... EndCase Return
Return If...Endif When
Ans: A.

Generate, Compute, Process Set, Reset, Increment,


Compute, Calculate, Ado, Sum, Multiply, ... Print,
Display, Input, Output, Edit.

Write a program that will display if the entered student's


grade is passed of failed. Passing grade is 70.
Input
grade If grade >= 70
display passed

Dominant term – Yellow Else

Big oh – Red display failed


endlf

Algorithms can be expressed in many kinds of notation,


including:
To understand the importance and characteristic of an
• Natural languages array
• Pseudocode
• Flowcharts
• Programming Languages ▪ An array can be defined as a collection of variables of
the same type defined by a common name.
▪ An array is a group of like-typed variables that are
• A program design technique that uses English referred to by a common name.
words. ▪ Arrays of any type can be created and may/ have one
or more dimensions. A specific
• Has no formal syntactical rules.
▪ element in an array is accessed by its index.
• Pseudo means false; thus, pseudocode means
▪ Arrays offer a convenient means of grouping related
false, code. It looks like (imitates) real code but it
information
is NOT real code.
▪ An array is a structure that holds multiple values of
• Pseudocode cannot be compiled nor executed,
the same type.
and there are no real formatting or syntax rules.
▪ The length of an array is established when the array
• Pseudocode should not include keywords in any is created (at runtime).
specific computer languages ▪ After creation, an array is a fixed-length structure.

For looping and selection, the keywords that are to be


used include:
Do While...EndDo
Suppose STACK[SIZE] is a one-dimensional array for
implementing the stack, which will hold the data items.
TOP is the pointer that points to the top most element of
the stack. DATA is the popped (or deleted) data item from
the top of the stack.
1. If TOP = 0, then
a. Display "The stack is empty",
b. Exit
2. Else remove the Top most element
3. DATA = STACK[TOP]
4. TOP = TOP -1
Exercise 5. Exit

Shortcut Term:
top – increment 1
Push – insert
Pop – decrement
Size – Number of elements

Answer

Exercise

size(): Return the number of elements in the stack


empty(): Return true if the stack is empty and false
otherwise.
1. Static implementation (using arrays)
2. Dynamic implementation (using pointers)

Suppose STACK[SIZE] is a one-dimensional array for


Answer
implementing the stack, which will hold the data items.
TOP is the pointer that points to the top most element of
the stack. Let DATA is the data item to be pushed.
1. If TOP = SIZE – 1, then:
(a) Display "The stack is in overflow
condition",
(b) Exit
2. TOP = TOP + 1 0+1=1
3. STACK [TOP] = ITEM
4. Exit
the operator is written in-between
the operands A+B* C-D
is a notation in which the
operator(s) is written before the operands -+A*BCD
Precedence – pop
the operator(s) are written
after the operands ABC + D – Postfix – push
Note that if you have 10 operators then you have 11
push lang rin kapag ka naka exponent
operands.
++ pop naman sya

Left to right when solving


Exponential operator ^ Highest precedence
Multiplication/Division * / Next precedence
Addition/Subtraction + - Least precedence

THE ALGORITHM FOR THE CONVERSION IS


AS FOLLOWS:
1. Scan the Infix string from left to right.
2. Initialize an empty stack
3. If the scanned character is an operand, add it to the
Postfix string. If the scanned character is an
operator and if the stack is not empty Push the
character to stack,

a. If the scanned character is an Operand and


the stack is not empty, compare the
precedence of the character with the element
on top of the stack (topStack) If topStack has
higher precedence over the scanned
character Pop the stack else Push the
scanned character to stack.

Repeat this step as long as stack is not empty and topStack


has precedence over the character. Repeat this step until
all the characters are scanned.
• If stack is not empty add topStack to Postfix string
and Pop the stack Repeat this step as long as stack is
not empty.
• Return the Postfix string. https://www.calcont.in/Conversion/infix_to_postfix
Question:

Reverse infix string:

Scanner Character:

THE ALGORITHM FOR THE CONVERSION IS AS


FOLLOWS:
1. Read the given infix expression into string called
infix.
2. Reverse the infix string and read one character at a
time and perform the following operations:
If the read character is an operand,
then add the operand to the prefix string.
If the read character is not an operand, then check
If the stack is not empty and precedence of the top of the
stack operator is higher than the read operator,
then pop the operator from stack and add this
operator to the prefix string.
Else push the operator onto the stack.

3. Repeat #2 till all characters are processed from the


input string
4. If stack is not empty, then pop the operator from
stack and add this operator to the prefix string.
5. Repeat #4 till all the operators are popped from the
stack.
6. Reverse the prefix string and display the result of the
given infix expression or the resultant prefix
expression stored in a string called prefix from this Reverse Final Prefix
algorithm.
Note: If same level Pop if not push.
https://www.calcont.in/Conversion/infix_to_prefix
Si Prefix lang ung may kakayahan na mag
reverse. https://www.free-online-calculator-use.com/infix-to-
Same precedence + + magiging push prefix-converter.html
-+ push
*/ push
*- pop muna asterik bago mag push ng minus
https://www.free-online-calculator-use.com/postfix-
evaluator.html
P = written in postfix notation.
STACK = hold operands to evaluates P. Algorithm
1. Add a right parenthesis"" at the end of P.
2. Scan P from left to right and repeat Steps 3 and 4 for
each element of P until the sentinel ")" is
encountered.
3. If an operand is encountered, put it on STACK. A postfix expression can be evaluated using the Stack data
4. If an operator is encountered, then: structure. To evaluate a postfix expression using Stack
(a) Remove the two top elements of STACK, where data structure we can use the following steps...
A is the top element and B is the next-to-top
element. 1. Read all the symbols one by one from left to
(b) Evaluate B, A. right in the given Postfix Expression
2. If the reading symbol is operand, then push it
(c) Place the result on to the STACK.
on to the Stack.
5. Result equal to the top element on STACK, 3. If the reading symbol is operator (+ , - , * , /
etc.,), then perform TWO pop operations and
6. Exit. store the two popped operands in two different
variables (operand1 and operand2). Then
perform reading symbol operation using
operand1 and operand2 and push result back on
to the Stack.
4. Finally! perform a pop operation and display the
popped value as final result.

A postfix expression is a collection of operators and


operands in which the operator is placed after the
operands. That means, in a postfix expression the operator
follows the operands.
ADVANTAGES OF A LINKED LIST
1. A dynamic structure
2. Efficient memory utilization
3. Insertion and deletion are easier and efficient
4. Many complex applications can be easily carried
out with linked list.
DISADVANTAGES OF A LINKED LIST
1. More memory
2. Access to an arbitrary data item is little bit
cumbersome and also time consuming.
http://www.btechsmartclass.com/data_structures/postfix- The primitive operations performed on the linked, list
evaluation.html are as follows
1. Creation
2. Insertion
▪ a collection of nodes that together form a linear
3. Deletion
ordering.
4. Traversing
▪ Each node is divided into two parts:
5. Searching
a) The information of the element
6. Concatenation
b) The address of the next node in the linked list

Address part of the node is called as Linked or next field.

1. operation is used to create a linked list.


Once a linked list is created with one node, insertion
operation can be used to add more elements in a node.

2. operation is used to insert a new node at


any specified location in the linked list. A new node may
be inserted.
(a) At the beginning of the linked list
(b) At the end of the linked list
ARRAY - elements stored in successive memory (c) At any specified position in between in a linked
locations. Also, order of elements stored in array is same list
logically and physically
3. operation is used to delete an item (or
LINKED LIST - elements can be added to (or deleted
node) from the linked list. A node may be deleted from
from) either end, or added to (or deleted from) the middle
the
of the list.
(a) Beginning of the linked list
(b) End of the linked list
(c) Specified location of a linked list
3. is the process of going through all
the nodes from one end to another end of a linked list.

Singly linked list, can visit from left to right,


forward traversing, nodes only.

Doubly linked list forward and backward, traversing


is possible.
4. is the process of appending
the second list to the end of the first list.

You might also like