Professional Documents
Culture Documents
Data Structure and Algorithms For Call Center
Data Structure and Algorithms For Call Center
Center
Unit19
Reporting Results---------------------------------------------------------------------------------------------------------------------------------- 10
Result-1------------------------------------------------------------------------------------------------------------------------------------------- 10
Result-2------------------------------------------------------------------------------------------------------------------------------------------- 10
Result-3------------------------------------------------------------------------------------------------------------------------------------------- 11
Result-4------------------------------------------------------------------------------------------------------------------------------------------- 12
Result-5------------------------------------------------------------------------------------------------------------------------------------------- 12
Result-6------------------------------------------------------------------------------------------------------------------------------------------- 13
Error Handlings------------------------------------------------------------------------------------------------------------------------------------- 13
Error Handling-1-------------------------------------------------------------------------------------------------------------------------------- 13
Error Handling-2-------------------------------------------------------------------------------------------------------------------------------- 13
Well-Defined Problems-------------------------------------------------------------------------------------------------------------------------- 14
Solving the First Problem to Be Show Options------------------------------------------------------------------------------------------ 14
Solving the Second Problem to Be Choose the Options-------------------------------------------------------------------------------15
Solving the Third Problem to be Store the Receive Calls------------------------------------------------------------------------------16
Solving the Fourth Problem to be Review All Calls-------------------------------------------------------------------------------------19
Solving the Fifth Problem to Be Dial A Number According to Received Order---------------------------------------------------20
Solving the Sixth Problem to be Exit from the System---------------------------------------------------------------------------------20
Asymptotic Analysis------------------------------------------------------------------------------------------------------------------------------ 24
Best-Case Analysis----------------------------------------------------------------------------------------------------------------------------- 24
Worst-Case Analysis--------------------------------------------------------------------------------------------------------------------------- 24
Average-Case Analysis------------------------------------------------------------------------------------------------------------------------ 24
Asymptotic Notations------------------------------------------------------------------------------------------------------------------------- 25
Big Oh Notation, Ο------------------------------------------------------------------------------------------------------------------------- 25
Omega Notation, Ω------------------------------------------------------------------------------------------------------------------------ 25
Theta Notation, θ-------------------------------------------------------------------------------------------------------------------------- 26
Algorithm Efficiency------------------------------------------------------------------------------------------------------------------------------ 27
Space Efficiency--------------------------------------------------------------------------------------------------------------------------------- 27
Time Efficiency---------------------------------------------------------------------------------------------------------------------------------- 27
Example for Time and Space Efficiency--------------------------------------------------------------------------------------------------- 27
Example for Space Efficiency in Java------------------------------------------------------------------------------------------------------- 28
Example for Time Efficiency in Java-------------------------------------------------------------------------------------------------------- 28
PAGE-1
Unit19
REFERENCES--------------------------------------------------------------------------------------------------31
FIGURE 1 RESULT-1...............................................................................................................................................................10
FIGURE 4 RESULT-2...............................................................................................................................................................10
FIGURE 5 RESULT-3...............................................................................................................................................................11
FIGURE 6 RESULT-4...............................................................................................................................................................12
FIGURE 7 RESULT-5...............................................................................................................................................................12
FIGURE 8 RESULT-6...............................................................................................................................................................13
FIGURE 2 ERROR HANDLING 1..............................................................................................................................................13
FIGURE 3 ERROR HANDLING 2..............................................................................................................................................13
FIGURE 9 BIG OH NOTATION, O...........................................................................................................................................25
FIGURE 10 OMEGA NOTATION, Ω........................................................................................................................................25
FIGURE 11 THETA NOTATION, Θ..........................................................................................................................................26
PAGE-2
Unit19
PAGE-3
Unit19
return next;
}
public void setNext(Node<E> next) {
this.next = next;
}
}
PAGE-4
Unit19
PAGE-5
Unit19
if(isEmpty()) {
head=newest;
tail=newest;
}
else
{ newest.setNext(null);
tail.setNext(newest);
tail=newest;
}
size++;
}
public E removeFirst() {
if(isEmpty())
{
System.out.println("List is Empty");
}
E data=head.getElement();
head=head.getNext();
size-=1;
return data;
}
public void traverse() {
int count = 0;
if(isEmpty())
{
System.out.println("List is Empty");
}
while(head!=null) {
count += 1;
E data=head.getElement();
head=head.getNext();
System.out.println(count+". "+data+"");
}
}
PAGE-6
Unit19
PAGE-7
Unit19
if (sl.size() != 0) {
System.out.print("If you want to call last phone number, Enter
'3' : ");
int dial = input.nextInt();
sl.last();
System.out.println("-----------------------");
}
}
else if (item == 4) {
System.exit(0);
}
else {
while (item != 1 || item != 2 || item != 3) {
System.out.print("Pease enter number '1' or '2' or '3' or '4' : ");
int second = input.nextInt();
Q.Check(second);
}
}
}
public static void main(String[] args) {
Queue Q = new Queue();
Scanner input = new Scanner(System.in);
while (true) {
System.out.println("Welcome From Call Center\n1. To be store the
received calls.\n"+"2. Review all calls.\n" +
"3. Dial a number according to received order.\n"+"4.
Exit");
System.console();
System.out.print("Enter with number : ");
int no = input.nextInt();
System.out.println("-----------------------");
while (no != 1 & no != 2 & no != 3 & no != 4) {
System.out.print("Must to enter only digit number '1' to '4'.
Pleas enter again : ");
no = input.nextInt();
}
PAGE-8
Unit19
Q.Check(no);
}
}
}
PAGE-9
Unit19
Reporting Results
Result-1
Figure 1 Result-1
Result-2
Figure 2 Result-2
If user not stores the receive phone numbers by firstly and then user choose
number 2. At the same time, user can see “List is Empty” message.
Result-3
PAGE-10
Unit19
If user stores the receive phone numbers by firstly and then user choose number 2.
At the same time, user can see his stored phone number list in program.
Figure 3 Result-3
PAGE-11
Unit19
Result-4
Figure 4 Result-4
If user stores the receive phone numbers by firstly and then user choose number 3,
user can see receives phone number and user can call last receives phone numbers.
Result-5
Figure 5 Result-5
If user not stores the receive phone numbers by firstly and then user choose
number 3, the program will show message. That message is “List is Empty”.
PAGE-12
Unit19
Result-6
Figure 6 Result-6
If user want to quit or leave from the program, need to enter number 4. If user
enter number 4, the program will exit from the system.
Error Handlings
Error Handling-1
In this case, if user is not entered only digit 1 from 4, error message can see and
need to enter digit number 1 to 4.
Error Handling-2
If user choose number is 1, user can input the receives phone number. However,
use must to enter with only digit number because other characters are not allowed for
phone number in this case. If user enter with other character, user can see error
message. Error message is need to enter only digit number.
PAGE-13
Unit19
Well-Defined Problems
Future Way company need to request to implement the data structure for call
center. In implementation, if a client call, her call must be stored until there is a free
operator to pick it up. Calls should be processed in the same order they are received. The
operator can choose:
1. Storing the received calls.
2. Review all calls.
3. Dial a number according to received order.
There are five problems in the implementation. They are, first to be show options
for user can be see, second to be choose the option by user, third to be store or save the
received calls, fourth to review all calls, fifth to be call a number according to received
order and, sixth to be exit from the system. That why, I choose Queue ADT to be
implement for call center.
Solving the First Problem to Be Show Options
The fist problem is need to show 4 option (Storing the received calls, review all
calls, dial a number according to received order and exit) in the program by firstly.
Therefore, I created main method.
public static void main(String[] args) {
Queue Q = new Queue();
Scanner input = new Scanner(System.in);
while (true) {
System.out.println("Welcome From Call Center\n1. To be store the
received calls.\n"+"2. Review all calls.\n" +
"3. Dial a number according to received order.\n"+"4.
Exit");
System.console();
System.out.print("Enter with number : ");
int no = input.nextInt();
System.out.println("-----------------------");
while (no != 1 & no != 2 & no != 3 & no != 4) {
System.out.print("Must to enter only digit number '1' to '4'.
Pleas enter again : ");
no = input.nextInt();
}
Q.Check(no);
}
PAGE-14
Unit19
}
In the main method, I coded 3 option to be show and then to be accept user
request.
After finished implementing main method. The program can show 4 option to user
and then user can choice the option.
Solving the Second Problem to Be Choose the Options
When user input the data for options, the program needs to check what user
needed is. That why, I created check method.
public void Check(int item) {
Scanner input = new Scanner(System.in);
Queue Q = new Queue();
if (item == 1) {
System.out.print("Enter receives phone number : ");
String recive = input.next();
for (int i =0;i<recive.length();i++) {
while (recive.charAt(i) != '0' &recive.charAt(i) != '1' &
recive.charAt(i) != '2' & recive.charAt(i) != '3' & recive.charAt(i) != '4' & recive.charAt(i) !=
'5'
& recive.charAt(i) != '6' & recive.charAt(i) != '7' &
recive.charAt(i) != '8' & recive.charAt(i) != '9') {
System.out.println("Must to enter only digit number.
Pleas enter again : ");
recive = input.next();
}
}
sl.addLast(recive);
System.out.println("-----------------------");
}
else if (item == 2) {
sl.traverse();
System.out.println("-----------------------");
}
PAGE-15
Unit19
else if (item == 3) {
sl.traverse();
if (sl.size() != 0) {
System.out.print("If you want to call last phone number, Enter
'3' : ");
int dial = input.nextInt();
sl.last();
System.out.println("-----------------------");
}
}
else if (item == 4) {
System.exit(0);
}
else {
while (item != 1 || item != 2 || item != 3) {
System.out.print("Pease enter number '1' or '2' or '3' or '4' : ");
int second = input.nextInt();
Q.Check(second);
}
}
}
In the check method, I created four conditions. First condition is to be store or
save the received calls. Second condition is to be review all calls. Third condition is to be
call a number according to received order. Last condition is to be exit from the system.
After finished implementing check method. User can choice options in the
program.
Solving the Third Problem to be Store the Receive Calls
In this problem, user want to store the data into the program. That why, I choose
singly linked list ADT because the singly linked list is a way to store a collection of items.
Each item in a linked list is stored in the form of a node. Therefore, first I created node
class.
package CallCenter;
PAGE-16
Unit19
PAGE-17
Unit19
}
public void setHead(Node<E> head) {
this.head = head;
}
public Node<E> getTail() {
return tail;
}
public void setTail(Node<E> tail) {
this.tail = tail;
}
public int size() {
return this.size;
}
}
When finish creating singly linked list class, created addLast method in the class
because user want to save the receive class.
public void addLast(String data) {
Node newest=new Node();
newest.setElement(data);
if(isEmpty()) {
head=newest;
tail=newest;
}
else
{ newest.setNext(null);
tail.setNext(newest);
tail=newest;
}
size++;
}
In the addLast method, I declared newest node variable and coded a condition. In
condition, if the list is empty, newest is assigned to head and tail. If the list is not empty,
next of the newest is created null and next of the tail is assigned newest. After that,
newest is assigned to the tail.
PAGE-18
Unit19
When finish creating addLast method, user can store the received phone numbers
into the program.
Solving the Fourth Problem to be Review All Calls
I created traverse method in singly linked list.
public void traverse() {
int count = 0;
if(isEmpty())
{
System.out.println("List is Empty");
}
while(head!=null) {
count += 1;
E data=head.getElement();
head=head.getNext();
System.out.println(count+". "+data+"");
}
}
In traverse method, created a condition. In that condition, I check list is empty or
not. If list is empty, I coded output message (list is empty). If list is not empty, created
while loop. In the while loop, compared head is not equal to null. If head is not equal to
null, head of the element is assigned to data variable and next of head assigned to head.
That why, all element is assigned to data and then I displayed that data.
When finish creating traverse method, user can see the phone numbers from the
program.
PAGE-19
Unit19
When finish creating last method, user can call last phone from the program.
Solving the Sixth Problem to be Exit from the System
I coded system exit.
else if (item == 4) {
System.exit(0);
}
PAGE-20
Unit19
The worst-case time of isEmpty method is the slowest of the two possibilities.
They are maximum time of true state and else state. For example, if true state is O(1)
and false state is O(1) the worst-case time for the whole if-then-else statement would be
O(N). isEmpty method run in constant time. In my implementation other methods run in
linear time on the size of the set. A less naive implementation could reduce these to
logarithmic time.
Space Complexity of IsEmpty Method
In isEmpty method, there is one flag variable. Boolean value is 1 bit. The space
complexity of isEmpty method is O(1).
Complexity of AddLast Method
public void addLast(String data) {
Node newest=new Node();
newest.setElement(data);
if(isEmpty()) {
head=newest;
tail=newest;
PAGE-21
Unit19
}
else
{ newest.setNext(null);
tail.setNext(newest);
tail=newest;
}
size++;
}
Time Complexity of AddLast Method
The worst-case time of addLast method is the slowest of the two possibilities. They
are maximum time of true state and else state. For example, if true state is O(N) and
false state is O(1) the worst-case time for the whole if-then-else statement would be
O(N).
Space Complexity of AddLast Method
In addLast method, there are newest, head, tail and size variables. Assuming 4
bytes for that variable, total space occupied by the program is 16bytes. So, the space
complexity of addLast method is O(n) or linear.
Complexity of Traverse Method
public void traverse() {
int count = 0;
if(isEmpty())
{
System.out.println("List is Empty");
}
while(head!=null) {
count += 1;
E data=head.getElement();
head=head.getNext();
System.out.println(count+". "+data+"");
}
}
Time Complexity of Traverse Method
In traverse method, if true state is O(1) and then while loop is N times, so the
sequence of statements also executes N times. Since, assuming the statements are O(1),
the total time for the for loop is N * O(1), which is O(N) overall.
PAGE-22
Unit19
In traverse method, there are count, data and head variables. Assuming 4 bytes for
that variable, total space occupied by the program is 12bytes. So, the space complexity
of addLast method is O(n) or linear.
Complexity of Last Method
The worst-case time of last method is the slowest of the two possibilities. They are
maximum time of true state and else state. For example, if true state is O(1) and false
state is O(1) the worst-case time for the whole if-then-else statement would be
O(N). Last method runs in constant time.
Space Complexity of Last Method
PAGE-23
Unit19
Asymptotic Analysis
Asymptotic analysis’s algorithm means to defining the mathematical foundation of
its run-time performance. If used asymptotic analysis, can be well the best-case,
average-case, and worst-case state of an algorithm. Asymptotic analysis is one of the
inputting bound procedure. For example, there is nothing input to algorithm, if is
concluded to work in a constant time. Other than the “input” all other factors are
considered constant. (TutorialsPoint, 2019)
There are three type of the time in asymptotic analysis,
Best-Case − Minimum time needed for processing.
Average-Case − Average time needed for processing.
Worst-Case − Maximum time needed for processing.
Best-Case Analysis
For the best-case analysis, the lower bound of a running time on an algorithm is
calculated. The case that can cause a minimum number of operations can be considered
as a best-case scenario. For example, in an operation like linear searching, the best case
is when the value searched is in the first position.
(TutorialsPoint, 2019)
Worst-Case Analysis
In worst-case analysis, can calculate upper bound on running time of an algorithm.
Need to know the problem that reasons maximum number of times to be executed. In
linear search, the worst-case occurs when the item to be searched (x in the above code)
is not current in the array. When x is not current, search () methods compares it with all
the items of array [] one by one. So, worst-case time complexity of linear search will be
Θ(n). (TutorialsPoint, 2019)
Average-Case Analysis
In average-case analysis, takes all possible inputs and calculate the time for all of
that inputs. Sum all the calculated values and divided the sum by total number of inputs.
Need to know distribution of problems. In linear search case, according to the algorithm,
all problems are uniformly distributed. That why, sum all the problems and divide the
sum by (n+1). Average-case time complexity is,
=
= Θ(n)
(Akanksha, 2019)
PAGE-24
Unit19
Asymptotic Notations
There are three asymptotic notations to calculate the running time complexity of an
algorithm.
1. Ο Notation
2. Ω Notation
3. θ Notation
Big Oh Notation, Ο
The notation Ο(n) is measuring the worst-case time complexity or the longest
amount of time an algorithm can possibly take to complete.
(TutorialsPoint, 2019)
Omega Notation, Ω
The notation Ω(n) is measuring the best-case time complexity or the best amount
of time an algorithm can possibly take to complete.
PAGE-25
Unit19
Ω(f(n)) ≥ {g(n): there exists c > 0 and n such that g(n) ≤ c.f(n) for all n > n . }
0 0
(TutorialsPoint, 2019)
Theta Notation, θ
The notation θ(n) is simple way to quickly both the lower bound and the upper
bound of an algorithm's running time.
θ(f(n)) = {g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n > n0.}
(TutorialsPoint, 2019)
PAGE-26
Unit19
Algorithm Efficiency
A measure of the average processing time essential for an algorithm to finish
perform on a set of information. Algorithm efficiency is characterized by its order.
Generally, a bubble sort algorithm will have complexity in sorting N elements
proportional to and of the order of N2, always written O(N2) because an average of N/2
comparisons are needed N/2 times, giving N2/4 total comparisons, later of the order of
N2. Otherwise, quicksort has an efficiency O (N log2N).
If 2 algorithms for the equal case are of the equal order then they are
approximately as efficient in terms of computation. Algorithm efficiency is useful for
counting the implementation try hard of sure cases. Two efficiency are very important for
performance in algorithm efficiency,
1. Space efficiency – space for memory, also known as space complexity.
2. Time efficiency – time for program, also known as time complexity.
(Encyclopedia, 2019)
Space Efficiency
Space efficiency is a method describing the total amount of memory space and
algorithm an algorithm gets in terms of the total amount of input to the algorithm. There
are some conditions where the space of memory used must be analyzed. For example, for
large amount of data. There are three kind of space efficiency,
1. Instruction space
2. Data space
3. Run-time stack space
Time Efficiency
Time efficiency is a method describing the total amount of time an algorithm gets
in terms of the total amount of input to the algorithm. Time can mean number of
memory accesses performed, the number of comparisons between integers, the number
of times some inner loop is executed, or some other natural unit related to the amount of
real time the algorithm will take. The actual running time depends on many factors,
The speed of CPU.
The compiler, compiler options.
The amount of memory space.
The actual data. Where the data is locating.
Example for Time and Space Efficiency
Let an array A and an integer x and then need to find x in the array. If x is there is
array A, the program will exit.
Simple solution to this case is traverse the whole array A and check if the any item is
equal to x.
PAGE-27
Unit19
for i : 1 to length of A
if A[i] is equal to x
return TRUE
return FALSE
Each of the operation in computer take approximately constant time. Let each
operation takes c time. The number of lines of code executed is actually depends on the
value of x. During analyses of algorithm, considering worst case scenario, for example,
when x is not present in the array A. In the worst-case, if condition will run N times
where N is the length of the array A. So, in the worst case, total execution time will be
(N ∗ c + c). N ∗ c for the if condition and c for the return statement (ignoring some
operations like assignment of i).
Example for Space Efficiency in Java
public static void main(String[] args) {
int a = 5, b = 5, c;
c = a + b;
System.out.println(c);
}
In this case, there are 3 variable a, b and c. The size of the integer is 2 or 4 bytes
which depends on the compiler. Current, the size as 4 bytes. So. The total space
occupied by the above-given program is 4*3 =12 bytes. Since no additional variables are
used, no extra space is needed
Example for Time Efficiency in Java
public static void main(String[] args) {
int i, n = 8;
for (i = 1; i <= n; i++) {
System.out.println("Hello Word !!!");
}
}
In this case, “Hello World!!!” will print N times. So, time complexity of above code
is O(N).
PAGE-28
Unit19
M5 Interpret what a trade-off is when specifying an ADT using an example to support your
answer.
PAGE-29
Unit19
PAGE-30
Unit19
References
Akanksha, R., 2019. www.geeksforgeeks.or. [Online]
Available at: https://www.geeksforgeeks.org/analysis-of-algorithms-set-2-asymptotic-
analysis/
[Accessed 1 2 2020].
Encyclopedia, 2019. www.encyclopedia.com. [Online]
Available at: https://www.encyclopedia.com/computing/dictionaries-thesauruses-
pictures-and-press-releases/algorithm-efficiency
[Accessed 1 2 2020].
TutorialsPoint, 2019. TutorialsPoint. [Online]
Available at:
https://www.tutorialspoint.com/data_structures_algorithms/asymptotic_analysis.htm
[Accessed 22 2 2020].
PAGE-31