Sie sind auf Seite 1von 2

A data type is a type together with a collection of operations to manipulate the type.

An abstract data type defines the data type solely in terms of a type and operations on that type. An aDT does not specify how the type is implemented. A data structure is the physical implementation of an ADT. Interfaces are created to define the operations of the ADT. Access control keeps methods from interfering with each other. Data structures use algorithms for sorting, searching, inserting, removing, and overall manipulation of their respective data. Separating the abstract definition of an ADT from its implementation in a data structure allows us to choose an efficient representation and implementation of the data and operators respectively.--ArrayBag public Boolean contains(T anEntry){ Boolean wasfound = false; int index =0; while(!wasFound && (index < numberOfEntries)) { if(anEntry.equals(bag[index])){wasFound = true;}else index++;}//end for return wasFound;} // end contains Best Case O(1) worst case O(n)--LinkedBag public Boolean contains(T anEntry){ Node currentNode = firstNode; Boolean wasFound = false; while(!wasFound && (currentNode !=null){ if(anEntry.equals (currentNode.getData())) wasFound true; else currentNode =currentNode .getNextNode();}//end while} return wasFound; } // end getReferenceTo ifFull(), isEmpty(),add,remove,getcurrentSize, all O(1). Clear() firstNode = null; numberOfEntries = 0;Big O describes the upper (worst case) bound and big Omega describes the lower (best case) bound. Big Theta describes the case where the upper and lower bounds of a function are on the same order of magnitude. ArrayList Prepend int newPosition = 0; if(itemCount ==0)listItem[newPosition] = item; else if(itemCount >=1){ ensureCapacity(); for (int Position = 0; position <= ItemCount; position++) listItem[position +1] = listItem[position]; listItem[newPositon] = item; itemCount++;LinkedList preprend Node newNode = new Node(item, null); if(isEmpty()){ tailNode = newNode;} else { newNode.SetNextNode(headNode.getNextNode);headNode.setNextNode(newNode);Quicksort and mergesort are considered effiecnet sorting algorithms. They both have logarithmic time complexities intheir average casse(fast) O(n log(n)) heap sort also. You would use mergesort if your needed speed and were not concerned with memory. The worst case time complexity is O(n log (n)) Stores memory in a temporary array. O(N) space complexity. You would use quicksort it has worst cast time complexity of O(n^2) but is still fast in average cases. Recursion with quicksort t would casuse too many activation records (n-1, n-2, n-3) with a large set of data that needs to be sorted. We prefer iteration space complexity of O(N) same as mergesort.Insertion Sort Proteced void sortSubList(int lowIndex, highIndex){ if(lowIndex < highIndex){ sortSUblist(lowIndex, highIndex-1); T insertItem = listItem[highIndex]; int insertIndex = highIndex; while(insertIndex > 0 && listItem[insertIndex-1].compareto) listItem[insertIndex] = listItem[insertIndex-1]; insertIndex --;} listItem[insertIndex] = insertItem;O(n^2) time complexity Bubblesort protected void sortSublist(int lowIndex, int highIndex){for (int i = highIndex; i > lowIndex; i--){ //"Bubble" largest value in listItem[lowIndex]...listItem[i]to position i by swapping adjacent items that are out of order// for (int j = lowIndex; j < i; j++){if (listItem[j].compareTo(listItem[j+1]) > 0){T temp = listItem[j];listItem[j] = listItem[j+1];listItem[j+1] = temp;} } // inner loop} // outer loop} ALIST public void add(T new Entry){ ensureCapacity(); list[numberOfEntries] = newEntry; numberOfEntries++}//ENDADD. Public Boolean add(int newPosition, T newEntry){ Boolean isSuccessful = true; if( (newPosition >= 1) && (newPosition <= numberOfEntries + 1)) { ensureCapacity(); for (intposition = numberOfEntries; position >= newPosition; position--)

List[position] = list[position -1]; list[newPosition 1] = newEntry; numberOfEntries++;}else isSucessful = false; return isSuccessful;//END ADD. Public T remove (int givenPositon( T result = null; if (givenPosition >= 1) && (givenPosition <= numberOfEntries)){ result = list[givenPosition 1]; if (givenPosition < numberOfEntries) for (int position = givenPosition; position < numberOfEntries -1; position++) number of Entries --;}//end if return result }end remove. Boolean replace (int givenPosition, T newEntry){ Boolean isSuccessful = true; if((givenPosition >= 1) && (givenPosition <= numberOfEntries)){ list[givenPosition -1] = newEntry; }else issuccessful = false; return isSuccessful; T getEntry (T result = null; (use if statement) { result =list[givenPosition -1];} return result;}LLIST public boolean add(int newPosition, T newEntry){Boolean isuccessful = true; if(newPosition >=1) && (newPosition <= numberOfEntries +1 )){ Node newNode = new Node(newEntry); if(isEmpty()){head = newNode;tail=newNode;}else if (newPosition==1) { newNode.setNextNode(head); head= newNode;}elseIf (newPosition == numberOfEntries +1){ tail.setNextNode(newNode); tail= newNode;} else{Node nodeBefore = getNodeaAt(newPosition -1); Node NodeAfter = nodeBefore.getNextNode(); nodeBefore.setNextNode(newNode);} //endIf numberOfEntries++} else isSucessful = false; return isSucessful; private Node getNOdeAt (int givenPosition){ Node currentNode =head; for (int counter = 1; counter < givenPosition; counter++) currentNode = currentNode.getNextNode(); return currentNode; } //end getNodeat public T remove(int givenPosition){ T result = null; if(givenPosition >=1) && (givenPositoni <= numberOfEntries)){ if (givenPosition == 1){ result = head.getData(); head = head.getNextNode(); if(numberOfEntries == 1) tail = null; } else{ Node nodeBefore = getNodeAt(givenPosition 1); Node nodeToRemove = nodeBefore.getNextNode(); Node nodeAfter = nodeToRemove .getNextNode(); NodeBefore.setNextNode(nodeAfter); result = nodeToRemove.getData(); if (givenPosition == numberOfEntries) tail = nodeBefore; } end if numberofEntries--;}//end if }return result; } nvoid clear(){head = null; tail = null; numberOfEntries = 0;}SORTING:Selection sort: find the smallest item in the unsorted partition of the array swap it into the correct position, move the line between the sorted and unsorted potions of the array. Swap is O(1) for loop executes n-1 times. Selection sort is O(n^2)Insertion Sort: leftmost item is sorted . start at last sorted item compare it to the item to insert. The complexity of insertion sorting is O(n) at best case of an already sorted array and O(n2) at worst case .Insertion sorting algorithm is similar to bubble sort. But insertion sort is more efficient than bubble sort because in insertion sort the elements comparisons are less as compare to bubble sort. In insertion sorting algorithm compare the value until all the prior elements are lesser than compared value is not found. This mean that the all previous values are lesser than compared value. This algorithm is more efficient than the bubble sort .Insertion sort is a good choice for small values and for nearly-sorted values.A linear search looks down a list, one item at a time, without jumping. In complexity terms this is an O(n)search - the time taken to search the list gets bigger at the same rate as the list does.A binary search is when you start with the middle of a sorted list, and see whether that's greater than or less than the value you're looking for, which determines whether the value is in the first or second half of the list. Jump to the half way through the sublist, and compare again etc. O(log n)Binary treesa binary tree is a tree data structure in which each node has at most two child nodes, The depth (or height) of a tree is the length of the path from the root to the deepest node in the tree. The size of a node is the number of descendants it has including itself. A full binary tree is a tree in which every node other than the leaves has two children.

Das könnte Ihnen auch gefallen