• Complain

Kalicharan - Advanced Topics in Java: Core Concepts in Data Structures

Here you can read online Kalicharan - Advanced Topics in Java: Core Concepts in Data Structures full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. City: Berkeley;CA, year: 2013, publisher: Apress, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Kalicharan Advanced Topics in Java: Core Concepts in Data Structures
  • Book:
    Advanced Topics in Java: Core Concepts in Data Structures
  • Author:
  • Publisher:
    Apress
  • Genre:
  • Year:
    2013
  • City:
    Berkeley;CA
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

Advanced Topics in Java: Core Concepts in Data Structures: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Advanced Topics in Java: Core Concepts in Data Structures" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Java is one of the most widely used programming languages today. It was first released by Sun Microsystems in 1995. Over the years, its popularity has grown to the point where it plays an important role in most of our lives. From laptops to data centers, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere! There are tons of applications and heaps of websites that will not work unless you have Java installed, and more are created every day. And, of course, Java is used to power what has become the worlds most dominant mobile platform, Android. Advanced Topics In Java teaches the algorithms and concepts that any budding software developer should know. Youll delve into topics such as sorting, searching, merging, recursion, random numbers and simulation, among others. You will increase the range of problems you can solve when you learn how to create and manipulate versatile and popular data structures such as binary trees and hash tables. This book assumes you have a working knowledge of basic programming concepts such as variables, constants, assignment, selection (if.else) and looping (while, for). It also assumes you are comfortable with writing functions and working with arrays. If you study this book carefully and do the exercises conscientiously, you would become a better and more agile software developer, more prepared to code todays applications - no matter the language. What youll learn What are and how to use some advanced algorithms, implemented in Java How to create, manipulate and use linked lists, stacks and queues How to use random numbers to program games and simulations How to work with files, binary trees and hash tables Sophisticated sorting methods such as heapsort, quicksort and mergesort How to implement all of the above in Java Who this book is for This book is for those with a working knowledge of basic software development topic concepts, such as variables, constants, assignment, selection (if.else) and looping (while, for). It also assumes you are comfortable with writing functions and working with arrays.

Kalicharan: author's other books


Who wrote Advanced Topics in Java: Core Concepts in Data Structures? Find out the surname, the name of the author of the book and a list of all author's works by series.

Advanced Topics in Java: Core Concepts in Data Structures — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Advanced Topics in Java: Core Concepts in Data Structures" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Noel Kalicharan Advanced Topics in C Core Concepts in Data Structures 10.1007/978-1-4302-6401-9_1
Noel Kalicharan 2013
1. Sorting, Searching, and Merging
Noel Kalicharan 1
(1)
Delhi, India
Abstract
In this chapter, we will explain the following:
In this chapter, we will explain the following:
  • How to sort a list of items using selection and insertion sort
  • How to add a new item to a sorted list so that the list remains sorted
  • How to sort an array of strings
  • How to sort related (parallel) arrays
  • How to search a sorted list using binary search
  • How to search an array of strings
  • How to write a program to do a frequency count of words in a passage
  • How to merge two sorted lists to create one sorted list
1.1 Sorting an Array: Selection Sort
S orting is the process by which a set of values are arranged in ascending or descending order. There are many reasons to sort. Sometimes we sort in order to produce more readable output (for example, to produce an alphabetical listing). A teacher may need to sort her students in order by name or by average score. If we have a large set of values and we want to identify duplicates, we can do so by sorting; the repeated values will come together in the sorted list.
Another advantage of sorting is that some operations can be performed faster and more efficiently with sorted data. For example, if data is sorted, it is possible to search it using binary searchthis is much faster than using a sequential search. Also, merging two separate lists of items can be done much faster than if the lists were unsorted.
There are many ways to sort. In this chapter, we will discuss two of the simple methods: selection and insertion sort. In , we will look at more sophisticated ways to sort. We start with selection sort.
Consider the following list of numbers stored in a C array, num :
Sorting num in ascending order using selection sort proceeds as follows st - photo 1
Sorting num in ascending order using selection sort proceeds as follows:
st pass
  • Find the smallest number in the entire list, from positions to ; the smallest is , found in position .
  • Interchange the numbers in positions and . This gives us the following:
    nd pass Find the smallest number in positions to the smallest is found - photo 2
nd pass
  • Find the smallest number in positions to ; the smallest is , found in position .
  • Interchange the numbers in positions and . This gives us the following:
    rd pass Find the smallest number in positions to the smallest is found - photo 3
rd pass
  • Find the smallest number in positions to ; the smallest is , found in position .
  • Interchange the numbers in positions and . This gives us the following:
    th pass Find the smallest number in positions to the smallest is found - photo 4
th pass
  • Find the smallest number in positions to ; the smallest is , found in position .
  • Interchange the numbers in positions and . This gives us the following:
    th pass Find the smallest number in positions to the smallest is found - photo 5
th pass
  • Find the smallest number in positions to ; the smallest is , found in position .
  • Interchange the numbers in positions and . This gives us the following:
    th pass Find the smallest number in positions to the smallest is found - photo 6
th pass
  • Find the smallest number in positions to ; the smallest is , found in position .
  • Interchange the numbers in positions and . This gives us the following:
    The array is now completely sorted Note that once the 6th largest 65 has - photo 7
The array is now completely sorted. Note that once the 6th largest (65) has been placed in its final position (5), the largest (79) would automatically be in the last position (6).
In this example, we made six passes. We will count these passes by letting the variable h go from to . On each pass, we find the smallest number from positions h to . If the smallest number is in position s , we interchange the numbers in positions h and s .
In general, for an array of size n , we make n-1 passes. In our example, we sorted seven numbers in six passes. The following is a pseudocode outline of the algorithm for sorting num[0..n-1] :
for h = 0 to n - 2
s = position of smallest number from num[h] to num[n-1]
swap num[h] and num[s]
endfor
We can implement this algorithm as follows, using the generic parameter, list :
void selectionSort(int list[], int lo, int hi) {
//sort list[lo] to list[hi] in ascending order
int getSmallest(int[], int, int);
void swap(int[], int, int);
for (int h = lo; h < hi; h++) {
int s = getSmallest(list, h, hi);
swap(list, h, s);
}
}
The two statements in the for loop could be replaced by this:
swap(list, h, getSmallest(list, h, hi));
We can write getSmallest and swap as follows:
int getSmallest(int list[], int lo, int hi) {
//return location of smallest from list[lo..hi]
int small = lo;
for (int h = lo + 1; h <= hi; h++)
if (list[h] < list[small]) small = h;
return small;
}
void swap(int list[], int i, int j) {
//swap elements list[i] and list[j]
int hold = list[i];
list[i] = list[j];
list[j] = hold;
}
To test whether selectionSort works properly, we write Program P1.1. Only main is shown. To complete the program, just add selectionSort , getSmallest , and swap .
Program P1.1
#include
#define MaxNumbers 10
int main() {
void selectionSort(int [], int, int);
int num[MaxNumbers];
printf("Type up to %d numbers followed by 0\n", MaxNumbers);
int n = 0, v;
scanf("%d", &v);
while (v != 0 && n < MaxNumbers) {
num[n++] = v;
scanf("%d", &v);
}
if (v != 0) {
printf("More than %d numbers entered\n", MaxNumbers);
printf("First %d used\n", MaxNumbers);
}
//n numbers are stored from num[0] to num[n-1]
selectionSort(num, 0, n-1);
printf("\nThe sorted numbers are\n");
for (int h = 0; h < n; h++) printf("%d ", num[h]);
printf("\n");
}
The program requests up to ten numbers (as defined by MaxNumbers ), stores them in the array num , calls selectionSort , and then prints the sorted list.
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Advanced Topics in Java: Core Concepts in Data Structures»

Look at similar books to Advanced Topics in Java: Core Concepts in Data Structures. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Advanced Topics in Java: Core Concepts in Data Structures»

Discussion, reviews of the book Advanced Topics in Java: Core Concepts in Data Structures and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.