Wednesday, October 7, 2009

Packages

Nellen Grace C. Ortiz
Analyn S. Obal


1. The purpose of packages is to group the classes into a subsystem. Packages serves as containers for the classes or use cases such as class diagram, sequence diagram and so on..




Reference: http://vinci.org/uml/packagex.html

2. Component diagram shows the components of the system and how they are related to the system, while class diagram is shows the association and inheritance and do not represent any particular processing.


• A simple example showing 3 dependent components
• The Web browser communicates customer orders to a shopping cart
• The shopping cart accesses a database for persistence and for transactions



Reference: http://vinci.org/uml/componentx.html








3. The deployment diagram it shows how the component of the system are physically related and it illustrate the physical implementation of the system, including the hardware, the relationship between the hardware, and the system on which it is deployed.



• Captures the distinct number of computers involved
• Shows the communication modes employed
• Component diagrams can be embedded into deployment diagrams effectively




Reference: http://vinci.org/uml/deploymentx.html


4. Steps in putting UML to work:

A.) Defining the use case model.

• Find the actors domain problem by reviewing
• Identify the major events and develop a set of primary cases.
• Refine the primary use cases to develop a detailed description of a system
• Review the use case scenarios with the business area


B.) UML diagramming system analysis phase.

• Derive activity from use case diagrams.
• Develop sequence and collaboration diagram from scenarios.
• Review the sequence diagram with the businesses area..

C.) Develop the class diagrams.

• Look for noun in use cases.
• Define the major relationships between the classes.
• “Has a” and “is a” relationships between class.
• Examine use case and sequence diagrams to determine the class.
• Create class diagrams that show the classes and relationships that exist in the use case.

D.) Draw state chart diagrams.

• Develop state chart diagrams to aid in understanding complex process.
• Determine method by examining state chart diagrams, Derive state, Attributes of the class are public (accessible externally), Private – internal to the class.
.

E.) Begin systems design by refining UML diagrams

• Write class specifications.
• Develop methods specifications of input and output requirements for the method.
• Create set of sequence diagrams.
• Create class diagrams using specialized class symbols.
• Analyze the class diagrams derived system components.



5. UML is important for modeling because it communicates and describes design concepts. It has a great and powerful quantity of the systems analysis and it also useful tool in the design toolbox.

Sunday, March 22, 2009

Sorting Algorithms

1.) Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be sorted, comparing two items at a time and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

First Pass:
( 5 1 4 2 8 ) ---> ( 1 5 4 2 8 ) Here, algorithm compares the first two elements,
and swaps them.
( 1 5 4 2 8 ) ---> ( 1 4 5 2 8 )
( 1 4 5 2 8 ) ---> ( 1 4 2 5 8 )
( 1 4 2 5 8 ) ---> ( 1 4 2 5 8 ) Now, since these elements are already in order,
algorithm does not swap them.
Second Pass:
( 1 4 2 5 8 ) ---> ( 1 4 2 5 8 )
( 1 4 2 5 8 ) ---> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) ---> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) ---> ( 1 2 4 5 8 )
Now, the array is already sorted, but our algorithm does not know if it is completed.
Algorithm needs one whole pass without any swap to know it is sorted.
Third Pass:
( 1 2 4 5 8 ) ---> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) ---> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) ---> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) ---> ( 1 2 4 5 8 )
Finally, the array is sorted, and the algorithm can terminate.

[wiki] http://en.wikipedia.org/wiki/Bubble_sort

2.) Insertion sort- is a simple sorting algorithm that is relatively efficient for small lists and mostly-sorted lists, and often is used as part of more sophisticated algorithms. It works by taking elements from the list one by one and inserting them in their correct position into a new sorted list. In arrays, the new list and the remaining elements can share the array's space, but insertion is expensive, requiring shifting all following elements over by one.


http://web.syr.edu/~tjhaskel/hmk8a.gif


web.syr.edu/~tjhaskel/hmk8a.gif

image from: web.syr.edu/~tjhaskel/

[wiki] http://en.wikipedia.org/wiki/Sorting_algorithm#Insertion_sort


3.) Shell sort- was invented by Donald Shell in 1959. It improves upon bubble sort and insertion sort by moving out of order elements more than one position at a time. One implementation can be described as arranging the data sequence in a two-dimensional array and then sorting the columns of the array using insertion sort. Although this method is inefficient for large data sets, it is one of the fastest algorithms for sorting small numbers of elements (sets with fewer than 1000 or so elements). Another advantage of this algorithm is that it requires relatively small amounts of memory.

http://oopweb.com/Algorithms/Documents/Sman/Volume/ShellSort_files/title_data/fig22.gif
26 x 284 - 4k - gif - oopweb.com/.../title_data/fig22.gif

image at: www.oopweb.com/.../Sman/Volume/ShellSort.html

[wiki] http://en.wikipedia.org/wiki/Sorting_algorithm#Shell_sort

4.) Merge sort- takes advantage of the ease of merging already sorted lists into a new sorted list. It starts by comparing every two elements (i.e., 1 with 2, then 3 with 4...) and swapping them if the first should come after the second. It then merges each of the resulting lists of two into lists of four, then merges those lists of four, and so on; until at last two lists are merged into the final sorted list.

http://upload.wikimedia.org/wikipedia/commons/6/60/Mergesort_algorithm_diagram.png


upload.wikimedia.org/wikipedia/commons/6/60/M...

image at: commons.wikimedia.org/wiki/File:Mergesort_alg...

[wiki] http://en.wikipedia.org/wiki/Sorting_algorithm#Merge_sort

5.) Heapsort- is a much more efficient version of selection sort. It also works by determining the largest (or smallest) element of the list, placing that at the end (or beginning) of the list, then continuing with the rest of the list, but accomplishes this task efficiently by using a data structure called aheap, a special type of binary tree. Once the data list has been made into a heap, the root node is guaranteed to be the largest element. When it is removed and placed at the end of the list, the heap is rearranged so the largest element remaining moves to the root. Using the heap, finding the next largest element takes O(log n) time, instead of O(n) for a linear scan as in simple selection sort. This allows Heapsort to run in O(n log n) time.

http://upload.wikimedia.org/wikipedia/commons/thumb/6/64/HeapsortSampleBefore.svg/625px-HeapsortSampleBefore.svg.png

625 x 375 - 23k - png - upload.wikimedia.org/wikipedia/commons/thumb/...

image at: commons.wikimedia.org/wiki/File:HeapsortSampl...

[wiki] http://en.wikipedia.org/wiki/Sorting_algorithm#Heapsort

6.) Quicksort is a divide and conquer algorithm which relies on a partition operation: to partition an array, we choose an element, called a pivot, move all smaller elements before the pivot, and move all greater elements after it. This can be done efficiently in linear time andin-place We then recursively sort the lesser and greater sublists. Efficient implementations of quicksort (with in-place partitioning) are typically unstable sorts and somewhat complex, but are among the fastest sorting algorithms in practice.

http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/Database/algorithm/Quick_Sort?action=download&value=quick.png

295 x 281 - 8k - www.joinc.co.kr/modules/moniwiki/wiki.php/Sit...

image at: teamblog.joinc.co.kr/yundream/127

[wiki] http://en.wikipedia.org/wiki/Sorting_algorithm#Quicksort

7.) Bucket sort, or bin sort, is a sorting algorithm that works by partitioning an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm. It is a cousin of radix sort in the most to least significant digit flavour. Since bucket sort is not a comparison sort, the Ω(n log n) lower bound is inapplicable. Estimates involve the number of buckets.

http://upload.wikimedia.org/wikipedia/commons/6/61/Bucket_sort_1.png

11 x 131 - 4k - png - upload.wikimedia.org/.../6/61/Bucket_sort_1.png

image at: commons.wikimedia.org/wiki/File:Bucket_sort_1.png

[wiki] http://en.wikipedia.org/wiki/Sorting_algorithm#Bucket_sort

Thursday, March 12, 2009

QUEUE IMPLEMENTATION

Thursday, March 12, 2009


/* Programmer’s name: Ortiz, Nellen
Name of Program: Queue implementation
Date Started: March 9, 2009
Date Finished : March 12, 2009
Instructor : Mr. Dony Dongiapon
Course: IT 123: Data Structures
Objective: To be able to make a program that implements a queue data structure in a linked list */



Concept: List of Courses Offered in the College

//class constructor
class Queue{
public int coursenum;
public String coursename;
public int unitnum;
public String deptname;
public Queue next;


public Queue (int Cnum, String Cname, int Unum, String Dname; )
{

coursenum=Cnum;
coursename=Cname;
unitnum=Unum;
deptname=Dname;
}


//displaying the elements on the list
public void displayQueue()
{
System.out.print(coursenum +” “ + deptname +” “ +” “+unitnum+ “ “ +: + coursename)
}
}


/*a separate class which contains the ,methods that would be used in implementing the program */
class QueueList
private Queue first;
private Queue last;
public QueueList()
{
first=null;
last=null;
}


//checking if the queue has elements
public Boolean isEmpty()
{
return (first==null);
}

//inserting an element on the queue
public void Enqueue(int Cnum, String Cname, int Unum, String Dname; )

{
Queue newQueue= new Queue (int Cnum, String Cname, int Unum, String Dname )

if( isEmpty())
last = newQueue;
newQueue.next=first;
first=newQueue;
}


//deleting an element on the queue
public void Dequeue (int Cnum)
{
Queue newQueue=new Queue (int Cnum, String Cname, int Unum, String Dname )

int temp=first.entrynum;
if (first.next==null)
last=null;
first=first.next;
return temp


}
}


public class MainClass {
public static void main(String[] args) {
LinkQueue theQueue = new LinkQueue();
theQueue.enqueue(1, “BSIT”, 118, “ICSD” )

theQueue.enqueue(2, “BSN”, 368, “ND”);
System.out.println(theQueue);

theQueue.dequeue(2);

System.out.println(theQueue);



System.out.println(theQueue);
}

Tuesday, February 24, 2009

Queue

Definition






Illustration



Tuesday, February 17, 2009

Double Ended Linked list


Definition:
It allows for insertions in the front or in the back of the list. Each type of link list will build off of the previous one. First we'll examine the singly linked list before moving onto the double-ended and doubly linked lists. [safari books]


Doubly-ended Implementation :

class Link
{
public int iData;
public double dData:
public Link next;

public Link(int id,double dd)
{
iData = id;
dData=dd;
}

public void displayLink()
{
System.out.print("{"+iData+","dData+"}");
}
}

class DoubleEndList
{
private Link first;
private Link last;


public DoubleEndList()
{
first = null;
last = null;
}


public boolean isEmpty()
{
return (first == null);
}

public void insertFirst(int id,double dd)
{
Link newLink = new Link(id,dd);

if (isEmpty ())
last = newLink;
newLink.next = first;

first = newLink;
}

//inserting a node on the last
public void insertLast(int id,double dd)
{
Link newLink = new Link(id,dd);
if (isEmpty())
first = newLink;
else
last.next = newLink;
last = newLink;
}

public Link deleteFirst(int id,double dd)
{
int temp = first.iData;
if (first.next == null)
last = null;
first = first.next;
return temp;
}


public Link deleteLast(int id, double dd)
{
int temp=last.iData;
if(last.next==null)
first=null;
last=last.next;
return temp;
}


public void displayList()
{
System.out.print("List(first-->Last);");
Link current=first;
while(current!=null)
{
current.displayLink();
current=current.next;
}
}
System.out.println(" ");
}

public class DoubleEndApp
{
public static void main(String[] args)
{

DoubleEndList theList = new DoubleEndList();

//apply the insertion methods on the first and the last node
theList.insertFirst(12,2.55);
theList.insertFirst(21,4.55);
theList.insertFirst(67,8.99);
theList.insertLast(18,9.99);
theList.insertLast(43,3.33);
theList.insertLast(34,5.66);

System.out.println(theList);

theList.deleteFirst();
theList.deleteLast();
System.out.println(theList);
}
}

Illustrations


Reference:
[safari books] http://my.safaribooksonline.com/30000LTI00162/ch05lev1sec2

DOUBLY LINKED LIST

A) Definition

  • It is convenient to traverse lists backwards and the implementation does not here but the solution is simple.[1]
  • It contains a pointer to the previous cell, extra link,which adds to the space requirement and doubles the cost of insertions and deletions. It simplifies deletion, because you no longer have to refer to a key by using pointer to the previous cell.[1]

B) Illustration



Java Codes:

class Link
{
public int iData;
public Link next;
public Link previous;
public Link(int id)
{
iData = id;
}


public void displayList()
{
return "{" + iData + "} ";
}
}


class DoublyLinkedList
{
private Link first;
private Link last;

public DoublyLinkedList()
{
first = null;
last = null;
}

public boolean isEmpty()
{
return first == null;
}

public void insertFirst(int dd)
{
Link newLink = new Link(dd);

if (isEmpty())
{
last = newLink;
}else{
first.previous = newLink;
}
newLink.next = first;
first = newLink;
}

public void insertLast(int dd)
{
Link newLink = new Link(dd);
if (isEmpty())
{
first = newLink;
}else{
last.next = newLink;
newLink.previous = last;
}
last = newLink;
}

public Link deleteFirst()
{
Link temp = first;
if(first.next == null)
{
last = null;
}else{
first.next.previous = null;
}
first = first.next;
return temp;
}

public Link deleteLast()
{
Link temp = last;
if(first.next == null)
{
first = null;
}else{
last.previous.next = null;
}
last = last.previous;
return temp;
}

public boolean insertAfter(int key, int dd)
{
Link current = first;
while (current.iData != key)
{
current = current.next;
if (current == null)
{
return false;
}
}
Link newLink = new Link(dd);
if (current == last)
{
newLink.next = null;
last = newLink;
}else{
newLink.next = current.next;
current.next.previous = newLink;
}
newLink.previous = current;
current.next = newLink;
return true;
}

public Link deleteKey(int key)
{
Link current = first;
while (current.iData != key)
{
current = current.next;
if (current == null)
return null;
}
if (current == first)
{
first = current.next;
}else{
current.previous.next = current.next;
}
if (current == last)
{
last = current.previous;
}else{
current.next.previous = current.previous;
}
return current;
}
}

// the main method
public class DoublyLinkedApp
{
public static void main(String[] args)
{
DoublyLinkedList theList = new DoublyLinkedList();

theList.insertFirst(2);
theList.insertFirst(44);
theList.insertFirst(66);
theList.insertLast(11);
theList.insertLast(3);
theList.insertLast(55);

System.out.println(theList);

theList.deleteFirst();
theList.deleteLast();
theList.deleteKey(11);
System.out.println(theList);

theList.insertAfter(2, 77);
theList.insertAfter(3, 88);
System.out.println(theList);
}
}

C) Reference

[1]Data Structures and Algorithm Analysis in C; Mark Allen Weiss; Florida International University

[wiki] http://en.wikipedia.org/wiki/Linked_list#Doubly-linked_list

Monday, February 2, 2009

Stack

Concept

According to wikipedia  a stack is an abstack data type and its based on the principle of Last In First Out(LIFO).It is uesd to run a Java Virtual Machine,it is ubiquitous.

Basic Operations

Push-adds a given node to the top .
Pop- removes and returns the current top node.
top(peek)- can return the current top element.


some environments
*Dup(licate)- the top item is popped and pushed again.
*peek- the topmost item is popped.
*Swap or exchange- the two topmost items exchange places.
*rotate- the topmost items are moved in a rotating fashion.
[wiki]





B)Illustration

illustration of Stack[3]

C)References
http://en.wikipedia.org/wiki/File:Data_stack.svg
http://en.wikipedia.org/wiki/Stack_(data_structure)



Implementation of Stack


class Link{
public int iData=0;


public Link(int iData, )
{
iData=id;

}

public void displayLink()
{
System.out.println(iData+":" );
}
}

class StackList{
private Link first;

public StackList(){
first=null;

}

public boolean isEmpty() {
return (first == null);
}

public void insertFirst( int id) {
Link newLink = new Link( id);
newLink.next = first;
first = newLink;
}

public Link deleteFirst()
{
Link temp=first;
return temp;
}

public Link pick()
{
Link temp=first;
return temp;
}

public void displayList
{
System.out.print("Elements on the stack: ");
Link temp=first;
while(temp!=null)
{
temp.displayList();
}

System.out.println(" ");
}
}


class StackListApp
{
public static void main (String[]args)
{
StackList theList=new StackList();

theList.insertFirst(12);
theList.insertFirst(25);
theList.insertFirst(91);


theList.deleteFirst();

theList.displayList();
}
}