Presorting is an old idea in computer science. In fact, interest in so translation - Presorting is an old idea in computer science. In fact, interest in so Indonesian how to say

Presorting is an old idea in comput

Presorting is an old idea in computer science. In fact, interest in sorting algorithms
is due, to a significant degree, to the fact that many questions about a list are
easier to answer if the list is sorted. Obviously, the time efficiency of algorithms
that involve sorting may depend on the efficiency of the sorting algorithm being
used. For the sake of simplicity, we assume throughout this section that lists are
implemented as arrays, because some sorting algorithms are easier to implement
for the array representation.
So far, we have discussed three elementary sorting algorithms—selection sort,
bubble sort, and insertion sort—that are quadratic in the worst and average cases,
and two advanced algorithms—mergesort, which is always in(nlogn),and
quicksort, whose efficiency is also(nlogn)in the average case but is quadratic in
the worst case. Are there faster sorting algorithms? As we have already stated in
Section 1.3 (see also Section 11.2), no general comparison-based sorting algorithm can have a better efficiency thannlognin the worst case, and the same result holds
for the average-case efficiency.
1
Following are three examples that illustrate the idea of presorting. More
examples can be found in this section’s exercises.
EXAMPLE 1Checking element uniqueness in an array If this element uniqueness problem looks familiar to you, it should; we considered a brute-force algorithm for the problem in Section 2.3 (see Example 2). The brute-force algorithm
compared pairs of the array’s elements until either two equal elements were found
or no more pairs were left. Its worst-case efficiency was in(n2
).
Alternatively, we can sort the array first and then check only its consecutive
elements: if the array has equal elements, a pair of them must be next to each
other, and vice versa.

The running time of this algorithm is the sum of the time spent on sorting
and the time spent on checking consecutive elements. Since the former requires
at leastnlogncomparisons and the latter needs no more thann−1 comparisons,
it is the sorting part that will determine the overall efficiency of the algorithm. So,
if we use a quadratic sorting algorithm here, the entire algorithm will not be more
efficient than the brute-force one. But if we use a good sorting algorithm, such
as mergesort, with worst-case efficiency in(nlogn),the worst-case efficiency of
the entire presorting-based algorithm will be also in(nlogn):

EXAMPLE 2Computing a mode Amodeis a value that occurs most often in a
given list of numbers. For example, for 5, 1, 5, 7, 6, 5, 7, the mode is 5. (If several
different values occur most often, any of them can be considered a mode.) The
brute-force approach to computing a mode would scan the list and compute the
frequencies of all its distinct values, then find the value with the largest frequency.

In order to implement this idea, we can store the values already encountered,
along with their frequencies, in a separate list. On each iteration, theith element
of the original list is compared with the values already encountered by traversing
this auxiliary list. If a matching value is found, its frequency is incremented;
otherwise, the current element is added to the list of distinct values seen so far
with a frequency of 1.
It is not difficult to see that the worst-case input for this algorithm is a list with
no equal elements. For such a list, itsith element is compared withi−1 elements
of the auxiliary list of distinct values seen so far before being added to the list with
a frequency of 1. As a result, the worst-case number of comparisons made by this
algorithm in creating the frequency list is The additionaln−1 comparisons needed to find the largest frequency in the auxiliary list do not change the quadratic worst-case efficiency class of the algorithm.
As an alternative, let us first sort the input. Then all equal values will be
adjacent to each other. To compute the mode, all we need to do is to find the
longest run of adjacent equal values in the sorted array.

The analysis here is similar to the analysis of Example 1: the running time of
the algorithm will be dominated by the time spent on sorting since the remainder
of the algorithm takes linear time (why?). Consequently, with annlognsort, this
method’s worst-case efficiency will be in a better asymptotic class than the worstcase efficiency of the brute-force algorithm.

EXAMPLE 3Searching problem Consider the problem of searching for a given
valuevin a given array of nsortable items. The brute-force solution here is
sequential search (Section 3.1), which needsncomparisons in the worst case. If
the array is sorted first, we can then apply binary search, which requires only
log
2n+1 comparisons in the worst case. Assuming the most efficientnlogn
sort, the total running time of such a searching algorithm in the worst case will be
T (n)=Tsort
(n)+Tsearch
(n)=(nlogn)+(logn)=(nlogn),
which is inferior to sequential search. The same will also be true for the averagecase efficiency. Of course, if we are to search in the same list more than once, the
time spent on sorting might well be justified. (Problem 4 in this section’s exercises
asks to estimate the minimum number of searches needed to justify presorting.)
Before we finish our discussion of presorting, we should mention that many,
if not most, geometric algorithms dealing with sets of points use presorting in
one way or another. Points can be sorted by one of their coordinates, or by
their distance from a particular line, or by some angle, and so on. For example,
presorting was used in the divide-and-conquer algorithms for the closest-pair
problem and for the convex-hull problem, which were discussed in Section 5.5.
Further, some problems for directed acyclic graphs can be solved more easily
after topologically sorting the digraph in question. The problems of finding the
longest and shortest paths in such digraphs (see the exercises for Sections 8.1
and 9.3) illustrate this point.
Finally, most algorithms based on the greedy technique, which is the subject of
Chapter 9, require presorting of their inputs as an intrinsic part of their operations.
0/5000
From: -
To: -
Results (Indonesian) 1: [Copy]
Copied!
Presorting adalah ide lama dalam ilmu komputer. Pada kenyataannya, minat dalam algoritma pengurutanjatuh tempo, ke tingkat yang signifikan, fakta bahwa banyak pertanyaan tentang daftarlebih mudah untuk menjawab jika daftar diurutkan. Jelas, efisiensi waktu algoritmaitu melibatkan penyortiran Mei tergantung pada efisiensi yang algoritma pengurutandigunakan. Demi kesederhanaan, kita menganggap seluruh bagian ini yang daftardiimplementasikan sebagai array, karena lebih mudah untuk menerapkan beberapa algoritma sortinguntuk array.Sejauh ini, kita telah membahas tiga dasar algoritma sorting-urut pilihan,semacam gelembung, dan mengurutkan penyisipan — kuadrat dalam kasus terburuk dan rata-rata,dan dua maju algoritma — mergesort, yang selalu di (nlogn), danquicksort, efisiensi yang juga (nlogn) dalam kasus tapi rata-rata kuadrat dalamkasus terburuk. Ada lebih cepat algoritma pengurutan? Seperti yang kita telah menyatakan diBagian 1.3 (Lihat juga bagian 11,2), tidak umum berdasarkan perbandingan algoritma sorting dapat memiliki thannlognin efisiensi lebih baik kasus terburuk, dan hasil yang sama memeganguntuk rata-rata-kasus efisiensi.1Berikut adalah tiga contoh yang menggambarkan ide presorting. Lebihcontoh dapat ditemukan dalam bagian ini latihan.CONTOH 1Checking elemen keunikan dalam array jika masalah keunikan elemen ini tampak akrab bagi Anda, seharusnya; Kami menganggap brute force algoritma untuk mengatasi masalah di bagian 2.3 (Lihat contoh 2). Algoritma brute forcedibandingkan dengan berbagai elemen pasang sampai kedua-dua elemen yang sama ditemukanatau banyak pasangan yang tersisa. Efisiensi terburuk pada (n2).Selain itu, kita dapat mengurutkan array pertama dan kemudian periksa hanya yang berturut-turutelemen: jika array memiliki unsur-unsur yang sama, sepasang dari mereka harus di sebelah setiaplainnya, dan sebaliknya.Saat menjalankan algoritma ini adalah jumlah waktu yang dihabiskan pada penyortirandan waktu yang dihabiskan untuk memeriksa elemen konsekutif. Karena memerlukan mantandi leastnlogncomparisons dan yang kedua membutuhkan tidak lebih thann−1 perbandingan,ini adalah bagian pengurutan yang akan menentukan efisiensi keseluruhan algoritma. Jadi,Jika kita menggunakan kuadrat di sini algoritma sorting, seluruh algoritma tidak akan lebihefisien daripada brute force satu. Tetapi jika kita menggunakan algoritma pengurutan yang baik, sepertisebagai mergesort, dengan efisiensi yang terburuk di (nlogn), efisiensi terburukalgoritma berbasis presorting seluruh akan juga di (nlogn):CONTOH 2Computing a modus Amodeis nilai yang paling sering terjadi padaDaftar nomor yang diberikan. Misalnya, untuk 5, 1, 5, 7, 6, 5, 7, modus adalah 5. (Jika beberapanilai-nilai yang berbeda terjadi paling sering, salah satu dari mereka dapat dianggap sebagai modus.) Thebrute force pendekatan komputasi mode akan memindai daftar dan menghitungfrekuensi semua nilai yang berbeda, kemudian menemukan nilai dengan frekuensi yang terbesar.Dalam rangka melaksanakan gagasan ini, kita dapat menyimpan nilai-nilai yang sudah temui,bersama dengan frekuensi, dalam daftar terpisah. Setiap kali iterasi, elemen theithDaftar asli dibandingkan dengan nilai-nilai yang telah dihadapi oleh melintasiDaftar ini bantu. Jika pencocokan nilai ditemukan, frekuensi bertambah;Jika tidak, elemen saat ini akan ditambahkan ke daftar nilai-nilai yang berbeda, melihat begitu jauhdengan frekuensi 1.Hal ini tidak sulit untuk melihat bahwa input yang terburuk untuk algoritma ini adalah daftar dengantidak ada unsur-unsur yang sama. Untuk daftar tersebut, elemen itsith adalah unsur-unsur dibandingkan withi−1Bantu daftar nilai-nilai yang berbeda terlihat begitu jauh sebelum sedang ditambahkan ke daftar denganfrekuensi 1. Sebagai hasilnya, jumlah kasus terburuk perbandingan dibuat olehalgoritma dalam menciptakan daftar frekuensi adalah perbandingan additionaln−1 diperlukan untuk menemukan frekuensi terbesar dalam daftar penolong tidak mengubah kelas efisiensi terburuk kuadrat dari algoritma.Sebagai alternatif, mari kita pertama mengurutkan input. Kemudian semua nilai yang sama akanberdekatan satu sama lain. Untuk menghitung modus, semua yang perlu kita lakukan adalah untuk menemukanterpanjang Jalankan berdekatan sama nilai dalam array diurutkan.Analisis di sini mirip dengan analisis contoh 1: saat menjalankanalgoritma akan didominasi oleh waktu yang dihabiskan pada penyortiran sejak sisanyadari algoritma waktu linear (mengapa?). Akibatnya, dengan annlognsort, inimetode yang terburuk efisiensi akan lebih baik asimtotik kelas dari efisiensi worstcase algoritma brute force.EXAMPLE 3Searching problem Consider the problem of searching for a givenvaluevin a given array of nsortable items. The brute-force solution here issequential search (Section 3.1), which needsncomparisons in the worst case. Ifthe array is sorted first, we can then apply binary search, which requires onlylog2n+1 comparisons in the worst case. Assuming the most efficientnlognsort, the total running time of such a searching algorithm in the worst case will beT (n)=Tsort(n)+Tsearch(n)=(nlogn)+(logn)=(nlogn),which is inferior to sequential search. The same will also be true for the averagecase efficiency. Of course, if we are to search in the same list more than once, thetime spent on sorting might well be justified. (Problem 4 in this section’s exercisesasks to estimate the minimum number of searches needed to justify presorting.)Before we finish our discussion of presorting, we should mention that many,if not most, geometric algorithms dealing with sets of points use presorting inone way or another. Points can be sorted by one of their coordinates, or bytheir distance from a particular line, or by some angle, and so on. For example,presorting was used in the divide-and-conquer algorithms for the closest-pairproblem and for the convex-hull problem, which were discussed in Section 5.5.Further, some problems for directed acyclic graphs can be solved more easilyafter topologically sorting the digraph in question. The problems of finding thelongest and shortest paths in such digraphs (see the exercises for Sections 8.1and 9.3) illustrate this point.Finally, most algorithms based on the greedy technique, which is the subject ofChapter 9, require presorting of their inputs as an intrinsic part of their operations.
Being translated, please wait..
 
Other languages
The translation tool support: Afrikaans, Albanian, Amharic, Arabic, Armenian, Azerbaijani, Basque, Belarusian, Bengali, Bosnian, Bulgarian, Catalan, Cebuano, Chichewa, Chinese, Chinese Traditional, Corsican, Croatian, Czech, Danish, Detect language, Dutch, English, Esperanto, Estonian, Filipino, Finnish, French, Frisian, Galician, Georgian, German, Greek, Gujarati, Haitian Creole, Hausa, Hawaiian, Hebrew, Hindi, Hmong, Hungarian, Icelandic, Igbo, Indonesian, Irish, Italian, Japanese, Javanese, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Korean, Kurdish (Kurmanji), Kyrgyz, Lao, Latin, Latvian, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malay, Malayalam, Maltese, Maori, Marathi, Mongolian, Myanmar (Burmese), Nepali, Norwegian, Odia (Oriya), Pashto, Persian, Polish, Portuguese, Punjabi, Romanian, Russian, Samoan, Scots Gaelic, Serbian, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenian, Somali, Spanish, Sundanese, Swahili, Swedish, Tajik, Tamil, Tatar, Telugu, Thai, Turkish, Turkmen, Ukrainian, Urdu, Uyghur, Uzbek, Vietnamese, Welsh, Xhosa, Yiddish, Yoruba, Zulu, Language translation.

Copyright ©2025 I Love Translation. All reserved.

E-mail: