Heaps, Trees and Hashing

User Generated

xvatwnzrf98

Writing

Data Structures for Problem Solving (IT265 -1704A -01)

Colorado Technical University

Description

The next structure you will investigate is the Hash table and its methods implemented in pseudo code when linked lists are used to handle collisions.

The task this week is to complete the pseudo code for the following hash table operations:

  1. Insert
  2. Remove

Assume Hashtable is a simple array of size 8, with indices 0..7. Numeric keys are mapped by a Hashfunction that gives the mod(8,n) value for any key “n” yielding the Hashtable index for that key (0..7). A Hashtable entry is null unless a key exists with that index as its hashed index; if so, the Hashtable entry points to the first node of a linked list of keys with that hash index. The last node on this linked list has a null reference for the next referenced node. Assume the occurrence of a linked list node is represented by the object “Node” and its “Data” and “NextRef” attributes.

Week 2 Deliverables:

  • 1 pseudo code implementation of each Hash table operation: Insert and Remove
  • Fully documented pseudo code.
  • Add the completed pseudo code and the output to the Key Assignment template Section 2: Hashing, Heaps and Trees.

Unformatted Attachment Preview

Running head: DATA STRUCTURES IN JAVA Data Structure Using Java Lists, Stacks, and Queues James Larkin 10-6-17 1 DATA STRUCTURES IN JAVA 2 Abstract Data structure organizes data in a more efficient programs. An efficient program utilizes less space and system resources. Data structures are meant to be data organization for such items. They form a basic part or an algorithm or a program. Any collection of data can be searched, processed or manipulated in any order or it can be modified. Data structures and algorithm choice can make a program to take the shortest time possible or longest time ever. Data structures require resources like space, time and programming effort hence the above named effect. Most common used algorithms in computer science includes the merge sort, stacks and queues, heaps and trees, recursion and searching algorithms. Efficiency and usefulness of these algorithms can be determined using Java programs. The study will entail discussions and implementation of these algorithms in details. Selection process in data structures entails analyzing a problem and determine the resources requires and constraints, determining the basic operation that must be meat for a program to run and selection the best data structure that meets the requirements of a program. DATA STRUCTURES IN JAVA 3 Table of Content Section 1: Lists, Stacks, and Queues............................................................................................................. 4 Stacks ........................................................................................................................................................ 4 Queues ...................................................................................................................................................... 6 Section 2: Heaps and Trees ........................................................................................................................... 9 Hash table pseudo code ............................................................................................................................. 9 Collision in linked list ............................................................................................................................... 9 Section 3: Sorting Algorithms .................................................................................................................... 10 Compare sort algorithms ......................................................................................................................... 10 Section 4: Searching ................................................................................................................................... 11 pseudo code search linked list or array ................................................................................................... 11 Section 5: Recursion ................................................................................................................................... 12 pseudo code for factorial of a number using recursion. .......................................................................... 12 References:.................................................................................................................................................. 13 DATA STRUCTURES IN JAVA Section 1: Lists, Stacks, and Queues Stacks Import java.io. *; Class Node { Public String element; Public Node next; Public Node (String Value) { Element = Value; } Public void showNode(){ System.out.printLn(“Element [ “ + element + “]”); } } Class LinkedList { Private Node start; Private Node end; Public LonkedList () { Start = null; End = null; } Public boolean is Empty(){ Returns start == null; } Public void enqueue(String Value){ Node newNode = new Node(Value); If (isEmpty()) 4 DATA STRUCTURES IN JAVA Start = newNode; else end.next = newNode; end = newNode; } Public String dequeue(){ String temp = start.element; if(start.next == null) end = null; start = start.next; return temp; } Public void displayList() { System.out.println(“Elements:”); Node current = start; While (current != null){ current.displayNode(); current = current.next; } System.out.println(“”); } } Class Queue { Private LinkedList queueLinkedList; Public Quueue(){ QuueLinkedList = new LinkedList(); } 5 DATA STRUCTURES IN JAVA Queues Import java.io. *; Class Node { Public String element; Public Node next; Public Node (String Value) { Element = Value; } Public void showNode(){ System.out.printLn(“Element [ “+ element + “]”); } } Class LinkedList { private Node first; public LinkedList(){ first = null; } Public Boolean is Empty(){ return (first ==null); } public void push(String value){ Node newNode = new Node(value); NewNode.next = first; First = newNode; } 6 DATA STRUCTURES IN JAVA Public Node pop(){ Node temp = first; first = first.next; return temp; } public void display() { System.out.println(“Elements: ”); Node current = first; While (current !=null){ current.displayNode(); current = current.next; } System.out.println(“”); } } class Stack{ private LinkedList stackLinkedList; public Stack() { StackLinkedList = new LinkedList(); } Public void push(String value){ 7 DATA STRUCTURES IN JAVA StackLinkedList.push(value);} Public Node pop() 8 DATA STRUCTURES IN JAVA 9 Section 2: Heaps and Trees Hash table pseudo code Collision in linked list DATA STRUCTURES IN JAVA Section 3: Sorting Algorithms Compare sort algorithms 10 DATA STRUCTURES IN JAVA 11 Section 4: Searching pseudo code search linked list or array DATA STRUCTURES IN JAVA 12 Section 5: Recursion pseudo code for factorial of a number using recursion. DATA STRUCTURES IN JAVA References: Weiss, Mark A. (2009). Data Structures and Problem Solving Using Java, 4th Edition. Retrieved from https://bookshelf.vitalsource.com/#/books/9781323417645/ 13
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Attached.

Running Head: DATA STRUCTURE IN JAVA

DATA STRUCTURE IN JAVA
Name:
Institution:

1

DATA STRUCTURE IN JAVA

2

Insertion
class Node {
Node next;
String data;
public Node (String x) {
data=x;
next=null
}
}
class HashTable {
Node [] node;
int size
public HashTable (int tablesize) {
size=8;
node=new Node[size]
}
public insert (int val) {
val %=node. length
Node nodeptr=new Node(Val)
if(node[val]==null) {
node[val]=nodeptr;
} else {

DATA STRUCTURE IN JAVA

3

nodeptr. next=node[val];
node[val]=nodeptr;
}
}
public void main (){
HashTable hashtable=new HashTable (8)
hashtable. Insert(val);}}
Removal
class Node {
Node next;
String data;
public Node (String x) {
data=x;
next=null
}
}
class HashTable {
Node [] node;
int size
public HashTable (int tablesize) {
size=8;
node=new Node[size]

DATA STRUCTURE IN JAVA

}
public remove (int val){
val %=node.length;
Node start=Node[val];
Node end=start;

if(start.data==val){
node[val]=start.next;
size--;
return;
}
while(end.next!=null&&end.next.data!=val){
end=end.next;
if(end.next.next==null){
end.next=nu...


Anonymous
I use Studypool every time I need help studying, and it never disappoints.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags