Recursion Conclusion
Running head: LEARNING DATA STRUCTURES 3
LEARNING DATA STRUCTURES 3
Through the length of this course, we will be using this document to portray different data structures and the method of implementation, with reference to the pseudo code of these methods
or data structures. We will also become familiar with the pros and cons of these methods. Each week will cover different elements of the Java language. When the five weeks come to an end we
should have better understanding how this all flow together.
Table of Contents
Summary of Sorting Algorithms 11
LEARNING DATA STRUCTURES 3
Lists, Stacks, and Queues
Stack
The stack executed utilizing a linked list can work for boundless number of qualities. That implies, stack actualized utilizing connected rundown works for variable size of information. Along these lines, there is no compelling reason to settle the size toward the start of the usage. The Stack actualized utilizing connected rundown can compose the same number of information esteems as we need. (Lenka, 2018)
Push (item)
If next = (max) throw full stack exception
Stack (next) = item
Next++
Pop ()
If (next == 0)
Throw empty stack exception
Next—
Return stack (next)
Display ()
If stack = null
Then Display (error message)
Queue
Like a stack, a queue is a direct information structure. Not at all like a stack, a queue erases just the most seasoned included information. To enable you to conceptualize how this would function, how about we pause for a minute to utilize a relationship. Envision a line being fundamentally the same as the ticketing arrangement of a shop. Every client takes a ticket and is served when their number is called (Jenkov, 2014)
MAX = 5
Array Queue [MAX]
Enqueue(item)
If End=MAX
Display (Queue is full)
Otherwise
Add 1 to End
If (item) is null
Then Dequeue ()
Conclusion
I have learned that stack has five elements or functions. Queue is a function like an order in the way things are going to be placed. Basically, stack is LIFO and Queue is FIFO. Both are considered vital in writing script using JAVA.
Heaps and Trees
Insert
MakeHashTable (int 8): HashTable
//Create hash table with 8 slots//
n= 0
//set slot one at 0//
for (n = 0; n ≤ 7: n++)
{
Hash += key[n]:
Hash += (hash << 7);
Hash ^= (hash >> 0);
}
//value must be between 0 and 7
Function insert (key, value)
//Create insert function//
n := findSlot (key)
if slot[n] is full
return=value
try slot[n+1]
//if slot is full return value and try next slot//
Remove
Function remove(key)
Create remove function//
N := findSlot(key)
If slot[n] is full
return // key not found//
o := n
loop
o := (o+1) modulus numSlots
if slot[n] is empty
exit loop
p := hash(slot[o].key) modulus numSlots
if (o > n and (p <= n or p > o)) or
(o < n and (p <= n and p > o))
slot[n] := slot[o]
i := o
mark slot[n] as empty
//if there is no value for key mark slot empty//
Sorting Algorithms
Sorting algorithms
This assignment regards sorting algorithms. More specifically, it addresses the algorithm differences that might be considered when choosing a sort algorithm. Most importantly, the differences are supported with sort algorithms that exemplify the characteristics related to those sorts. As part of this assignment, a summary of the sort algorithms will be generated. Last but notthe least, the Big O critique will be included. That said this assignment progresses as follows
Differences among sort algorithms:
Simplicity
Apparently, some sort algorithms are quite simple than others. This is especially the case when the size of the array is quite small. In this regard, a sort algorithm that exemplifies this characteristic is the Insertion sort.
Apparently, insertion sort is a O(n2) algorithm meaning that it is adequately efficient and usually good when the size of the array is less than 100 items. This also means that the smaller the items in the array are, the faster the insertion sort will perform. However, it should be understood up front that the performance of the insertion sort will reduce significantly when the size of array or the number of items in the array increases.
Time efficiency
One of the factors a programmer might consider when selecting a sorting algorithm is regarding the time efficiency of that algorithm. Obviously, some sorting algorithms have time efficient than others. However, some others are inefficient based on the factor of time.
Examples of sort algorithms that exemplify this characteristic include Bubble sort, selection sort, and insertion sort. All these sort algorithms have "O(n2) run time which is always unacceptable" (Cormen et al, 2009). In other words, these sort algorithms have no practical applications in the computer industry. In other words, these three sort algorithms fall short in terms of time efficiency even when dealing with small sequences.
Space efficiency
Apparently, some sort algorithms are space efficient than others. This is the case because one would be writing programs for environments with limited memory. In such a case the programmer would want to consider space efficient sort algorithm to perform sorting of the arrays.
An example of a space efficient algorithm that exemplifies this characteristic of this characteristic is the heap sort. Apparently, heap sort is one of the general-purpose algorithms that there is. If a programmer is working in embedded system environments where the memory space is low, then he or she would want to use heap sort to perform sort arrays. This is the case because the sequence of heap sort is small enough to fit easily into the main memory.
Popularity
Obviously, some sort algorithms are popular in the computer industry than others. The popularity of these sort algorithms is based on their fast performance when implemented as the in-place algorithm.
An example of popular sort algorithm implemented as the in-place algorithm that exemplifies this characteristic is the Quick sort. Despite its popularity, it should be understood up front that quick sort has a run time of O(n2). Such a run time makes it susceptible in real time applications but still performs quite fast in real world scenarios.
Power
Apparently, not all sort algorithms are powerful in their respective performances. The power of such sort algorithm is because it has a bottom up merge sort variant known as a Tim variant.
An example of a powerful sort algorithm that exemplifies this characteristic is the merge sort. It should be understood up front that "merge sort has an optimal run time of O(nlogn) in the worst-case scenario" (Heineman, Pollice & Selkow, 2016). This also means that it is one of the powerful sort algorithms there is in the computer world. With such power, merge sort has the capacity to sort data even if such data is distributed in different memory locations. This also means that its sequence is big such that it will need more memory space to perform its sorting function well.
Summary of Sorting Algorithms
Searching
In an Array
Binary search in an array often allows individuals to search for data structures in an array of either lookup tables and dynamic sets of items. This provides for an easy search for keys or items within the internet. The binary search keys usually keep the lookup operations in an easy manner hence improving the corresponding operations of data searchers in an easy manner. The following is an array of 25 prime numbers that can be searched. These include = 2, 3,5, 7,11,13,19,23,29,31,37,41, 43,47,53,59,61,71,73,79,83,97.
In case an individual wants to know whether 17 is prime, if 17 is in the array then it is considered as prime. The position of any element that has been set out in the array is referred to as index. Most of the indices in the array often begin with 0 and often count in upwards position. In addition, the search for an array, the binary search process often utilizes the similar concept by splitting the intervals halfway meaning that to find the key value would be achieved easily (Selkow, 2016).
Linked List
To perform the binary search using the linked list, the determination of the middle element of high importance. The binary search can always be an efficient and fast process. However, the memory for the allocation of the linked list is always noncontiguous and dynamic. This makes it difficult in order to search and find the middle element. The following is the main approach that can be used in the linked list. The approach begins with setting the last node as Null. The middle element is also calculated with the use of two pointers as the best approach. Once the middle data has matched its required value for search, one can always return it. The middle value that has been achieved can be moved to the lower half. This would make it more efficient to achieve its expected performance. After the condition has come out the common elements in the list can be traversed. The example would be last>next=start (Naimipour, 2004).
PART 2
Linked List variation
The following is the process of binary search with a linked list variation
if (start == NULL)
return NULL;
struct Node* slow = start;
struct Node* fast = start -> next;
while (fast != last)
{
fast = fast -> next;
if (fast != last)
{
slow = slow -> next;
fast = fast -> next;
}
} return slow;
Sometimes it is important to provide verification of the binary through the recursive solution, which is very simple. This can be done to every node and subtree to make the larger node more fitting to the binary for effective processing (Sedgewick & Wayne, 2017).
References:
Arora., I. (2017). Implementing our Own Hash Table with Separate Chaining in Java. Retrieved from http//: www.geeksforgeeks.org/implementing-our-own-hash-table-with-separate-chaining- in-java/
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to algorithms. Cambridge [etc.: MIT Press.
Heineman, G. T., Pollice, G., & Selkow, S. (2016). Algorithms in a Nutshell: A Practical Guide. Sebastopol: O'Reilly Media Inc.
Jenkov, J. (2014, June 6). Java Collections - Queue. Retrieved from
http//: www.tutorials.jenkov.com/java-collections/queue.htm
Lenka, C. (2018). Stack Class in Java. Retrieved August/ from
http//: www.geeksforgeeks.org/stack-class-in-java/
Naimipour, K. (2004). Foundations of algorithms using C++ pseudocode. Sudbury (Massachusetts: Jones and Bartlett Publishers.
Sedgewick, R., & Wayne, K. (2017). Computer science: An interdisciplinary approach. Sebastopol: O'Reilly Media Inc
Selkow, S. (2016). Algorithms in a Nutshell: A Practical Guide. Sebastopol: O'Reilly Media Inc