Académique Documents
Professionnel Documents
Culture Documents
Unit 1
1. Write about Asymptotic Notations
2. Describe Linear and Non Linear Data Structures
3. Write a program to explain Singly Linked List
4. Write a program to explain Doubly Linked List
5. Explain in detail about Sparse Matrices
6. Describe Two dimensional Arrays
7. Explain in detail about Circular Lists
Unit 2
1. Write about Stacks and Queues
2. Describe Infix to postfix conversion
3. Write a program to explain Max Heap
4. Write a program to explain DeQueue
5. Explain in detail about Priority Queue ADT
6. Describe Circular Queues
7. Explain in detail about Vector Classes
Unit 3
1. Write about Linear and Binary Search Methods
2. Describe Hashing Techniques
3. Write a program to explain Quick Sort
4. Write a program to explain Merge Sort
5. Explain in detail about Comparisons of Sorting Methods
UNIT 1
Contents:
1. Explain in detail about an Algorithm
An algorithm is a finite set of instructions that is followed accomplishes a particular task. (or)
an algorithm is a step-by-step process of solving a particular problem. The algorithm must
satisfy the following criteria.
Input: zero ore more quantities are exactly supplied.
Output: At least one quantity is produced.
Definiteness: Each instruction is clear and unambiguous.
Finiteness: The algorithm should be finite that means after a finite number of steps it should
terminate.
Effectiveness: Every step of the algorithm should be feasible.
Ex: algorithm to count the sum of n numbers
Algorithm sum (1,n)
{
Result:=0;
For i:=1 to n do i:=i+1;
result:=result + i;
}
2. Describe Performance Analysis in detail?
The efficiency of an algorithm can be decided by measuring the performance of an
algorithm. We can measure the performance of an algorithm by computing the amount of
time and storage requirement.
2.1 Space Complexity:
The space complexity can be defined as amount of memory required by an algorithm to
run.
To compute the space complexity we use two factors: constant and instance characteristic.
}
requires n units for a, plus space for n, r and i, so it's O(n)
2.2 Time Complexity:
The time complexity of an algorithm is the amount of computer time required by analgorithm
to run to completion.
There are two types of computing time- compile time and rum time. The timecomplexity is
generally computed using run time or execution time.
It is difficult to compute the time complexity in terms of physically clocked time. Forinstance
in multiuser system, executing time depends on many factors such as systemload, number
of other programs running, instruction set used.
The time complexity is therefore given in terms of frequency count.
Frequency count is basically a count denoting number of times of execution ofstatement.
Ex:
Algorithm sum(A,B,C,m,n)frequencytotal
{ -For i:= 1 to m dom+1m+1
For j:= 1 to n dom(n+1)m(n+1)
C[i,j]:= A[I,j] B[ i,j];mnmn
}-2mn+2m+1
So the time complexity of above algorithm is mn by neglecting the constants.
3) Explain in detail about Asymptotic Notations?
Measuring Efficiency is depend upon the following
When algorithm is applied to a large data set, will finish relatively quickly.
Speed and memory usage
Measuring speed-we measure algorithm speed in terms of Operations relative to input size.
Big O Notation
Definition: Let f(x) and g(x) be two functions; We say thatf(x) (O(g(x))
if there exists a constant c, Xo > 0 such that f(x)c*g(x) for all X Xo.
Big-Omega Notation:
Definition: Letf (x)andg(x) be two functions; We say thatf(x) (((g(x))
if there exists a constant c, Xo 0such that f(x) c*g(x) for all X Xo
f(x) is asymptotically greater than or equal to g(x)
Big-Omega gives an asymptotic lower bound
Big Notation:
Definition: Let f(x) and g(x) be two functions ; We say thatf(x) (((g(x)) if there exists a
constant c1, c2, Xo > 0; such that for every integer x ( x0 we have c1g(x) f(x) c2g(x)
F(x) is asymptotically equal to g(x)
F(x) is bounded above and below by g(x)
Big-Theta gives an asymptotic equivalence
are due to the difficulty in insertion and deletion at the beginning of the array since it takes
time O(n).
A completely different way to represent a list is to make each item in the list part of a
structure that also contains a link to the structure containing the next item as shown in the
following fig, this type of list is called a linked list, because it is a list whose order is given by
links from one to the next.
Types of Linked Lists:
Basically there are four types of linked list
single linked list
doubly linked list
circular linked list
circular doubly linked list
Single Linked List: the simplest kind of linked list is a single linked list, which hasone link
per node. This link points to the next node in the list or to a null value if it is the finalnode.
Doubly Linked List: a more sophisticated kind of linked list is a doubly linked list or
two way linked list. Each node has two links:
One of them points to previous node or points to a null value if it is the first node.
The other points to the next node or points to a null value if it is a final node.
Circular Linked List: in this, the first and the final nodes are linked together. In fact in
a singly circular linked list each node has one link. Similarly, to an ordinary singly linked list,
except that the next link of the last node points to the first node.
Circular Doubly Linked List: in this, each mode has two links, similarly to doubly
linked list, except that the previous link of the first node points to the last node and the next
The so-called static list structures allow only inspection and enumeration of the values. A
HYPERLINK "http://en.wikipedia.org/wiki/Mutable_object" \o "Mutable object"mutable or
dynamic list may allow items to be inserted, replaced, or deleted during the list's existence.
Linear List Array Representation
Use a one-dimensional array element[]
L = (a, b, c, d, e)
Store element i of list in element[i].
A java Program for Array Representation of Linear List
A List Interface
public interface List
{
public void createList(int n);
public void insertFirst(Object ob);
public void insertAfterbjectob, Object pos);
(O public Object deleteFirst();
public Object deleteAfter(Object pos);
publicbooleanisEmpty();
publicintsize();
}
An ArrayListClass
classArrayListimplements List
{
classNode
{ Object data;
int next;
Node(Object ob, inti) // constructor
{ data = ob;
next = i;
}
}
int MAXSIZE; // max number of nodes in the list
Node list[]; // create list array
int head, count; // count: current number of nodes in the list
ArrayList(int s) // constructor
{ MAXSIZE = s;
list = new Node[MAXSIZE];
}
public void initializeList()
{ for( int p = 0; p < MAXSIZE-1; p++ )
list[p] = new Node(null, p+1);
list[MAXSIZE-1] = new Node(null, -1);
}
public void createList(int n) // create n nodes
{ int p;
for( p = 0; p < n; p++ )
{
list[p] = new Node(11+11*p, p+1);
count++;
}
list[p-1].next = -1; // end of the list
}
public void insertFirst(Object item)
{
if( count == MAXSIZE )
{ System.out.println("***List is FULL");
return;
}
int p = getNode();
if( p != -1 )
{
list[p].data = item;
if(isEmpty() ) list[p].next = -1;
else list[p].next = head;
head = p;
count++;
}
}
public void insertAfter(Object item, Object x)
{
if( count == MAXSIZE )
{ System.out.println("***List is FULL");
return;
}
int q = getNode(); // get the available position to insert new node
int p = find(x); // get the index (position) of the Object x
if( q != -1 )
{ list[q].data = item;
list[q].next = list[p].next;
list[p].next = q;
count++;
}
}
publicintgetNode() // returns available node index
{ for( int p = 0; p < MAXSIZE; p++ )
}
int q = list[p].next;
Object tmp = list[q].data;
list[p].next = list[q].next;
count--;
returntmp;
}
public void display()
{ int p = head;
System.out.print("\nList: [ " );
while( p != -1)
{ System.out.print(list[p].data + " "); // print data
p = list[p].next; // advance to next node
}
System.out.println("]\n");//
}
publicbooleanisEmpty()
{ if(count == 0) return true;
else return false;
}
publicintsize()
{ return count; }
}
Testing ArrayListClass
classArrayListDemo
{
public static void main(String[] args)
{
ArrayListlinkedList = new ArrayList(10);
linkedList.initializeList();
linkedList.createList(4); // create 4 nodes
linkedList.display(); // print the list
System.out.print("InsertFirst 55:");
linkedList.insertFirst(55);
linkedList.display();
System.out.print("Insert 66 after 33:");
linkedList.insertAfter(66, 33); // insert 66 after 33
linkedList.display();
Object item = linkedList.deleteFirst(); System.out.println("Deleted node: " + item);
linkedList.display();
System.out.print("InsertFirst 77:");
linkedList.insertFirst(77);
linkedList.display();
item = linkedList.deleteAfter(22); // delete node after node 22
System.out.println("Deleted node: " + item);
linkedList.display();
System.out.println("size(): " + linkedList.size());
}
}
b) Linked Representation
Let L = (e1,e2,,en)
Each element ei is represented in a separate node
Each node has exactly one link field that is used to locate the next element in the linear list
The last node, en, has no node to link to and so its link field is NULL.
This structure is also called a chain.
A LinkedListClass
classLinkedListimplements List
{
classNode
{ Object data; // data item
Node next; // refers to next node in the list
Node( Object d ) // constructor
{ data = d; } // next is automatically set to null
}
Node head; // head refers to first node
Node p; // p refers to current node
int count; // current number of nodes
public void createList(int n) // create 'n' nodes
{
p = new Node(11); // create first node
head = p; // assign mem. address of 'p' to 'head'
for(inti = 1; i< n; i++ ) // create 'n-1' nodes
p = p.next = new Node(11 + 11*i);
count = n;
}
public void insertFirst(Object item) // insert at the beginning of list
{
p = new Node(item); // create new node
p.next = head; // new node refers to old head
head = p; // new head refers to new node
count++;
}
public void insertAfter(Object item,Object key)
{
p = find(key); // get location of key item
if( p == null )
System.out.println(key + " key is not found");
else
{ Node q = new Node(item); // create new node
q.next = p.next; // new node next refers to p.next
p.next = q; // p.next refers to new node
count++;
}
}
public Node find(Object key)
{
p = head;
while( p != null ) // start at beginning of list until end of list
{
if(p.data == key ) return p; // if found, return key address
p = p.next; // move to next node
}
return null; // if key search is unsuccessful, return null
}
public Object deleteFirst() // delete first node
{
if(isEmpty() )
{ System.out.println("List is empty: no deletion");
return null;
}
Node tmp = head; // tmpsaves reference to head
head = tmp.next;
count--;
returntmp.data;
}
public Object deleteAfter(Object key) // delete node after key item
{ p = find(key); // p = location of key node
if( p == null )
{ System.out.println(key + " key is not found");
return null;
}
if(p.next == null ) // if(there is no node after key node)
{ System.out.println("No deletion");
return null;
}
else
{ Nodetmp = p.next; // save node after key node
p.next = tmp.next; // point to next of node deleted
count--;
returntmp.data; // return deleted node
}
}
public void displayList()
{ p = head; // assign mem. address of 'head' to 'p'
System.out.print("\nLinked List: ");
while( p != null ) // start at beginning of list until end of list
{ System.out.print(p.data + " -> "); // print data
p = p.next; // move to next node
}
System.out.println(p); // prints 'null'
}
publicbooleanisEmpty() // true if list is empty
{ return (head == null); }
publicint size()
{ return count; }
} // end of LinkeList class
Testing LinkedListClass
classLinkedListDemo
{ public static void main(String[] args)
{ LinkedList list = new LinkedList(); // create list object
list.createList(4); // create 4 nodes
list.displayList();
list.insertFirst(55); // insert 55 as first node
list.displayList();
list.insertAfter(66, 33); // insert 66 after 33
list.displayList();
Object item = list.deleteFirst(); // delete first node
if( item != null )
{ System.out.println("deleteFirst(): " + item);
list.displayList();
}
item = list.deleteAfter(22); // delete a node after node(22)
if( item != null )
{ System.out.println("deleteAfter(22): " + item);
list.displayList();
}
Linked lists are among the simplest and most common data structures. They can be used
to implement several other common HYPERLINK
"http://en.wikipedia.org/wiki/Abstract_data_type" \o "Abstract data type"abstract data types,
including HYPERLINK "http://en.wikipedia.org/wiki/List_%28abstract_data_type%29" \o
"List (abstract data type)"lists (the abstract data type), HYPERLINK
"http://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29" \o "Stack (abstract data
type)"stacks, HYPERLINK
"http://en.wikipedia.org/wiki/Queue_%28abstract_data_type%29" \o "Queue (abstract data
type)"queues, HYPERLINK "http://en.wikipedia.org/wiki/Associative_array" \o "Associative
array"associative arrays, and HYPERLINK "http://en.wikipedia.org/wiki/S-expression" \o "Sexpression"S-expressions, though it is not uncommon to implement the other data
structures directly without using a list as the basis of implementation.
The principal benefit of a linked list over a conventional HYPERLINK
"http://en.wikipedia.org/wiki/Array_data_structure" \o "Array data structure"array is that the
list elements can easily be inserted or removed without reallocation or reorganization of the
entire structure because the data items need not be stored contiguously in memory or on
disk. Linked lists allow insertion and removal of nodes at any point in the list, and can do so
with a constant number of operations if the link previous to the link being added or removed
is maintained during list traversal.
On the other hand, simple linked lists by themselves do not allow HYPERLINK
"http://en.wikipedia.org/wiki/Random_access" \o "Random access"random access to the
data, or any form of efficient indexing. Thus, many basic operations such as obtaining
the last node of the list (assuming that the last node is not maintained as separate node
reference in the list structure), or finding a node that contains a given datum, or locating the
place where a new node should be inserted may require scanning most or all of the list
elements.
Program:
import java.lang.*;
import java.util.*;
public class Node
{
Node data;
node next;
}
public class SinglyLinkeList
{
Node start;
int size;
public SinnglyLinkedList()
{
start=null;
size=0;
}
public void add(Node data)
{
if(size=0)
{
start=new Node();
start.next=null;
start.data=data;
}
else
{
Node currentnode=getnode(size-1);
Node newnode=new Node();
newnode.data=data;
newnode.next=null;
currentnode.next=newnode;
}
size++;
}
Node tempnode=getNodeAt(position-1);
Node newnode= new Node();
newnode.data=data;
newnode.next=tempnode.next;
size++;
}
}
public Node getFirst()
{
return getNodeAt(0);
}
public Node getLast()
{
return getNodeAt(size-1);
}
public Node removeAtFirst()
{
if(size==0)
{
System.out.println("Empty List ");
}
else
{
Node tempnode=getNodeAt(position-1);
Node data=tempnode.next.data;
tempnode.next=tempnode.next.next;
size--;
return data;
}
}
Node data=start.data;
start=start.next;
size--;
return data;
}
}
public Node removeAtLast()
{
if(size==0)
{
System.out.println("Empty List ");
}
else
{
Node data=getNodeAt(size-1);
Node data=tempnode.next.data;
size--;
return data;
}
}
public string void main(string[] args)
{
LinkedList l1=new LinkedList();
BufferReader bf=new BufferReader(new InputStreamReader(Sysyem.in));
str.readline();
string str1;
str1.readline();
l1.insertAt(str,str1);
System.out.println("Linked List after inserting at particular Position :"+l1);
break;
case 5: System.out.println("Linked LIst before removing front element: "+l1);
System.out.println("Linked List after removing front element : ");
l1.removeAtFirst();
break;
case 6: System.out.println("Linked List before removing last element: "+l1);
System.out.println("Linked List after removing last element :");
l1.removeAtLast();
default:break;
}
}
}
7) Explain in detail about Double Linked List with a java program?
A more sophisticated kind of linked list is a doubly linked list or two way linked list. Each
node has two links:
One of them points to previous node or points to a null value if it is the first node.
The other points to the next node or points to a null value if it is a final node.
a doubly-linked list is a HYPERLINK "http://en.wikipedia.org/wiki/Linked_data_structure" \o
"Linked data structure"linked data structure that consists of a set of sequentially linked
HYPERLINK "http://en.wikipedia.org/wiki/Record_%28computer_science%29" \o "Record
The two node links allow traversal of the list in either direction. While adding or removing a
node in a doubly-linked list requires changing more links than the same operations on a
singly linked list, the operations are simpler and potentially more efficient (for nodes other
than first nodes) because there is no need to keep track of the previous node during
traversal or no need to traverse the list to find the previous node, so that its link can be
modified.
Program:
class Link
{
public long dData;
// data item
public Link next;
// next link in list
public Link previous;
// previous link in list
// ------------------------------------------------------------public Link(long d)
// constructor
{ dData = d; }
// ------------------------------------------------------------public void displayLink()
// display this link
{ System.out.print(dData + " "); }
// ------------------------------------------------------------} // end class Link
class DoublyLinkedList
{
private Link first;
// ref to first item
private Link last;
// ref to last item
// ------------------------------------------------------------public DoublyLinkedList()
// constructor
{
first = null;
// no items on list yet
last = null;
}
// ------------------------------------------------------------public boolean isEmpty()
// true if no links
{ return first==null; }
// ------------------------------------------------------------public void insertFirst(long dd) // insert at front of list
{
Link newLink = new Link(dd); // make new link
if( isEmpty() )
last = newLink;
// if empty list,
// newLink <-- last
else
first.previous = newLink; // newLink <-- old first
newLink.next = first;
// newLink --> old first
first = newLink;
// first --> newLink
}
// ------------------------------------------------------------public void insertLast(long dd) // insert at end of list
{
Link newLink = new Link(dd); // make new link
if( isEmpty() )
// if empty list,
first = newLink;
// first --> newLink
else
{
last.next = newLink;
// old last --> newLink
newLink.previous = last; // old last <-- newLink
}
last = newLink;
// newLink <-- last
}
// ------------------------------------------------------------public Link deleteFirst()
// delete first link
{
// (assumes non-empty list)
Link temp = first;
if(first.next == null)
// if only one item
last = null;
// null <-- last
else
first.next.previous = null; // null <-- old next
first = first.next;
// first --> old next
return temp;
}
// if last link,
// newLink --> null
// newLink <-- last
else
// not last link,
{
newLink.next = current.next; // newLink --> old next
// newLink <-- old next
current.next.previous = newLink;
}
newLink.previous = current; // old current <-- newLink
current.next = newLink;
// old current --> newLink
return true;
// found it, did insertion
}
// ------------------------------------------------------------public Link deleteKey(long key) // delete item w/ given key
{
// (assumes non-empty list)
Link current = first;
// start at beginning
while(current.dData != key) // until match is found,
{
current = current.next; // move to next link
if(current == null)
return null;
// didn't find it
}
if(current==first)
// found it; first item?
first = current.next;
// first --> old next
else
// not first
// old previous --> old next
current.previous.next = current.next;
if(current==last)
// last item?
last = current.previous; // old previous <-- last
else
// not last
// insert at front
theList.insertLast(11);
theList.insertLast(33);
theList.insertLast(55);
// insert at rear
} // end main()
} // end class DoublyLinkedApp
7) Explain in detail about Circular List?
Circular list
In general, the last HYPERLINK
"http://en.wikipedia.org/wiki/Node_%28computer_science%29" \o "Node (computer
science)"node of a list, the link field often contains a null reference, a special value used to
indicate the lack of further nodes. A less common convention is to make it point to the first
node of the list; in that case the list is said to be circular or circularly linked; otherwise it is
said to be open or linear.
In the case of a circular doubly linked list, the only change that occurs is that the end, or
"tail", of the said list is linked back to the front, or "head", of the list and vice versa.
Performance
1. The advantage is that we no longer need both a head and tail variable to keep track of
the list. Even if only a single variable is used, both the first and the last list elements can
be found in constant time. Also, for implementing queues we will only need one pointer
namely tail, to locate both head and tail.
2. The disadvantage is that the algorithms have become more complicated.
Basic Operations on a Circular Linked List
Insert Inserts a new element at the end of the list.
Delete Deletes any node from the list.
Find Finds any node in the list.
Print Prints the list.
A Java Program:
import java.lang.*;
import java.util.*;
import java.io.*;
class SLinkedCircularList
{
private int data;
private SLinkedCircularList next;
public SLinkedCircularList()
{
data = 0;
next = this;
}
public SLinkedCircularList(int value)
{
data = value;
next = this;
}
public SLinkedCircularList InsertNext(int value)
{
SLinkedCircularList node = new SLinkedCircularList(value);
if (this.next == this) // only one node in the circular list
{
// Easy to handle, after the two lines of executions,
// there will be two nodes in the circular list
node.next = this;
this.next = node;
}
else
{
// Insert in the middle
SLinkedCircularList temp = this.next;
node.next = temp;
this.next = node;
}
return node;
}
public int DeleteNext()
{
if (this.next == this)
{
System.out.println("\nThe node can not be deleted as there is only one node in the
circular list");
return 0;
}
SLinkedCircularList node = this.next;
this.next = this.next.next;
node = null;
return 1;
}
public void Traverse()
{
Traverse(this);
}
public void Traverse(SLinkedCircularList node)
{
if (node == null)
node = this;
System.out.println("\n\nTraversing in Forward Direction\n\n");
SLinkedCircularList startnode = node;
do
{
System.out.println(node.data);
node = node.next;
}
while (node != startnode);
}
public int GetNumberOfNodes()
{
return GetNumberOfNodes(this);
}
public int GetNumberOfNodes(SLinkedCircularList node)
{
if (node == null)
node = this;
int count = 0;
SLinkedCircularList startnode = node;
do
{
count++;
node = node.next;
}
while (node != startnode);
System.out.println("\nCurrent Node Value: " + node.data);
System.out.println("\nTotal nodes in Circular List: " + count);
return count;
}
public static void main(String[] args)
{
SLinkedCircularList node1 = new SLinkedCircularList(1);
node1.DeleteNext(); // Delete will fail in this case.
SLinkedCircularList node2 = node1.InsertNext(2);
node1.DeleteNext(); // It will delete the node2.
node2 = node1.InsertNext(2); // Insert it again
SLinkedCircularList node3 = node2.InsertNext(3);
SLinkedCircularList node4 = node3.InsertNext(4);
SLinkedCircularList node5 = node4.InsertNext(5);
node1.GetNumberOfNodes();
node3.GetNumberOfNodes();
node5.GetNumberOfNodes();
node1.Traverse();
node3.DeleteNext(); // delete the node "4"
node2.Traverse();
node1.GetNumberOfNodes();
node3.GetNumberOfNodes();
node5.GetNumberOfNodes();
}
}
8) Explain in detail about Sparse Matrices?
Data structures used to maintain sparse matrices must provide access to the nonzero
elements of a matrix in a manner which facilitates efficient implementation of the algorithms
that are examined in Section 8. The current sparse matrix implementation also seeks to
support a high degree of generality both in problem size and the definition of a matrix
element. Among other things, this implies that the algorithms must be able to solve
problems that are too large to fit into core.
Simply put, the fundamental sparse matrix data structure is:
Each matrix is a relation in a data base, and
Each nonzero element of a matrix is a tuple in a matrix relation.
Matrix tuples have the structure indicated in the following figure
The row and column domains of each tuple constitute a compound key to the matrix
relation. Their meaning corresponds to the standard dense matrix terminology.
The description of a matrix element is left intentionally vague. Its definition varies with the
application. Matrix elements must include a real number, double precision real number,
complex number, or any other entity for which the arithmetical operations of addition,
subtraction, multiplication, and division are reasonably defined.
In this context, matrix elements are accessed through high level data base operations:
Get retrieves a random tuple.
Next retrieves tuples sequentially. You will recall that the scan operator is used extensively
by sparse matrix algorithms in Section 8. Scan is implemented by embellishing the next
primitive.
Put updates the non-key portions of an existing tuple.
Insert adds a new tuple to a relation.
Delete removes an existing tuple from a relation.
This data structure places few constraints on the representation of a matrix. However,
several conventions are adopted to facilitate consistent algorithms and efficient cache
access:
Matrices have one-based indexing, i.e. the row and column indices of an nn matrix range
from 1 to n.
Column zero exists for each row of an asymmetric matrix. Column zero serves as a row
header and facilitates row operations. It does not enter into the calculations.
A symmetric matrix matrix is stored as an upper triangular matrix. In this representation, the
diagonal element anchors row operations as well as entering into the computations.
Column zero is not used for symmetric matrices.
Example of sparse matrix
[ 11 22 0 0 0 0 0 ] [ 0 33 44 0 0 0 0 ] [ 0 0 55 66 77 0 0 ] [ 0 0 0 0 0 88 0 ] [
0 0 0 0 0 0 99 ]
The above sparse matrix contains only 9 nonzero elements of the 35,with 26 of those
elements as zero.
Storing a sparse matrix
The basic data structure for a matrix is a two-dimensional array. Each entry in the array
represents an element ai,j of the matrix and can be accessed by the two HYPERLINK
"http://en.wikipedia.org/wiki/Array_data_structure" \o "Array data structure" indices i and j.
Traditionally, i indicates the row number (top-to-bottom), while j indicates the column
number (left-to-right) of each element in the table. For an mn matrix, enough memory to
store up to (mn) entries to represent the matrix is needed.
Substantial memory requirement reductions can be realized by storing only the non-zero
entries. Depending on the number and distribution of the non-zero entries, different data
structures can be used and yield huge savings in HYPERLINK
"http://en.wikipedia.org/wiki/Computer_storage" \o "Computer storage" memory when
compared to the basic approach.
Formats can be divided into two groups: (1) those that support efficient modification, and (2)
those that support efficient matrix operations. The efficient modification group includes DOK
(Dictionary of keys), LIL (List of lists), and COO (Coordinate list) and is typically used to
construct the matrix. Once the matrix is constructed, it is typically converted to a format,
such as CSR (Compressed Sparse Row) or CSC (Compressed Sparse Column), which is
more efficient for matrix operations.
Dictionary of keys (DOK)
DOK represents non-zero values as a dictionary (e.g., a HYPERLINK
UNIT 2
Contents:
Explain in detail about Stack ADT?
A stack is a linear data structure in which insertion and deletion takes place at same end.
This end is called the top. The other end of the list is called bottom. A stack is usually
visualized not horizontally but vertically. A stack is container of objects that are inserted and
deleted according to LIFO (Last in First Out) .i.e., the last inserted element in the stack is
deleted first.
The process of inserting a new element on the top of the stack is known as Push
operation. After the push operation the top is incremented by one and new element resets
at the top. When the array is full and this condition is known as stack overflow. In such case
no element is inserted.
The process of removing an element from the top of the stack is called pop operation.
After every pop operation, top is decremented by one. If there is no new element in the
stack, then the stack is called as empty stack or stack underflow. In such case, the pop
operation cannot be applicable.
Algorithm isempty ()
{
Return (t<0);
}
Size() - returns the number of elements in the stack
Algorithm size()
{
Return t+1;
}
Top() - returns the top element of the stack
Algorithm top()
{
If isempty() then Throw StackEmptyException;
Return s[t];
}
Pop() - deletes the top element from the stack
Algorithm pop()
{
If isempty() then Throw StackEmptyException;
a<- s[t];
t<- t-1;
return a;
}
Push(x) - add the element x to top of the stack.
Algorithm Push(a)
{
if size() = N then
Throw StackEmptyException;
Else
t<-t+1;
s[t]<-a;
}
The time complexity of stack to perform all its operations is O(1).
Array Implementation of Stack ADT
A Stack Interface
public interfaceStack
{ public void push(Object ob);
public Object pop();
public Object peek();
public boolean isEmpty();
public int size();
}
An ArrayStack Class
public class ArrayStack implements Stack
{
private Object a[];
private int top; // stack top
public ArrayStack(int n) // constructor
{ a = new Object[n]; // create stack array
top = -1; // no items in the stack
}
public void push(Object item) // add an item on top of stack
{
if(top == a.length-1)
{ System.out.println("Stack is full");
return;
}
top++; // increment top
a[top] = item; // insert an item
}
public Object pop() // remove an item from top of stack
{
if( isEmpty() )
{ System.out.println("Stack is empty");
return null;
}
Object item = a[top]; // access top item
top--; // decrement top
return item;
}
public Object peek() // get top item of stack
{ if( isEmpty() ) return null;
return a[top];
}
public boolean isEmpty() // true if stack is empty
{ return (top == -1); }
public int size() // returns number of items in the stack
{ return top+1; }
}
Testing ArrayStack Class
class ArrayStackDemo
{
public static void main(String[] args)
{
ArrayStack stk = new ArrayStack(4); // create stack of size 4
Object item;
stk.push('A'); // push 3 items onto stack
stk.push('B');
stk.push('C');
System.out.println("size(): "+ stk.size());
item = stk.pop(); // delete item
System.out.println(item + " is deleted");
stk.push('D'); // add three more items to the stack
stk.push('E');
stk.push('F');
System.out.println(stk.pop() + " is deleted");
stk.push('G'); // push one item
item = stk.peek(); // get top item from the stack
System.out.println(item + " is on top of stack");
}
}
Linked List Implementation of Stack ADT
public class LinkedStack implements Stack {
private class Node {
public Object data;
public Node next;
public Node(Object data, Node next) {
this.data = data;
this.next = next;
}
}
private Node top = null;
public void push(Object item) {
top = new Node(item, top);
}
public Object pop() {
Object item = peek();
top = top.next;
return item;
}
public boolean isEmpty() {
return top == null;
}
public Object peek() {
if (top == null) {
throw new NoSuchElementException();
}
return top.data;
}
public int size() {
int count = 0;
for (Node node = top; node != null; node = node.next) {
count++;
}
return count;
}
}
{
if isempty() then
Throw QueueEmptyException;
return a[f];
}
Enqueue() - insert an element to the queue
Algorithm enqueue()
{
if isempty() then
Throw QueueEmptyException;
temp<- q[f];
f<-f+1;
return temp;
}
Dequeue() delete the element from the queue
Algorithm dequeue()
{
If size()= N-1 then
Throw QueueFullException;
Else
q[r] <-a;
r<- r+1;
}
The time complexity to perform above operations is O(1)
Array Representation of Queue ADT:
import java.io.*;
import java.lang.*;
class clrqueue
{
DataInputStream get=new DataInputStream(System.in);
int a[];
int i,front=0,rear=0,n,item,count=0;
void getdata()
{
try
{
System.out.println("Enter the limit");
n=Integer.parseInt(get.readLine());
a=new int[n];
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
void enqueue()
{
try
{
if(count<n)
{
System.out.println("Enter the element to be added:");
item=Integer.parseInt(get.readLine());
a[rear]=item;
rear++;
count++;
}
else
System.out.println("QUEUE IS FULL");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
void dequeue()
{
if(count!=0)
{
System.out.println("The item deleted is:"+a[front]);
front++;
count--;
}
else
System.out.println("QUEUE IS EMPTY");
if(rear==n)
rear=0;
}
void display()
{
int m=0;
if(count==0)
System.out.println("QUEUE IS EMPTY");
else
{
for(i=front;m<count;i++,m++)
System.out.println(" "+a[i%n]);
}
}
}
class myclrqueue
{
public static void main(String arg[])
{
DataInputStream get=new DataInputStream(System.in);
int ch;
clrqueue obj=new clrqueue();
obj.getdata();
try
{
do
{
System.out.println(" 1.Enqueue 2.Dequeue 3.Display 4.Exit");
System.out.println("Enter the choice");
ch=Integer.parseInt(get.readLine());
switch (ch)
{
case 1:
obj.enqueue();
break;
case 2:
obj.dequeue();
break;
case 3:
obj.display();
break;
}
}
while(ch!=4);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Linked List Representation of QUEUE ADT
import java.io.*;
class Node
{
public int item;
public Node next;
public Node(int val)
{
item = val;
}
}
class LinkedList
{
private Node front,rear;
public LinkedList()
{
front = null;
rear = null;
}
public void insert(int val)
{
Node newNode = new Node(val);
if (front == null) {
front = rear = newNode;
}
else {
rear.next = newNode;
rear = newNode;
}
}
public int delete()
{
if(front==null)
{
System.out.println("Queue is Empty");
return 0;
}
else
{
int temp = front.item;
front = front.next;
return temp;
}
}
removed. The two elements removed, in this case, are 1 & 2 leaving the buffer with just a 3:
If the buffer has 7 elements then it is completely full:
A consequence of the circular buffer is that when it is full and a subsequent write is
performed, then it starts overwriting the oldest data. In this case, two more elements A &
B are added and they overwrite the 3 & 4:
Alternatively, the routines that manage the buffer could prevent overwriting the data and
return an error or raise an exception. Whether or not data is overwritten is up to the
semantics of the buffer routines or the application using the circular buffer.
Finally, if two elements are now removed then what would be returned is not 3 & 4 but 5 & 6
because A & B overwrote the 3 & the 4 yielding the buffer with:
{
System.out.println("Enter the limit");
n=Integer.parseInt(get.readLine());
a=new int[n];
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
void enqueue()
{
try
{
if(count<n)
{
System.out.println("Enter the element to be added:");
item=Integer.parseInt(get.readLine());
a[rear]=item;
rear++;
count++;
}
else
System.out.println("QUEUE IS FULL");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
void dequeue()
{
if(count!=0)
{
System.out.println("The item deleted is:"+a[front]);
front++;
count--;
}
else
System.out.println("QUEUE IS EMPTY");
if(rear==n)
rear=0;
}
void display()
{
int m=0;
if(count==0)
System.out.println("QUEUE IS EMPTY");
else
{
for(i=front;m<count;i++,m++)
System.out.println(" "+a[i%n]);
}
}
}
class myclrqueue
{
public static void main(String arg[])
{
DataInputStream get=new DataInputStream(System.in);
int ch;
clrqueue obj=new clrqueue();
obj.getdata();
try
{
do
{
System.out.println(" 1.Enqueue 2.Dequeue 3.Display 4.Exit");
System.out.println("Enter the choice");
ch=Integer.parseInt(get.readLine());
switch (ch)
{
case 1:
obj.enqueue();
break;
case 2:
obj.dequeue();
break;
case 3:
obj.display();
break;
}
}
while(ch!=4);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Explain in detail about Dequeue ADT?
A double-ended queue or dequeue is simply a combination of a HYPERLINK
"http://notes.komputerwiz.net:8000/wiki/Stack_%28ADT%29" \o "Stack (ADT)"stack and a
HYPERLINK "http://notes.komputerwiz.net:8000/wiki/Queue_%28ADT%29" \o "Queue
(ADT)"queue in that items can be inserted or removed from both ends.
double-ended queue queue-like linear data structure
that supports insertion and deletion of items at both ends of the queue
richer ADT than both the queue and the stack ADT
Functions
int size() Returns how many items are in the deque.
bool isEmpty() Returns whether the deque is empty (i.e. size is 0).
void insertFirst(Object o) Puts an object at the front.
void insertLast(Object o) Puts an object at the back.
Object removeFirst() Removes the object from the front and returns it.
Object removeLast() Removes the object from the back and returns it.
Object first() Peeks at the front item without removing it.
Object last() Peeks at the back item without removing it.
Singly Linked List implementation
Doubly Linked List implementation each node has prev and next link, hence all
operations run at O(1) time
front=maxSize;
array[--front]=item;
numberOfItems++;
}
public void addLast(Item item)
{
if(rear==maxSize-1)
rear=-1;
array[++rear]=item;
numberOfItems++;
}
public Item removeFirst()
{
Item temp=array[front++];
if(front==maxSize)
front=0;
numberOfItems--;
return temp;
}
public Item removeLast()
{
Item temp=array[rear--];
if(rear==-1)
rear=maxSize-1;
numberOfItems--;
return temp;
}
public int getFirst()
{
return front;
}
public int getLast()
{
return rear;
}
public static void main(String[] args)
{
Deque<String> element1=new Deque<String>();
Deque<String> element2=new Deque<String>();
for(int i=0;i<args.length;i++)
element1.addFirst(args[i]);
try {
for(;element1.numberOfItems+1>0;)
{
String temp=element1.removeFirst();
System.out.println(temp);
}
}
catch(Exception ex)
{
System.out.println("End Of Execution due to remove from empty queue");
}
System.out.println();
for(int i=0;i<args.length;i++)
element2.addLast(args[i]);
try {
for(;element2.numberOfItems+1>0;)
{
String temp=element2.removeLast();
System.out.println(temp);
}
}
catch(Exception ex)
{
System.out.println("End Of Execution due to remove from empty queue");
}
}
5. Write a java program for Infix To Postfix Conversion Using Stack
class InfixToPostfix
{
java.util.Stack<Character> stk =
new java.util.Stack<Character>();
public String toPostfix(String infix)
{
infix = "(" + infix + ")"; // enclose infix expr within parentheses
String postfix = "";
/* scan the infix char-by-char until end of string is reached */
for( int i=0; i<infix.length(); i++)
{
char ch, item;
ch = infix.charAt(i);
if( isOperand(ch) ) // if(ch is an operand), then
postfix = postfix + ch; // append ch to postfix string
if( ch == '(' ) // if(ch is a left-bracket), then
stk.push(ch); // push onto the stack
}
} // end of for-loop
return postfix;
} // end of toPostfix() method
public boolean isOperand(char c)
{ return(c >= 'A' && c <= 'Z'); }
public boolean isOperator(char c)
{
return( c=='+' || c=='-' || c=='*' || c=='/' );
}
public int precedence(char c)
{
int rank = 1; // rank = 1 for '* or '/'
if( c == '+' || c == '-' ) rank = 2;
return rank;
}
}
///////////////////////// InfixToPostfixDemo.java ///////////////
class InfixToPostfixDemo
{
public static void main(String args[])
{
InfixToPostfix obj = new InfixToPostfix();
String infix = "A*(B+C/D)-E";
System.out.println("infix: " + infix );
System.out.println("postfix:"+obj.toPostfix(infix) );
}
}
Applications:
These are used for job scheduling in operating system.
In network communication, to manage limited band width for transmission, the priority
queue
is used.
These are used to manage discrete events in simulation modelling.
Min Heap: A min heap is a tree in which the values in each node are less than or equal to
these in
its children.
Heap Operations
Insertion (Push)
To insert an element x into heap, we create a hole in the next available location, since
otherwise tree will not be complete. If x can be placed in the hole without violating the heap
order,
then we do so and are done. Otherwise we slide the element that is in the holes parent
node in the hole.
The following fig shows that to insert 14. We create a hole in the next available heap
location.
Inserting 14 in the hole would violate the heap order property. So 31 is slide down into the
hole. This
strategy is continued until the correct location for 14 is found.
This general strategy is known as Precolate up. The new element is percolated up the
heap
until the correct location is found.
Throw overflow();
Int hole = ++overflow();
Int hole = ++currentsize;
For( ; hole >1 && x< array[hole/2] ; hole=/2)
Array[hole]=array[hole/2];
Array[hole]=x;
}
Deletion (Pop)
If the priority queue is ascending or min priority queue, then only smallest is deleted at each
time. If the priority queue is descending/ max priority queue then only the largest element is
deleted at
each time. The following example shows deleting the smallest element for the previous
priority queue
.i.e., 13
Initially
Throw undeflow();
T lastelement = heap[ heapsize--];
Int currentnode=1;
Child=2;
While(child< = heapsize)
{
If(child < heapsize && heap[child] < heap [child+1])
Child++;
If(lastelement > = heap [child])
Break;
Heap[currentnode] = heap [child];
Currentnode = child;
Child = *2
}
Heap[currentnode]=lastelemnt;
}
The time complexity to perform above operations is O(logn).
Explain in detail about Java.Util Package-Arraylist, Linked List, Vector Classes,stack, queue
and iterators.
Java.Util Package-Arraylist
The java.util.ArrayList class provides resizable-array and implements the List
interface.Following are the important points about ArrayList:
It implements all optional list operations and it also permits all elements, includes null.
It provides methods to manipulate the size of the array that is used internally to store the
list.
The constant factor is low compared to that for the LinkedList implementation.
Class declaration
Following is the declaration for java.util.ArrayList class:
public class ArrayList<E>
extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, Serializable
Here <E> represents an Element. For example, if you're building an array list of Integers
then you'd initialize it as
ArrayList<Integer> list = new ArrayList<Integer>();
Class constructors
S.N.Constructor & Description
1ArrayList()
This constructor is used to create an empty list with an initial capacity sufficient to hold 10
elements.
2ArrayList(Collection<? extends E> c)
This constructor is used to create a list containing the elements of the specified collection.
3ArrayList(int initialCapacity)
This constructor is used to create an empty list with an initial capacity.
Class methods
S.N.Method & Description
1boolean add(E e)
This method appends the specified element to the end of this list.
2void add(int index, E element)
This method inserts the specified element at the specified position in this list.
Class methods
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
This method appends the specified element to the end of this Vector.
2void add(int index, E element)
This method inserts the specified element at the specified position in this Vector.
3boolean addAll(Collection<? extends E> c)
This method appends all of the elements in the specified Collection to the end of this
Vector.
4boolean addAll(int index, Collection<? extends E> c)
This method inserts all of the elements in the specified Collection into this Vector at the
specified position.
5void addElement(E obj)
This method adds the specified component to the end of this vector, increasing its size by
one.
6int capacity()
This method returns the current capacity of this vector.
7void clear()
This method removes all of the elements from this vector.
8clone clone()
This method returns a clone of this vector.
9boolean contains(Object o)
This method returns true if this vector contains the specified element.
Java.Util Package-Stacks
The java.util.Stack class represents a last-in-first-out (LIFO) stack of objects.
When a stack is first created, it contains no items.
In this class, the last element inserted is accessed first.
Class declaration
Following is the declaration for java.util.Stack class:
public class Stack<E>
extends Vector<E>
Class constructors
S.N.Constructor & Description
1Stack()
This constructor creates an empty stack.
Class methods
S.N.Method & Description
1boolean empty()
This method tests if this stack is empty.
2E peek()
This method looks at the object at the top of this stack without removing it from the stack.
3E pop()
This method removes the object at the top of this stack and returns that object as the value
of this function.
4E push(E item)
This method pushes an item onto the top of this stack.
5int search(Object o)
This method returns the 1-based position where an object is on this stack.
________________________________________________________________________
____________
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
UNIT 3
CONTENTS
Explain in detail about LINEAR SEARCH?
Linear search or sequential search is a method for finding a particular value in a
HYPERLINK "http://en.wikipedia.org/wiki/List_%28computing%29" \o "List (computing)"list
that consists of checking every one of its elements, one at a time and in sequence, until the
desired one is found.
Linear search is the simplest HYPERLINK "http://en.wikipedia.org/wiki/Search_algorithm" \o
"Search algorithm"search algorithm; it is a special case of HYPERLINK
"http://en.wikipedia.org/wiki/Brute-force_search" \o "Brute-force search"brute-force search.
Its HYPERLINK "http://en.wikipedia.org/wiki/Worst-case_complexity" \o "Worst-case
complexity"worst case cost is proportional to the number of elements in the list; and so is its
HYPERLINK "http://en.wikipedia.org/wiki/Average-case_complexity" \o "Average-case
complexity"expected cost, if all list elements are equally likely to be searched for.
Analysis
For a list with n items, the best case is when the value is equal to the first element of the
list, in which case only one comparison is needed. The worst case is when the value is not
in the list (or occurs only once at the end of the list), in which case n comparisons are
needed.
If the value being sought occurs k times in the list, and all orderings of the list are equally
likely, the expected number of comparisons is
For example, if the value being sought occurs once in the list, and all orderings of the list
are equally likely, the expected number of comparisons is However, if it is known that it
occurs once, then at most n - 1 comparisons are needed, and the expected number of
comparisons is
Application
Linear search is usually very simple to implement, and is practical when the list has only a
few elements, or when performing a single search in an unordered list.
When many values have to be searched in the same list, it often pays to pre-process the list
in order to use a faster method. For example, one may HYPERLINK
"http://en.wikipedia.org/wiki/Sort_%28computing%29" \o "Sort (computing)"sort the list and
use binary search, or build any efficient HYPERLINK
"http://en.wikipedia.org/wiki/Search_data_structure" \o "Search data structure"search data
structure from it. Should the content of the list change frequently, repeated re-organization
may be more trouble than it is worth.
As a result, even though in theory other search algorithms may be faster than linear search
(for instance HYPERLINK "http://en.wikipedia.org/wiki/Binary_search" \o "Binary search"
binary search), in practice even on medium sized arrays (around 100 items or less) it might
be infeasible to use anything else. On larger arrays, it only makes sense to use other, faster
search methods if the data is large enough, because the initial time to prepare (sort) the
data is comparable to many linear searches
Program in Java
import java.util.Scanner;
class LinearSearch
{
public static void main(String args[])
{
int c, n, search, array[];
Scanner in = new Scanner(System.in);
System.out.println("Enter number of elements");
n = in.nextInt();
array = new int[n];
to be searched is empty, then the key cannot be found in the array and a special "not
found" indication is returned.
A binary search halves the number of items to check with each iteration, so locating an item
(or determining its absence) takes HYPERLINK
"http://en.wikipedia.org/wiki/Logarithmic_time" \o "Logarithmic time"logarithmic time. A
binary search is a HYPERLINK "http://en.wikipedia.org/wiki/Dichotomic_search" \o
"Dichotomic search"dichotomic HYPERLINK
"http://en.wikipedia.org/wiki/Divide_and_conquer_algorithm" \o "Divide and conquer
algorithm"divide and conquer HYPERLINK "http://en.wikipedia.org/wiki/Search_algorithm"
\o "Search algorithm"search algorithm.
Performance
With each test that fails to find a match at the probed position, the search is continued with
one or other of the two sub-intervals, each at most half the size. More precisely, if the
number of items, N, is odd then both sub-intervals will contain (N1)/2 elements, while if N is
even then the two sub-intervals contain N/21 and N/2 elements.
If the original number of items is N then after the first iteration there will be at most N/2
items remaining, then at most N/4 items, at most N/8 items, and so on. In the worst case,
when the value is not in the list, the algorithm must continue iterating until the span has
been made empty; this will have taken at most HYPERLINK
"http://en.wikipedia.org/wiki/Binary_logarithm" \o "Binary logarithm"log2(N)+1 iterations,
where the notation denotes the HYPERLINK "http://en.wikipedia.org/wiki/Floor_function"
\o "Floor function"floor function that rounds its argument down to an integer. This
HYPERLINK "http://en.wikipedia.org/wiki/Worst_case_analysis" \o "Worst case analysis"
worst case analysis is tight: for any N there exists a query that takes exactly HYPERLINK
"http://en.wikipedia.org/wiki/Binary_logarithm" \o "Binary logarithm"log2(N)+1 iterations.
When compared to HYPERLINK "http://en.wikipedia.org/wiki/Linear_search" \o "Linear
search"linear search, whose worst-case behaviour is N iterations, we see that binary
search is substantially faster as N grows large. For example, to search a list of one million
items takes as many as one million iterations with linear search, but never more than twenty
iterations with binary search. However, a binary search can only be performed if the list is in
sorted order.
Program in Java
import java.util.Scanner;
class BinarySearch
{
public static void main(String args[])
{
int c, first, last, middle, n, search, array[];
Scanner in = new Scanner(System.in);
System.out.println("Enter number of elements");
n = in.nextInt();
array = new int[n];
System.out.println("Enter " + n + " integers");
for (c = 0; c < n; c++)
array[c] = in.nextInt();
System.out.println("Enter value to find");
search = in.nextInt();
first = 0;
last = n - 1;
middle = (first + last)/2;
while( first <= last )
{
original data and retrieve constant time (barring collisions). Another use is in HYPERLINK
"http://en.wikipedia.org/wiki/Cryptography" \o "Cryptography"cryptography, the science of
encoding and safeguarding data. It is easy to generate hash values from input data and
easy to verify that the data matches the hash, but hard to 'fake' a hash value to hide
malicious data. This is the principle behind the HYPERLINK
"http://en.wikipedia.org/wiki/Pretty_Good_Privacy" \o "Pretty Good Privacy"Pretty Good
Privacy algorithm for data validation.
Hash functions are also frequently used to accelerate table lookup or data comparison
tasks such as finding items in a database, detecting duplicated or similar records in a large
file and finding similar stretches in DNA sequences.
A hash function should be HYPERLINK
"http://en.wikipedia.org/wiki/Deterministic_algorithm" \o "Deterministic algorithm"
deterministic: when it is invoked twice on pieces of data that should be considered equal
(e.g., two strings containing exactly the same characters), the function should produce the
same value. This is crucial to the correctness of virtually all algorithms based on hashing. In
the case of a hash table, the lookup operation should look at the slot where the insertion
algorithm actually stored the data that is being sought for, so it needs the same hash value.
Hash functions are typically not HYPERLINK "http://en.wikipedia.org/wiki/Inverse_function"
\o "Inverse function"invertible, meaning that it is not possible to reconstruct the input datum
x from its hash value h(x) alone. In many applications, it is common that several values
hash to the same value, a condition called a hash collision. Since collisions cause
"confusion" of objects, which can make exact hash-based algorithm slower approximate
ones less precise, hash functions are designed to minimize the probability of collisions. For
cryptographic uses, hash functions are engineered in such a way that is impossible to
reconstruct any input from the hash alone without expending great amounts of computing
time (see also HYPERLINK "http://en.wikipedia.org/wiki/One-way_function" \o "One-way
function"One-way function).
Hash functions are related to (and often confused with) checksums, check digits,
fingerprints, randomization functions, error-correcting codes, and cryptographic. Although
these concepts overlap to some extent, each has its own uses and requirements and is
designed and optimized differently. The Hash Keeper database maintained by the
American National Drug Intelligence Center, for instance, is more aptly described as a
catalog of file fingerprints than of hash values.
Hash tables
Hash functions are primarily used in HYPERLINK "http://en.wikipedia.org/wiki/Hash_table"
\o "Hash table"hash tables, to quickly locate a data record (e.g., a HYPERLINK
"http://en.wikipedia.org/wiki/Dictionary" \o "Dictionary"dictionary definition) given its
HYPERLINK "http://en.wikipedia.org/wiki/Primary_key" \o "Primary key"search key (the
headword). Specifically, the hash function is used to map the search key to an index; the
index gives the place in the hash table where the corresponding record should be stored.
Hash tables, in turn, are used to implement HYPERLINK
"http://en.wikipedia.org/wiki/Associative_array" \o "Associative array"associative arrays and
HYPERLINK "http://en.wikipedia.org/wiki/Set_%28abstract_data_type%29" \o "Set (abstract
data type)"dynamic sets.
Typically, the domain of a hash function (the set of possible keys) is larger than its range
(the number of different table indexes), and so it will map several different keys to the same
index. Therefore, each slot of a hash table is associated with (implicitly or explicitly) a
HYPERLINK "http://en.wikipedia.org/wiki/Set_%28mathematics%29" \o "Set (mathematics)"
set of records, rather than a single record. For this reason, each slot of a hash table is often
called a bucket, and hash values are also called bucket indices.
Thus, the hash function only hints at the record's locationit tells where one should start
looking for it. Still, in a half-full table, a good hash function will typically narrow the search
down to only one or two entries.
Hash Table Operations
Search: compute f(k) and see if a pair exists
Insert: compute f(k) and place it in that position
Delete: compute f(k) and delete the pair in that position
Ideal Hashing Example
homeBucket = k % divisor
Divisor equals to the number of buckets b
0 <= homeBucket < divisor = b
Overflow Handling
Search the hash table in some systematic fashion for a bucket that is not full
Linear probing (linear open addressing)
Quadratic probing
Double Hashing
Eliminate overflows by permitting each bucket to keep a list of all pairs for which it is home
bucket
Hashing with Chains
Linear probing:
In general, our collision resolution strategy is to generate a sequence of hash table slots
(probe sequence) that can hold the record; test each slot until find empty one (probing)
For example, D=8, keys a,b,c,d have hash values h(a)=3, h(b)=0, h(c)=4, h(d)=3
Where do we insert d? 3 already filled
Probe sequence using linear hashing:
h1(d) = (h(d)+1)%8 = 4%8 = 4
h2(d) = (h(d)+2)%8 = 5%8 = 5*
h3(d) = (h(d)+3)%8 = 6%8 = 6
etc.
7, 0, 1, 2
Wraps around the beginning of the table!
Linear probing: hi(x) = (h(x) + i) % D
all buckets in table will be candidates for inserting a new record before the probe sequence
returns to home position
clustering of records, leads to long probing sequences
Linear probing with skipping: hi(x) = (h(x) + ic) % D
reference; however, linear probing has greater locality and, thus, better cache performance.
Quadratic probing is used in the HYPERLINK
"http://en.wikipedia.org/wiki/Berkeley_Fast_File_System" \o "Berkeley Fast File System"
Berkeley Fast File System to allocate free blocks. The allocation routine chooses a new
cylinder-group when the current is nearly full using quadratic probing, because of the speed
it shows in finding unused cylinder-groups.
Let h(k) be a HYPERLINK "http://en.wikipedia.org/wiki/Hash_function" \o "Hash function"
hash function that maps an element k to an integer in [0,m-1], where m is the size of the
table. Let the ith probe position for a value k be given by the function
INCLUDEPICTURE
"http://upload.wikimedia.org/math/d/9/f/d9f59944e827f1892472e1aa1e120f93.png" \*
MERGEFORMATINET
where c2 0. If c2 = 0, then h(k,i) degrades to a HYPERLINK
"http://en.wikipedia.org/wiki/Linear_probing" \o "Linear probing" linear probe. For a given
HYPERLINK "http://en.wikipedia.org/wiki/Hash_table" \o "Hash table" hash table, the values
of c1 and c2 remain constant.
Examples:
If INCLUDEPICTURE
"http://upload.wikimedia.org/math/d/5/a/d5acd6ad977ac05618efe06d44659435.png" \*
MERGEFORMATINET , then the probe sequence will be INCLUDEPICTURE
"http://upload.wikimedia.org/math/9/5/8/958c8ff6f49a30867c56b29217d50ce2.png" \*
MERGEFORMATINET
For m = 2n, a good choice for the constants are c1 = c2 = 1/2, as the values of h(k,i) for i in
[0,m-1] are all distinct. This leads to a probe sequence of INCLUDEPICTURE
"http://upload.wikimedia.org/math/5/7/9/57956aa60720da84a3b23441e1603b09.png" \*
MERGEFORMATINET where the values increase by 1, 2, 3, ...
For prime m > 2, most choices of c1 and c2 will make h(k,i) distinct for i in [0, (m-1)/2]. Such
choices include c1 = c2 = 1/2, c1 = c2 = 1, and c1 = 0, c2 = 1. Because there are only about
m/2 distinct probes for a given element, it is difficult to guarantee that insertions will
}
BufferedReader wordReader;
int tableSize = Integer.parseInt (args[1]);
Hashtable table = new Hashtable (tableSize);
String word;
// Load the words into the table.
int wordCount = 0;
wordReader = reader (args[0]);
do {
try {
word = wordReader.readLine ();
} catch (Exception e) ...
if (word == null) {
break;
} else {
wordCount++;
table.put (word, new Integer(wordCount));
}
} while (true);
// Now see how long it takes to look up all the words.
wordReader = reader (args[0]);
long startTime = System.currentTimeMillis ( );
do {
try {
word = wordReader.readLine ();
} catch (Exception e) ...
if (word == null) {
break;
} else {
boolean result = table.containsKey (word);
}
} while (true);
long finishTime = System.currentTimeMillis ( );
System.out.println ("Time to hash " + wordCount + " words is "
+ (finishTime-startTime) + " milliseconds.");
table.printStatistics ( );
}
}
Hashtable.java
public class Hashtable {
private static boolean DEBUGGING = false;
private LinkedList [] myTable;
public Hashtable (int size) {
myTable = new LinkedList [size];
for (int k=0; k<size; k++) {
myTable[k] = new LinkedList ( );
}
}
private static long hash (String key) {
// Uncomment one of the following lines to use the corresponding hash function.
// return hash1 (key);
// return hash2 (key);
// return hash3 (key);
}
return h << 2 >>> 2;
}
// Add the key to the table. The value is included just for compatibility with
// the Hashtable class in java.util.
public void put (String key, Integer value) {
int h = (int) (hash (key) % myTable.length);
if (!myTable[h].find (key)) {
myTable[h].insert (new Info (key, value));
if (DEBUGGING) {
System.out.println ("Inserting " + key);
}
} else {
System.err.println (key + " already in table.");
}
}
// Return true if key is in the table, and false otherwise.
public boolean containsKey (String key) {
int h = (int) (hash (key) % myTable.length);
return (myTable[h].find(key));
}
// Print statistics about the table:
//the maximum length of a collision list;
//the optimal length of a collision list;
//the average number of comparisons needed for a successful search;
//the standard deviation for the number of comparisons needed for
// a successful search.
public void printStatistics ( ) {
// Code omitted to save paper.
}
}
// Auxiliary classes follow in the file; code is omitted to save paper.
TTThashTest.java
import java.util.*;
public class TTThashTest {
// Measure the time to put all possible Tic-tac-toe boards into the hash table.
public static void main (String [ ] args) {
Hashtable table = new Hashtable ( );
long startTime = System.currentTimeMillis ( );
for (int k=0; k<19683; k++) {
TTTboard b = new TTTboard (k);
table.put (b, new Integer (k));
}
long finishTime = System.currentTimeMillis ( );
System.out.println ("Time to insert all Tic-tac-toe boards = "
+ (finishTime-startTime));
}
}
Java.Util Hashmap
java.util
Class HashMap<K,V>
Serializable
Hash table based implementation of the Map interface. This implementation provides all of
the optional map operations, and permits null values and the null key. (The HashMap class
is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This
class makes no guarantees as to the order of the map; in particular, it does not guarantee
that the order will remain constant over time.
This implementation provides constant-time performance for the basic operations
(get and put), assuming the hash function disperses the elements properly among the
buckets. Iteration over collection views requires time proportional to the "capacity" of
the HashMap instance (the number of buckets) plus its size (the number of key-value
mappings). Thus, it's very important not to set the initial capacity too high (or the load factor
too low) if iteration performance is important.
An instance of HashMap has two parameters that affect its performance: initial
capacity and load factor. The capacity is the number of buckets in the hash table, and the
initial capacity is simply the capacity at the time the hash table is created. The load factor is
a measure of how full the hash table is allowed to get before its capacity is automatically
increased. When the number of entries in the hash table exceeds the product of the load
factor and the current capacity, the hash table is rehashed (that is, internal data structures
are rebuilt) so that the hash table has approximately twice the number of buckets.
As a general rule, the default load factor (.75) offers a good tradeoff between time and
space costs. Higher values decrease the space overhead but increase the lookup cost
(reflected in most of the operations of the HashMap class, including get and put). The
expected number of entries in the map and its load factor should be taken into account
when setting its initial capacity, so as to minimize the number of rehash operations. If the
initial capacity is greater than the maximum number of entries divided by the load factor, no
rehash operations will ever occur.
If many mappings are to be stored in a HashMap instance, creating it with a sufficiently
large capacity will allow the mappings to be stored more efficiently than letting it perform
automatic rehashing as needed to grow the table.
Note that this implementation is not synchronized. If multiple threads access a hash map
concurrently, and at least one of the threads modifies the map structurally, it must be
synchronized externally. (A structural modification is any operation that adds or deletes one
or more mappings; merely changing the value associated with a key that an instance
already contains is not a structural modification.) This is typically accomplished by
synchronizing on some object that naturally encapsulates the map. If no such object exists,
the map should be "wrapped" using the HYPERLINK
"http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html" \l
"synchronizedMap(java.util.Map)"Collections.synchronizedMap method. This is best done
at creation time, to prevent accidental unsynchronized access to the map:
Map m = Collections.synchronizedMap(new HashMap(...));
The iterators returned by all of this class's "collection view methods" are fail-fast: if the map
is structurally modified at any time after the iterator is created, in any way except through
the iterator's own remove method, the iterator will throw aHYPERLINK
"http://docs.oracle.com/javase/7/docs/api/java/util/ConcurrentModificationException.html" \o
"class in java.util"ConcurrentModificationException. Thus, in the face of concurrent
modification, the iterator fails quickly and cleanly, rather than risking arbitrary, nondeterministic behavior at an undetermined time in the future.
Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally
speaking, impossible to make any hard guarantees in the presence of unsynchronized
concurrent modification. Fail-fast iterators throwConcurrentModificationException on a besteffort basis. Therefore, it would be wrong to write a program that depended on this
exception for its correctness: the fail-fast behavior of iterators should be used only to detect
bugs.
JAVA.Util Hash Set
java.util
Class HashSet<E>
HYPERLINK "http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html" \o "class in
java.lang"java.lang.Object
HYPERLINK "http://docs.oracle.com/javase/7/docs/api/java/util/AbstractCollection.html" \o
"class in java.util"java.util.AbstractCollection<E>
HYPERLINK "http://docs.oracle.com/javase/7/docs/api/java/util/AbstractSet.html" \o "class
in java.util"java.util.AbstractSet<E>
java.util.HashSet<E>
Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
HYPERLINK "http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html" \o
"interface in java.io"Serializable, HYPERLINK
"http://docs.oracle.com/javase/7/docs/api/java/lang/Cloneable.html" \o "interface in
java.lang"Cloneable, HYPERLINK
"http://docs.oracle.com/javase/7/docs/api/java/lang/Iterable.html" \o "interface in java.lang"
Iterable<E>, HYPERLINK
"http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html" \o "interface in java.util"
Collection<E>, HYPERLINK "http://docs.oracle.com/javase/7/docs/api/java/util/Set.html" \o
"interface in java.util"Set<E>
Direct Known Subclasses:
HYPERLINK
"http://docs.oracle.com/javase/7/docs/api/javax/print/attribute/standard/JobStateReasons.ht
ml" \o "class in javax.print.attribute.standard"JobStateReasons, HYPERLINK
"http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashSet.html" \o "class in java.util"
LinkedHashSet
public class HashSet<E>
extends HYPERLINK "http://docs.oracle.com/javase/7/docs/api/java/util/AbstractSet.html"
\o "class in java.util"AbstractSet<E>
implements HYPERLINK "http://docs.oracle.com/javase/7/docs/api/java/util/Set.html" \o
"interface in java.util"Set<E>, HYPERLINK
"http://docs.oracle.com/javase/7/docs/api/java/lang/Cloneable.html" \o "interface in
java.lang"Cloneable, HYPERLINK
"http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html" \o "interface in java.io"
Serializable
This class implements the Set interface, backed by a hash table (actually
a HashMap instance). It makes no guarantees as to the iteration order of the set; in
particular, it does not guarantee that the order will remain constant over time. This class
permits the null element.
This class offers constant time performance for the basic operations
(add, remove, contains and size), assuming the hash function disperses the elements
properly among the buckets. Iterating over this set requires time proportional to the sum of
the HashSet instance's size (the number of elements) plus the "capacity" of the
backing HashMap instance (the number of buckets). Thus, it's very important not to set the
initial capacity too high (or the load factor too low) if iteration performance is important.
Note that this implementation is not synchronized. If multiple threads access a hash set
concurrently, and at least one of the threads modifies the set, it must be synchronized
externally. This is typically accomplished by synchronizing on some object that naturally
encapsulates the set. If no such object exists, the set should be "wrapped" using the
HYPERLINK "http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html" \l
"synchronizedSet(java.util.Set)"Collections.synchronizedSet method. This is best done at
creation time, to prevent accidental unsynchronized access to the set:
Set s = Collections.synchronizedSet(new HashSet(...));
The iterators returned by this class's iterator method are fail-fast: if the set is modified at
any time after the iterator is created, in any way except through the iterator's
own remove method, the Iterator throws aHYPERLINK
"http://docs.oracle.com/javase/7/docs/api/java/util/ConcurrentModificationException.html" \o
"class in java.util"ConcurrentModificationException. Thus, in the face of concurrent
modification, the iterator fails quickly and cleanly, rather than risking arbitrary, nondeterministic behavior at an undetermined time in the future.
Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally
that the ability to detect that the list is sorted is efficiently built into the algorithm.
Performance of bubble sort over an already-sorted list (best-case) is O(n). By contrast,
most other algorithms, even those with better HYPERLINK
"http://en.wikipedia.org/wiki/Average-case_complexity" \o "Average-case complexity"
average-case complexity, perform their entire sorting process on the set and thus are more
complex. However, not only does HYPERLINK "http://en.wikipedia.org/wiki/Insertion_sort"
\o "Insertion sort"insertion sort have this mechanism too, but it also performs better on a list
that is substantially sorted (having a small number of HYPERLINK
"http://en.wikipedia.org/wiki/Inversion_%28discrete_mathematics%29" \o "Inversion
(discrete mathematics)"inversions).
Bubble sort should be avoided in case of large collections. It will not be efficient in case of
reverse ordered collection.
Step-by-step example
Let us take the array of numbers "5 1 4 2 8", and sort the array from lowest number to
greatest number using bubble sort. In each step, elements written in bold are being
compared. Three passes will be required.
First Pass:( 5 1 4 2 8 ) ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and
swaps since 5 > 1.( 1 5 4 2 8 ) ( 1 4 5 2 8 ), Swap since 5 > 4( 1 4 5 2 8 ) ( 1 4 2 5 8 ), Swap
since 5 > 2( 1 4 2 5 8 ) ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5),
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
), Swap since 4 > 2( 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. The 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 )
Java Program for Bubble Sort
import java.util.Scanner;
class BubbleSort {
public static void main(String []args) {
int n, c, d, swap;
Scanner in = new Scanner(System.in);
System.out.println("Input number of integers to sort");
n = in.nextInt();
int array[] = new int[n];
System.out.println("Enter " + n + " integers");
for (c = 0; c < n; c++)
array[c] = in.nextInt();
for (c = 0; c < ( n - 1 ); c++) {
for (d = 0; d < n - c - 1; d++) {
if (array[d] > array[d+1]) /* For descending order use < */
{
swap
= array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
System.out.println("Sorted list of numbers");
for (c = 0; c < n; c++)
System.out.println(array[c]);
}
}
Describe Insertion Sorting Technique?
Insertion sort is a simple HYPERLINK "http://en.wikipedia.org/wiki/Sorting_algorithm" \o
"Sorting algorithm"sorting algorithm that builds the final HYPERLINK
"http://en.wikipedia.org/wiki/Sorted_array" \o "Sorted array"sorted array (or list) one item at
a time. It is much less efficient on large lists than more advanced algorithms such as
HYPERLINK "http://en.wikipedia.org/wiki/Quicksort" \o "Quicksort"quicksort, HYPERLINK
"http://en.wikipedia.org/wiki/Heapsort" \o "Heapsort"heapsort, or HYPERLINK
"http://en.wikipedia.org/wiki/Merge_sort" \o "Merge sort"merge sort. However, insertion sort
provides several advantages:
Simple implementation
Efficient for (quite) small data sets
HYPERLINK "http://en.wikipedia.org/wiki/Adaptive_sort" \o "Adaptive sort"Adaptive (i.e.,
efficient) for data sets that are already substantially sorted: the HYPERLINK
"http://en.wikipedia.org/wiki/Time_complexity" \o "Time complexity"time complexity is O(n +
d), where d is the number of HYPERLINK
"http://en.wikipedia.org/wiki/Inversion_%28discrete_mathematics%29" \o "Inversion
(discrete mathematics)"inversions
More efficient in practice than most other simple quadratic (i.e., HYPERLINK
"http://en.wikipedia.org/wiki/Big_O_notation" \o "Big O notation"O(n2)) algorithms such as
HYPERLINK "http://en.wikipedia.org/wiki/Selection_sort" \o "Selection sort"selection sort or
HYPERLINK "http://en.wikipedia.org/wiki/Bubble_sort" \o "Bubble sort"bubble sort; the best
case (nearly sorted input) is HYPERLINK "http://en.wikipedia.org/wiki/Big_O_notation" \o
"Big O notation"O(n)
HYPERLINK "http://en.wikipedia.org/wiki/Stable_sort" \o "Stable sort"Stable; i.e., does not
change the relative order of elements with equal keys
HYPERLINK "http://en.wikipedia.org/wiki/In-place_algorithm" \o "In-place algorithm"In-place
; i.e., only requires a constant amount O(1) of additional memory space
23457961
23456791
12345679
Java Program for Insertion Sort:
public class InsertionSort
{ public static void main(String a[]){ int i; int array[] = {12,9,4,99,120,1,3,10};
System.out.println("\n\n RoseIndia\n\n"); System.out.println(" Selection Sort\n\n");
System.out.println("Values Before the sort:\n"); for(i = 0; i < array.length; i++)
System.out.print( array[i]+" "); System.out.println(); insertion_srt(array, array.length);
System.out.print("Values after the sort:\n"); for(i = 0; i <array.length; i++)
System.out.print(array[i]+" "); System.out.println(); System.out.println("PAUSE"); }
public static void insertion_srt(int array[], int n){ for (int i = 1; i < n; i++){ int j = i;
int B = array[i]; while ((j > 0) && (array[j-1] > B)){ array[j] = array[j-1]; j--; } array[j] = B; }
}}
int q=partition(a,p,r);
quickSort(a,p,q);
quickSort(a,q+1,r);
}
}
private static int partition(int[] a, int p, int r) {
int x = a[p];
int i = p-1 ;
int j = r+1 ;
while (true) {
i++;
while ( i< r && a[i] < x)
i++;
j--;
while (j>p && a[j] > x)
j--;
if (i < j)
swap(a, i, j);
else
return j;
}
}
private static void swap(int[] a, int i, int j) {
// TODO Auto-generated method stub
mergesort(low, middle);
// Sort the right side of the array
mergesort(middle + 1, high);
// Combine them both
merge(low, middle, high);
}
}
private void merge(int low, int middle, int high) {
// Copy both parts into the helper array
for (int i = low; i <= high; i++) {
helper[i] = numbers[i];
}
int i = low;
int j = middle + 1;
int k = low;
// Copy the smallest values from either the left or the right side back
// to the original array
while (i <= middle && j <= high) {
if (helper[i] <= helper[j]) {
numbers[k] = helper[i];
i++;
} else {
numbers[k] = helper[j];
j++;
}
k++;
}
// Copy the rest of the left side of the array into the target array
while (i <= middle) {
numbers[k] = helper[i];
k++;
i++;
}
}
}
Describe Heap Sorting Technique?
Heapsort
Merge sort time is O(n log n)
But requires (temporarily) n extra storage items
Heapsort
Works in place: no additional storage
Offers same O(n log n) performance
Idea (not quite in-place):
Insert each element into a priority queue
Repeatedly remove from priority queue to array
Array slots go from 0 to n-1
//Source code for Heap Sort public class HeapSort { private static int[] a; private static
int n; private static int left; private static int right; private static int largest;
public
static void buildheap(int []a){
n=a.length-1;
for(int i=n/2;i>=0;i){
maxheap(a,i);
} }
public static void maxheap(int[] a, int i){
left=2*i;
right=2*i+1;
if(left <= n && a[left] > a[i]){
largest=left;
}
else{
largest=i;
}
if(right <= n && a[right] > a[largest]){
largest=right;
}
if(largest!=i){
exchange(i,largest);
maxheap(a, largest);
} }
public static void exchange(int i, int j){
int t=a[i];
a[i]=a[j];
a[j]=t;
}
public static void sort(int []a0){
a=a0;
buildheap(a);
for(int i=n;i>0;i){
exchange(0, i);
n=n-1;
maxheap(a, 0);
} }
public static void
main(String[] args) {
int []a1={4,1,3,2,16,9,10,14,8,7};
sort(a1);
for(int
i=0;i<a1.length;i++){
System.out.print(a1[i] + " ");
} }}
Describe Radix Sorting Technique?
Each key is first figuratively dropped into one level of buckets corresponding to the value of
the rightmost digit. Each bucket preserves the original order of the keys as the keys are
dropped into the bucket. There is a one-to-one correspondence between the number of
buckets and the number of values that can be represented by a digit. Then, the process
repeats with the next neighbouring digit until there are no more digits to process. In other
words:
Take the least significant digit (or group of bits, both being examples of HYPERLINK
"http://en.wikipedia.org/wiki/Radix" \o "Radix"radices) of each key.
Group the keys based on that digit, but otherwise keep the original order of keys. (This is
what makes the LSD radix sort a HYPERLINK "http://en.wikipedia.org/wiki/Stable_sort" \o
"Stable sort"stable sort).
Repeat the grouping process with each more significant digit.
The sort in step 2 is usually done using HYPERLINK
"http://en.wikipedia.org/wiki/Bucket_sort" \o "Bucket sort"bucket sort or HYPERLINK
int[] list = {7843, 4568, 8765, 6543, 7865, 4532, 9987, 3241,
6589, 6622, 211, 2564};
String temp;
Integer numObj;
int digit, num;
ArrayQueue<Integer>[] digitQueues = (ArrayQueue<Integer>[])(new ArrayQueue[10]);
for (int digitVal = 0; digitVal <= 9; digitVal++)
digitQueues[digitVal] = new ArrayQueue<Integer>();
// sort the list
for (int position=0; position <= 3; position++)
{
for (int scan=0; scan < list.length; scan++)
{
temp = String.valueOf (list[scan]);
digit = Character.digit (temp.charAt(3-position), 10);
digitQueues[digit].enqueue (new Integer(list[scan]));
}
// gather numbers back into list
num = 0;
for (int digitVal = 0; digitVal <= 9; digitVal++)
{
while (!(digitQueues[digitVal].isEmpty()))
{
numObj = digitQueues[digitVal].dequeue();
list[num] = numObj.intValue();
num++;
}
}
}
// output the sorted list
for (int scan=0; scan < list.length; scan++)
System.out.println (list[scan]);
}
}
10. Draw a table to show comparison of Sorting Algorithms
Comparison of Sortig Algorithms
S.N.
Constructor & Description
1
LinkedList() This constructs
constructs an empty list.
2
LinkedList(Collection<? extends E>
c) This constructs a list containing
the elements of the specified
collection, in the order they are
returned by the collection's iterator.
S.N.
Method & Description
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
2
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
Powered By Samyak Infotech Pvt. Ltd.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
UNIT - 4
Contents:
pointer fields that has no value. These pointer fields are set to NULL. The following fig
shows the linked representation of the binary tree is
Explain in detail about Tree Traversals
There are four common ways to traverse a binary tree
Pre-order
In-order
Post-order
Level-order
Pre-order: in this type, the root is visited first, followed by the left sub tree followed by right
sub tree. Thus, the pre order traversal of the sample tree shown below is
Pre-order traversal is: D B A C F E G
Pre-order traversal will be implemented using the following code:
Template <class T>
Void Preorder (binaryTreeNode <T> *t)
{
If(t != NULL)
{
Visit(t);
Preorder( t->leftchild);
Preorder(t->rightchild);
}
}
In-order: the left sub tree is traversed first, followed by the root, and finally by the right sub
tree. Thus, the in-order traversal of the sample tree shown earlier would yield the sequence.
A- B C- D E F G
It will be implemented by the following code
Template <class T>
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
S.N.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
S.N.
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
S.N.
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
S.N.
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
System.out.println(focusNod
e);
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
Powered By Samyak Infotech Pvt. Ltd.
}
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
S.N.
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
S.N.
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
Powered By Samyak Infotech Pvt. Ltd.
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
Powered By Samyak Infotech Pvt. Ltd.
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
Powered By Samyak Infotech Pvt. Ltd.
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
Powered By Samyak Infotech Pvt. Ltd.
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
Powered By Samyak Infotech Pvt. Ltd.
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
S.N.
1
2
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
S.N.
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
Powered By Samyak Infotech Pvt. Ltd.
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
Powered By Samyak Infotech Pvt. Ltd.
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
S.N.
1
2
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
Powered By Samyak Infotech Pvt. Ltd.
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
Powered By Samyak Infotech Pvt. Ltd.
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
Powered By Samyak Infotech Pvt. Ltd.
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
}
return focusNode;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
}
return focusNode;
}
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
}
return focusNode;
}
public static void main(String[] args)
{
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
Powered By Samyak Infotech Pvt. Ltd.
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
Powered By Samyak Infotech Pvt. Ltd.
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
theTree.addNode(25, "Vice
President");
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
Powered By Samyak Infotech Pvt. Ltd.
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
Powered By Samyak Infotech Pvt. Ltd.
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
Powered By Samyak Infotech Pvt. Ltd.
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
Powered By Samyak Infotech Pvt. Ltd.
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Powered By Samyak Infotech Pvt. Ltd.
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
Powered By Samyak Infotech Pvt. Ltd.
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
Powered By Samyak Infotech Pvt. Ltd.
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
Powered By Samyak Infotech Pvt. Ltd.
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
S.N.
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
Powered By Samyak Infotech Pvt. Ltd.
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
Powered By Samyak Infotech Pvt. Ltd.
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
Powered By Samyak Infotech Pvt. Ltd.
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
Node leftChild;
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
Powered By Samyak Infotech Pvt. Ltd.
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
Node leftChild;
Node rightChild;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
Node leftChild;
Node rightChild;
Node(int key, String name) {
S.N.
1
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
Node leftChild;
Node rightChild;
Node(int key, String name) {
this.key = key;
this.name = name;
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
This is a collection
designed for holding elements prior
to processing.
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
// Future parent for our new
Node
Node parent;
while (true) {
// root is the top parent so
we start
// there
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
Powered By Samyak Infotech Pvt. Ltd.
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
Powered By Samyak Infotech Pvt. Ltd.
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
Powered By Samyak Infotech Pvt. Ltd.
this.key = key;
this.name = name;
}
S.N.
1
2
S.N.
1
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Sorting Technique
Powered By Samyak Infotech Pvt. Ltd.
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
// If the right child has
no children
if (focusNode == null) {
// then place the new
node on the right of it
parent.rightChild =
newNode;
return; // All Done
}
}
}
}
}
// All nodes are visited in
ascending order
// Recursion is used to go to one
node and
// then go to its child nodes and
so forth
public void
inOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
// Traverse the left node
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
Powered By Samyak Infotech Pvt. Ltd.
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
Node leftChild;
Node rightChild;
Node(int key, String name) {
this.key = key;
this.name = name;
}
public String toString() {
S.N.
1
2
S.N.
1
10
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
Java.util.Interfaces
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
Powered By Samyak Infotech Pvt. Ltd.
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
// Create a new Node and
initialize it
Node newNode = new
Node(key, name);
// If there is no root this
becomes root
if (root == null) {
root = newNode;
} else {
// Set root as the Node we
will start
// with as we traverse the
tree
Node focusNode = root;
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
Powered By Samyak Infotech Pvt. Ltd.
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
Powered By Samyak Infotech Pvt. Ltd.
S.N.
1
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
2Enumeration<E>
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
Powered By Samyak Infotech Pvt. Ltd.
parent = focusNode;
// Check if the new node
should go on
// the left side of the
parent node
if (key < focusNode.key) {
// Switch focus to the
left child
focusNode =
focusNode.leftChild;
// If the left child has no
children
if (focusNode == null) {
// then place the new
node on the left of it
parent.leftChild =
newNode;
return; // All Done
}
} else { // If we get here
put the node on the right
focusNode =
focusNode.rightChild;
inOrderTraverseTree(focus
Node.leftChild);
// Visit the currently focused
on node
System.out.println(focusNod
e);
// Traverse the right node
inOrderTraverseTree(focus
Node.rightChild);
}
}
public void
preorderTraverseTree(Node
focusNode) {
if (focusNode != null) {
System.out.println(focusNod
e);
preorderTraverseTree(focus
Node.leftChild);
preorderTraverseTree(focus
Node.rightChild);
}
}
public void
postOrderTraverseTree(Node
focusNode) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
Node leftChild;
Node rightChild;
Node(int key, String name) {
this.key = key;
this.name = name;
}
public String toString() {
return name + " has the key "
+ key;
/*
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
Powered By Samyak Infotech Pvt. Ltd.
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
Node leftChild;
Node rightChild;
Node(int key, String name) {
this.key = key;
this.name = name;
}
public String toString() {
return name + " has the key "
+ key;
/*
* return name + " has the key
" + key + "\nLeft Child: " + leftChild
+
* "\nRight Child: " + rightChild
+ "\n";
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
Powered By Samyak Infotech Pvt. Ltd.
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
Node leftChild;
Node rightChild;
Node(int key, String name) {
this.key = key;
this.name = name;
}
public String toString() {
return name + " has the key "
+ key;
/*
* return name + " has the key
" + key + "\nLeft Child: " + leftChild
+
* "\nRight Child: " + rightChild
+ "\n";
*/
S.N.
1
2
S.N.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add.htm" boolean
add(E e)This method appends the
specified element to the end of this
list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_add_index.htm" void
add(int index, E element)This
method inserts the specified
element at the specified position in
this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall.htm" boolean
addAll(Collection<? extends E> c)
This method appends all of the
elements in the specified collection
to the end of this list, in the order
that they are returned by the
specified collection's iterator.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addall_collection.htm"
boolean addAll(int index,
Collection<? extends E> c) This
method inserts all of the elements
in the specified collection into this
list, starting at the specified
position.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addfirst.htm" void
addFirst(E e) This method returns
inserts the specified element at the
beginning of this list..
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_addlast.htm" void
addLast(E e) This method returns
appends the specified element to
the end of this list.
Powered By Samyak Infotech Pvt. Ltd.
10
Java.util.Interfaces
The java.util.Interfaces contains the
collections framework, legacy
collection classes, event model,
date and time facilities,
internationalization, and
miscellaneous utility classes (a
string tokenizer, a random-number
generator, and a bit array).
S.N.Intreface & Description
1Deque<E>
2Enumeration<E>
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clear.htm" void clear()
This method removes all of the
elements from this list.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_clone.htm" Object
clone() This method returns returns
a shallow copy of this LinkedList.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_contains.htm" boolean
contains(Object o) This method
returns true if this list contains the
specified element.
HYPERLINK
"http://www.tutorialspoint.com/java/
util/linkedlist_descendingiterator.ht
m" Iterator<E> descendingIterator()
This method returns an iterator over
the elements in this deque in
reverse sequential order.
3EventListener
4Formattable
5Iterator<E>
6Queue<E>
Worst Case
Selection Sort
n2
n2
Insertion Sort
n2
nlogn
Quick Sort
nlogn
n
Tree Sort
nlogn
nlogn
public class BinaryTree {
Sorting Technique
Average Case
n2
Bubble Sort
n2
n2
Merge Sort
nlogn
n2
Radix Sort
n
n2
Heap Sort
nlogn
Node root;
public void addNode(int key,
String name) {
if (focusNode != null) {
postOrderTraverseTree(foc
usNode.leftChild);
postOrderTraverseTree(foc
usNode.rightChild);
System.out.println(focusNod
e);
}
}
public Node findNode(int key) {
// Start at the top of the tree
Node focusNode = root;
// While we haven't found the
Node
// keep looking
while (focusNode.key != key) {
// If we should search to the
left
if (key < focusNode.key) {
// Shift the focus Node to
the left child
focusNode =
focusNode.leftChild;
Powered By Samyak Infotech Pvt. Ltd.
} else {
// Shift the focus Node to
the right child
focusNode =
focusNode.rightChild;
}
// The node wasn't found
if (focusNode == null)
return null;
}
return focusNode;
}
public static void main(String[] args)
{
BinaryTree theTree = new
BinaryTree();
theTree.addNode(50, "Boss");
theTree.addNode(25, "Vice
President");
theTree.addNode(15, "Office
Manager");
theTree.addNode(30,
"Secretary");
theTree.addNode(75, "Sales
Manager");
theTree.addNode(85,
"Salesman 1");
// Different ways to traverse
binary trees
//
theTree.inOrderTraverseTree(theTr
ee.root);
//
theTree.preorderTraverseTree(theT
ree.root);
//
theTree.postOrderTraverseTree(the
Tree.root);
// Find the node with key 75
System.out.println("\nNode
with the key 75");
System.out.println(theTree.find
Node(75));
}
}
class Node {
int key;
String name;
Node leftChild;
Node rightChild;
Node(int key, String name) {
this.key = key;
this.name = name;
}
public String toString() {
return name + " has the key "
+ key;
/*
* return name + " has the key
" + key + "\nLeft Child: " + leftChild
+
* "\nRight Child: " + rightChild
+ "\n";
*/
}
normally set to NULL. Similarly, the right pointer of a node whose right child is an empty
sub tree is also set to NULL. Thus, a large number of pointers are set to NULL. These
NULL pointers could be used in different and more effective way.
Assume that the left pointer of a node n is set to NULL as the left child of n is
an empty sub tree. Then the left pointer of n can be set to point to the in order predecessor
of n. Similarly, if the right child of a node m is empty then the right pointer of m is empty
then the right pointer of m can be set to point to in order successor of m. the following fig
shows a threaded binary tree, lines with arrows represents threads.
In the above fig., links with arrows heads indicate links leading to in order successors while
other lines denote the usual links in a binary tree. Note that link with arrows and the
normal links indicate different relationship between nodes and the links are no longer used
to describe only parent-child relationship. Consequently, it must be understood
whether the left or right link of node n is
leading to its children or to in order predecessor of n or to the in order successor of n.
Two flags, left flag and right flag are used per node to indicate the type of its left
or right links. If left flag of a node is 0 then its left link leads to the left sub tree of n.
Otherwise, the left link leads to the in order predecessor of n. Similarly, if the right flag of
a node n is 0 then the right link leads to the right sub
tree of n, otherwise the right link leads to the in-order successor n. The left and right
link leading to in-order predecessors or successors are called threaded to distinguish
them from the conventional links of a binary tree. The links are used as threads only they
would have a pointed to empty sub-tree on a non-threaded binary tree. Every node in a
threaded binary tree must contain the flags, to indicate whether its left and right pointers are
threads. Hence the structure of a node in such trees contain two more fields: data, left
and right as shown in the following fig.,
Representation of Graphs:
There are two commonly used methods of representing the graphs
Adjacency Matrix:
In this method the graph can be represented by using matrix of n*n such that
A[i] [j] = 1 if (I, j) is an edge else 0
If the diagraph has weights we can store the weights in the matrix.
Adjacency list:
In this method graph can be represented using linked list. In this method there is an array of
linked list for each vertex V in the graph. If the edge have weights then these weights can
be stored in the linked list elements.
Explain in detail about Graph Searching Algorithms
A systematically follow up of the edges the graph in order to visit the vertices of the graph
is called graph searching.
There are two basic searching algorithms:
Breadth First Search
Depth First Search
The difference between those is in order in which they explore the un visited edges of the
graph.
Breadth first Search
BFS follows the following rules:
Select an unvisited node V, visit it, have it be the root in a BFS tree being formed. Its level
is called the current level.
For each node x in the current level, in the order in which the level nodes were visited, visit
all unvisited neighbors of x. the newly visited nodes from this level from a new level. This
new level becomes the next current level.
Repeat step2 for all unvisited vertices.
Repeat from step1 until no more vertices remaining.
Ex: consider the following graph
BFS Sequence is A-B-C-D-E-F-G-H
Java Program for BFS
import java.io.*;
class bfs1
{
public static void main(String args[]) throws IOException
{
int i,n,j,k;
System.out.println("No. of vertices :") ;
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
n =Integer.parseInt(br.readLine());
int q[] = new int[10];
int m[] = new int[10];
int a[][] = new int[10][10];
for (i=0; i<10; i++)
{
m[i] = 0;
}
System.out.println("\n\nEnter 1 if edge is present, 0 if not");
for (i=0; i<n; i++)
{
System.out.println("\n");
for (j=i; j<n; j++)
{
System.out.println("Edge between " + (i+1) + " and " + (j+1)+ ":" );
a[i][j]=Integer.parseInt(br.readLine());
a[j][i]=a[i][j];
}
a[i][i]=0;
}
System.out.println("\nOrder of accessed nodes : \n");
q[0] = 0; m[0] = 1;
int u;
int node=1;
DepthFirstSearch
It begins from then a particular vertex, then one of its child is visited and then the child of
child is visited. This process continuous until we reach the bottom of the graph.
Ex: consider the following graph
Step 7
Explain in detail about Dijkstras Algorithm
Single-Source Shortest Path Problem
Single-Source Shortest Path Problem - The problem of finding shortest paths from a source
vertex v to all other vertices in the graph.
Dijkstra's algorithm - is a solution to the single-source shortest path problem in graph
theory.
Works on both directed and undirected graphs. However, all edges must have nonnegative
weights.
Approach: Greedy
Input: Weighted graph G={E,V} and source vertex vV, such that all edge weights are
nonnegative
Output: Lengths of shortest paths (or the shortest paths themselves) from a given source
vertex vV to all other vertices
Dijkstra's algorithm Pseudocode
dist[s] 0
(distance to source vertex is zero)for all v V{s}
do dist[v] (set all other
distances to infinity) S (S, the set of visited vertices is initially empty) QV (Q, the queue
initially contains all vertices)
while Q (while the queue is not empty) do u
mindistance(Q,dist)(select the element of Q with the min. distance)
SS{u} (add u to list
of visited vertices)
for all v neighbors[u]
do if dist[v] > dist[u] + w(u, v) (if new
shortest path found)
then
d[v] d[u] + w(u, v)(set new value of shortest
path)
(if desired, add traceback code)
return dist
An Example:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Implementations and Running Times
The simplest implementation is to store vertices in an array or linked list. This will produce a
running time of
O(|V|^2 + |E|)
For sparse graphs, or graphs with very few edges and many nodes, it can be implemented
more efficiently storing the graph in an adjacency list using a binary heap or priority queue.
This will produce a running time of
O((|E|+|V|) log |V|)
As with all greedy algorithms, we need to make sure that it is a correct algorithm (e.g., it
always returns the right solution if it is given correct input).
JNTU Previous Questions
1. Write about BFS Graph Traversal
[SEPT 2010] [MARCH 2010]
Ans: Refer Unit 4 Question no.5
2. Implement Kruskals Algorithm for Minimum Cost Spanning Trees. [SEPT 2010]