1. The document discusses sorting and searching algorithms and exercises related to analyzing their time complexities. It provides solutions for exercises involving sorting lists by different schemes, optimizing sorting algorithms by splitting arrays, and selecting subsets from sorted and unsorted arrays.
2. Key points made include that sorting then selecting items is faster than repeated searches for large lists, and that splitting an array into square root of n subsets each sorted and merged provides the optimal time complexity of O(n√n) for sorting algorithms like insertion sort.
3. Questions ask to determine complexities of sorting algorithms like insertion sort, merge sort, and selection from arrays, and to recommend optimal algorithms like quicksort or selection for given array sizes and problem constraints
Cryptanalysis with a Quantum Computer - An Exposition on Shor's Factoring Alg...Daniel Hutama
Integer factorization is a problem that has been studied by mathematicians for centuries, but has yet to see an efficient classical solution. The apparent intractability of the factorization problem has become the cornerstone of several cryptosystems, such as the widely used RSA encryption scheme for securing financial transactions and communications.
In this presentation, we show an in-depth study of quantum circuit designs for a quantum computer running Shor's algorithm. In particular, we present a classical-based reversible quantum circuit design of Vedral et. al., and a Fourier space circuit designed by Draper and Beauregard. Included in the appendix are detailed descriptions of Shor's full algorithm and a fully worked (classically simulated) example for factoring a 5-bit semiprime number.
Readers should have a basic knowledge of quantum computing concepts, such as qubits, quantum logic gates, entanglement, and their mathematical descriptions.
Cryptanalysis with a Quantum Computer - An Exposition on Shor's Factoring Alg...Daniel Hutama
Integer factorization is a problem that has been studied by mathematicians for centuries, but has yet to see an efficient classical solution. The apparent intractability of the factorization problem has become the cornerstone of several cryptosystems, such as the widely used RSA encryption scheme for securing financial transactions and communications.
In this presentation, we show an in-depth study of quantum circuit designs for a quantum computer running Shor's algorithm. In particular, we present a classical-based reversible quantum circuit design of Vedral et. al., and a Fourier space circuit designed by Draper and Beauregard. Included in the appendix are detailed descriptions of Shor's full algorithm and a fully worked (classically simulated) example for factoring a 5-bit semiprime number.
Readers should have a basic knowledge of quantum computing concepts, such as qubits, quantum logic gates, entanglement, and their mathematical descriptions.
Shor's algorithm is for quantum computer. Using this algorithm any arbitrarily large number can be factored in polynomial time. which is not possible in classical computer
I am Nigel J. I am a Computer Network Assignment Expert at computernetworkassignmenthelp.com. I hold a Master's in Computer Science from, the University of Glasgow, UK. I have been helping students with their assignments for the past 15 years. I solve assignments related to Computer Networks.
Visit computernetworkassignmenthelp.com or email support@computernetworkassignmenthelp.com.
You can also call on +1 678 648 4277 for any assistance with Computer Network Assignment.
I am John G. I am a Stochastic Processes Assignment Expert at statisticsassignmenthelp.com. I hold a Masters in Statistics, from London, UK. I have been helping students with their homework for the past 5 years. I solve assignments related to Stochastic Processes.
Visit statisticsassignmenthelp.com or email info@statisticsassignmenthelp.com.
You can also call on +1 678 648 4277 for any assistance with Stochastic Processes Assignments.
Shor's algorithm is for quantum computer. Using this algorithm any arbitrarily large number can be factored in polynomial time. which is not possible in classical computer
I am Nigel J. I am a Computer Network Assignment Expert at computernetworkassignmenthelp.com. I hold a Master's in Computer Science from, the University of Glasgow, UK. I have been helping students with their assignments for the past 15 years. I solve assignments related to Computer Networks.
Visit computernetworkassignmenthelp.com or email support@computernetworkassignmenthelp.com.
You can also call on +1 678 648 4277 for any assistance with Computer Network Assignment.
I am John G. I am a Stochastic Processes Assignment Expert at statisticsassignmenthelp.com. I hold a Masters in Statistics, from London, UK. I have been helping students with their homework for the past 5 years. I solve assignments related to Stochastic Processes.
Visit statisticsassignmenthelp.com or email info@statisticsassignmenthelp.com.
You can also call on +1 678 648 4277 for any assistance with Stochastic Processes Assignments.
Analysis and design of algorithms part2Deepak John
Analysis of searching and sorting. Insertion sort, Quick sort, Merge sort and Heap sort. Binomial Heaps and Fibonacci Heaps, Lower bounds for sorting by comparison of keys. Comparison of sorting algorithms. Amortized Time Analysis. Red-Black Trees – Insertion & Deletion.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
UiPath Test Automation using UiPath Test Suite series, part 4
220exercises2
1. 2 Exercises and Solutions
Most of the exercises below have solutions but you should try first to solve
them. Each subsection with solutions is after the corresponding subsection
with exercises.
2.1 Sorting and searching: exercises
1. You must find 1000 most expensive items from an unsorted price list con-
taining 107
different items. Two schemes of solution are as follows.
• Scheme A: repeat 1000 times the sequential search (with the linear
complexity O(n)).
• Scheme B: convert the list into an array (the same complexity O(n)
as for search), then sort the array (complexity O(n log n)) and fetch
1000 top items.
Which scheme would you prefer assuming that searching for 100 items in
the unsorted list takes 0.1 millisecond (ms) and sorting of 100 items also
takes 0.1 ms? Time for fetching data should not be taken into account.
2. Processing time of InsertionSort is c·n2
. To merge k pre-sorted subarrays
that contain together n items you have to compare the k top items in all
the subarrays to choose the current maximum item and place it into the
sorted array (assuming that all the items have to be sorted in ascending
order). Therefore, the time for merging is proportional to (k − 1) · n. Let
the processing time of the merge be c · (k − 1) · n where the scale factor
has the same value as for InsertionSort. Analyse whether it is possible to
accelerate sorting of n items in the following way:
• Split the initial array of size n into k subarrays of size n/k. The last
subarray may be longer to preserve the total number of items n but
do not go in such details in your analysis.
• Sort each subarray separately by InsertionSort.
• Merge the sorted subarrays into a final sorted array.
If you have found that the acceleration is possible, then find the optimum
value of k and compare the resulting time complexity of this sorting algo-
rithm to that of InsertionSort and MergeSort.
3. The processing time of a sorting algorithm is described by the following
recurrence equation (c is a positive constant):
T(n) = 3T(n/3) + 2cn;
T(1) = 0
Solve this equation to derive an explicit formula for T(n) assuming n = 3m
and specify the Big-Oh complexity of the algorithm.
1
2. 4. Find out whether the above algorithm is faster or slower than usual Merge-
sort that splits recursively an array into only two subarrays and then
merges the sorted subarrays in linear time cn.
5. Time complexity of sorting n data items with insertionSort is O(n2
),
that is, the processing time of insertionSort is cs · n2
where cs is a con-
stant scale factor.
Time complexity of merging k subarrays pre-sorted in ascending order and
containing n items in total is O(k ·n). The processing time is cm(k −1)·n
because at each step t = 1, 2, . . . , n you compare k current top items in all
the subarrays (that is, (k − 1) comparisons), pick up the maximum item,
and place it in position (n − t + 1) in the final sorted array.
You are going to save time by splitting the initial array of size n into k
smaller subarrays, sorting each subarray by insertionSort, and merging
the sorted subarrays in a single sorted array.
Let the scale factors cs and cm be equal: cs = cm = c. Analyse whether
you can actually accelerate sorting of n items in the following way:
• Split the initial array of size n into k subarrays of size n
k . The last
subarray may be longer to preserve the total number of items n but
do not go into such detail in your analysis.
• Sort each subarray separately by InsertionSort.
• Merge the sorted subarrays into a final sorted array.
If the acceleration is possible, then find the optimum value of k giving
the best acceleration and compare the resulting time complexity of the
resulting sorting algorithm to that of InsertionSort and MergeSort.
6. You decided to improve insertion sort by using binary search to find the
position p where the new insertion should take place:
Algorithm ImprovedInsertionSort
Input/output: an integer array a = {a[0], . . . , a[n − 1]} of size n
begin ImprovedInsertionSort
1 for i ← 1 while i < n step i ← i + 1 do
2 stmp ← a[i]; p ← BinarySearch(a, i − 1, stmp)
3 for integer j ← i − 1 while j ≥ p step j ← j − 1 do
4 a[j + 1] ← a[j]
5 end for
6 a[p] ← stmp
7 end for
end ImprovedInsertionSort
Here, stmp = a[i] is the current value to be inserted at each step i into
the already sorted part a[0], . . . , a[i − 1] of the array a. The binary search
2
3. along that part returns the position p such that stmp < a[p] and either
p = 0 or stmp ≥ a[p − 1]. After finding p, the data values in the subse-
quent positions j = i − 1, . . . , p are sequentially moved one position up to
i, . . . , p+1 so that the value stmp can be inserted into the proper position p.
Answer the following questions regarding time complexity of the proposed
algorithm. Hint: to answer the questions you may need the formulae for
the sum of integers from 1 to n: 1 + 2 + . . . + n = n(n+1)
2 and for the sum
of their logarithms by the base 2: log2 1 + log2 2 + . . . + log2 n ≡ log2 n! ≥
n log2 n − 1.44n (see also Appendix ??).
(a) Determine how many data moves in total should be done in average
to sort an array a of the size n.
(b) Determine how many data moves in total should be done in the worst
case to sort the array a.
(c) Determine how many comparisons should be done by BinarySearch
in average to sort the array a.
(d) Determine how many comparisons should be done by BinarySearch
in the worst case to sort the array a.
(e) What is the worst-case complexity of ImprovedInsertionSort if you
take account of only the comparisons made by BinarySearch?
(f) What is the worst-case complexity of ImprovedInsertionSort if only
moves of the data values are taken into account?
7. Find the best way for selecting p most popular persons in an unordered
database containing entries for n different persons all over the world. Each
entry i of the data base has a non-negative integer key ki that numerically
specifies how popular is that person. For instance, the key that is less than
all other keys characterises the least popular person, and the key that is
greater than all other keys belongs to the top-rank “star”. You have two
options:
(i) repeat p times a sequential search through the whole data base and
select each time the top-most key while skipping all the already found
keys or
(ii) sort first the whole data base using the QuickSort method and then
select the p entries with the top-most keys.
You found the sequential search and QuickSort have processing times
T(n) = 0.1n ms and T(n) = 0.1n log10 n ms, respectively, and the time for
selecting an entry from a sorted data base is negligibly small with respect
to the sorting time.
Which option, (i) or (ii), would you recommend for any particular pair
of the values of n and p in order to minimise running time? If your data
base contains 106
entries and you have to select 100 most popular persons,
then which option will be the best?
3
4. 8. Specify the worst-case and average-case Big-Oh complexity of the following
algorithms, assuming an input array of size N: InsertionSort, HeapSort,
MergeSort, QuickSort, SequentialSearch, BinarySearch.
9. Convert an array [10, 26, 52, 76, 13, 8, 3, 33, 60, 42] into a maximum heap.
10. Convert the above array into a well-balanced binary search tree. Explain
what is the basic difference between a heap and a binary search tree?
11. You have to split an unsorted integer array, Wn, of size n into the two
subarrays, Uk and Vn−k, of sizes k and n − k, respectively, such that all
the values in the subarray Uk are smaller than the values in the subarray
Vn−k . You may use the following two algorithms:
A. Sort the array Wn with QuickSort and then simply fetch the smallest
k items from the positions i = 0, 1, . . . , k − 1 of the sorted array to
form Uk (you should ignore time of data fetching comparing to the
sorting time).
B. Directly select k smallest items with QuickSelect from the unsorted
array (that is, use QuickSelect k times to find items that might be
placed to the positions i = 0, 1, . . . , k − 1 of the sorted array).
Let processing time of QuickSort and QuickSelect be Tsort(n) = csortn log2 n
and Tslct(n) = cslctn, respectively. Choose the algorithm with the smallest
processing time for any particular n and k.
Assume that in the previous case QuickSort spends 10.24 microseconds to
sort n = 1024 unsorted items and QuickSelect spends 1.024 microseconds
to select a single i-smallest item from n = 1024 unsorted items. What
algorithm, A or B, must be chosen if n = 220
and k = 29
≡ 512?
2.2 Sorting and searching: solutions
1. The scaling factors for the linear search and the sort are 0.1
100 = 0.001 and
0.1
100 log 100 = 1
200 = 0.0005, respectively (you may use any convenient base
of the logarithm for computing the running time). Then the overall time
for the scheme A is TA = 0.001 · 107
· 103
= 107
ms, or 104
seconds. The
overall time for B consists of the time to convert the list into an array:
TB,1 = 0.001 · 107
ms, or 10 seconds, and the time for sorting the array:
TB,2 = 0.0005 · 107
· log(107
) = 35 · 103
ms = 35s.
Therefore, the scheme of choice is B.
2. Let an array of size n be split into k subarrays of size n
k . Then the total
time to separately sort the subarrays is k · c · n
k
2
= c · n2
k . Time for
merging k presorted subarrays is c · (k − 1) · n. Thus the total time is
proportional to n2
k + n · (k − 1).
If k = 1 the sorting is O(n2
). If k = n the sorting is also O(n2
). This
suggests that the computational complexity may be less somewhere in be-
tween these bounds.
4
5. Those who know the calculus may easily derive the optimum k by dif-
ferentiating the expression n
k + k − 1 by k and setting it equal to zero:
− n
k2 + 1 = 0, or k =
√
n. Those who do not like mathematics may ex-
ploit the inverse symmetry between the terms n
k and k in this sum. These
terms have the fixed product n = n
k ·k, so they should be set equal for the
optimum point: n
k = k, or k =
√
n. Both variants of getting the result are
acceptable.
The resulting time complexity of this sorting is O(n1.5
) so that the algo-
rithm is better than InsertionSort but worse than MergeSort.
3. The implicit formula T(3m
) = 3T(3m−1
) + 2c3m
can be reduced to
T(3m
)
3m
=
T(3m−1
)
3m−1
+ 2c
thus by telescoping:
T (3m
)
3m = T (3m−1
)
3m−1 + 2c
T (3m−1
)
3m−1 = T (3m−2
)
3m−2 + 2c
· · · · · ·
T (31
)
31 = T (30
)
30 + 2c
T(1) = 0
so that T (3m
)
3m = 2cm, or T(n) = 2cn log3 n
Another solution: by math induction
T(31
) = 3 · T(1) + 2 · 3c = 2 · 3c
T(32
) = 2 · 32
c + 2 ∗ 32
c = 2 · 2 · 32
c
T(33
) = 2 · 2 · 33
c + 2 · 33
c = 2 · 3 · 33
c
Let us assume that T(3k
) = 2ck · 3k
holds for k = 1, . . . , m − 1. Then
T(3m
) = 3 · 2 · (m − 1) · 3m−1
c + 2 · 3m
c = 2 · m · 3m
c
so that the assumption is valid by induction for all values m. The “Big-
Oh” complexity of this algorithm is O(n log n).
4. For Mergesort, T(n) = cn log2 n, therefore, to compare the algorithms one
must derive whether cn log2 n is greater or lesser than 2cn log3 n, that is,
whether log2 n is greater or lesser than 2 log3 n = 2 log3 2 · log2 n. Because
2 log3 2 = 1.262 > 1.0, the algorithm under consideration is slightly slower
than Mergesort.
5. Let an array of size n be split into k subarrays of size n
k . Then the total
time to separately sort the subarrays is k · c · n
k
2
= c · n2
k . Time for
merging k presorted subarrays is c · (k − 1) · n. Thus the total time is
proportional to n2
k + n · (k − 1).
5
6. If k = 1 the sorting is O(n2
). If k = n the sorting is also O(n2
). This
suggests that the computational complexity may be less somewhere in be-
tween these bounds.
Those who know the calculus may easily derive the optimum k by dif-
ferentiating the expression n
k + k − 1 by k and setting it equal to zero:
− n
k2 + 1 = 0, or k =
√
n. Those who do not like mathematics may ex-
ploit the inverse symmetry between the terms n
k and k in this sum. These
terms have the fixed product n = n
k ·k, so they should be set equal for the
optimum point: n
k = k, or k =
√
n. Both variants of getting the result are
acceptable.
The resulting time complexity of this sorting is O(n1.5
) so that the algo-
rithm is better than InsertionSort but worse than MergeSort.
6. Time complexity of the proposed algorithm depends both on data moves
and data comparisons for searching a position of every item.
(a) Because the position of inserting the i-th item may equiprobably be
from 0 to i, in average about i/2 data moves should be done. In total:
1
2
(0 + 1 + . . . + i) =
n(n + 1)
4
(b) Twice more: n(n+1)
2 moves in the worst case
(c) The binary search in the sorted part of i items takes 1
2 log2 i steps in
the average. Thus in total the average number of comparisons is
1
2
[log2 1 + log2 2 + ... + log2 n] =
1
2
log2(n!) ≈
n
2
log2(n)
(d) Twice more, or n log2 n comparisons in the worst case
(e) With respect to comparisons only, it has complexity O(n log n)
(f) With respect to moves, it is still O(n2
)
7. Time for the options (i) and (ii) is T(n) = cpn T(n) = cn log10 n, respec-
tively. Thus, the second option is better when p > log10 n. To minimise
average running time, one has to choose the first option if log10n ≤ p and
the second option otherwise. Because log10106
= 6 < 100, the second
option is the best.
6
7. 8.
Algorithm Worst-case Average-case
Insertion sort O(n2
) O(n2
)
Heapsort O(n log n) O(n log n)
Mergesort O(n log n) O(n log n)
Quicksort O(n2
) O(n log n)
Sequential search O(n) O(n)
Binary search O(log n) O(log n)
9. The maximum heap is created from a given array of n integer keys by
percolating the keys down starting from the largest non-leaf position p =
n/2 (abbreviation PD:k stands for the percolation down starting from
the position k):
Position 1 2 3 4 5 6 7 8 9 10
Array 10 26 52 76 13 8 3 33 60 42
PD:5 10 26 52 76 42 8 3 33 60 13
PD:4 10 26 52 76 42 8 3 33 60 13
PD:3 10 26 52 76 42 8 3 33 60 13
PD:2 10 76 52 26 42 8 3 33 60 13
10 76 52 60 42 8 3 33 26 13
PD:1 76 10 52 60 42 8 3 33 26 13
76 60 52 10 42 8 3 33 26 13
76 60 52 33 42 8 3 10 26 13
Max. heap 76 60 52 33 42 8 3 10 26 13
The initial array and the percolation steps of creating the maximum heap
are shown in figures below.
Initial array:
7
8. Percolation down from the position 5 (PD:5):
Percolation down from the position 2 (PD:2):
8
9. Percolation down from the position 1 (PD:1):
10. The depth-first traversal of a binary search tree puts all the items attached
to the nodes into sorted order. Therefore, to convert the array into such a
tree, one should sort the array, and place the sorted elements in line with
the traversal of the tree. In our case, the depth-first traversal from left
to right gives the following sequence of the nodes relating to the sorted
array:
Node : 8 4 9 2 5 10 1 6 3 7
Element : 3 8 10 13 33 26 42 52 60 76
so that the well-balanced binary search tree similar to the heap is as
follows:
9
10. A binary search tree satisfies the following search order priority: for every
node x in the tree, the values of all the keys in the left subtree are smaller
than or equal to the key in x and the values of all the keys in the right
subtree are greater than the key in x. In a heap, the key of each parent
node is greater than or equal to the key of any child node.
11. The algorithms A and B spend time TA = csortn log2 n and TB = cslctkn,
respectively, to select the desired k items. Therefore, the algorithm B out-
performs the algorithm A if cslctkn ≤ csortn log2 n, i.e. if k ≤ csort
cslct
log2 n.
In accord with the given conditions, csort1024 log2 1024 = 10240csort =
10.24 microseconds for QuickSort, so that csort = 10−3
microseconds per
item. For QuickSelect, cslct1024 = 1.024microseconds, so that cslct = 10−3
microseconds per item. Because k = 512 10−3
10−3 log2 220
= 20. the
algorithm of choice for k = 512 and n = 220
is A.
2.3 Symbol tables and hashing: exercises
1. The NZ Inland Revenue Department assigns a unique 8-digit decimal IRD
number in the range [00,000,000 ... 99,999,999] to every person paying
taxes. Provided that the amount of random access memory (RAM) avail-
able is not restricted, you can sort an arbitrary large database of the IRD
numbers using an integer array of size 100,000,000. Each element of the
array is a counter that counts how many times the IRD number occurs in
the database (zero if the IRD number is absent).
(a) What is the Big-Oh complexity of this algorithm, which is called a
bucket sort, for sorting a database of size N?
(b) What is the Big-Oh complexity of checking whether a given IRD
number is present or absent in the sorted database?
(c) What is the Big-Oh complexity of updating the database by deleting
or inserting a particular number?
(d) Explain, why the bucket sort cannot serve as a general sorting algo-
rithm?
2. Convert an array [10, 26, 52, 76, 13, 8, 3, 33, 60, 42] into a hash table of size
13 using modulo-based hash addressing: address = data value mod 13
and linear probing to resolve collisions. Hint: Modulo operation m mod n
returns the residual of the integer division m/n: e.g., if m = 17, n = 13
then 17/13 = 1 and 17mod 13 = 4. The operation is denoted m%n in
Java.
3. Convert the above array into a hash table of size 13 using modulo-based
hash addressing: address = data value mod 13 and double hashing with
the backward step max{1, data value /13} to resolve collisions.
4. Convert the above array into a hash table of size 13 using modulo-based
hash addressing address = data value mod 13 and chaining to resolve
collisions.
10
11. 2.4 Symbol tables and hashing: solutions
1. The bucket sort has the following properties.
(a) It has complexity O(N) for sorting an arbitrary database of size N.
(b) Complexity of checking whether a given IRD number is present or
absent in the sorted database is O(1).
(c) Complexity of updating the database by deleting or inserting a par-
ticular number is O(1).
(d) The bucket sort cannot serve as a general sorting algorithm because
in the general case the range of data to be sorted is not restricted.
2. The initially empty hash table of size 13 is formed using the hash address
h(k) = kmod 13 and linear probing (with the probe decrement ∆ = −1)
as follows:
Key k Address h(k) Collision resolution
10 10 no collision
26 0 no collision
52 0 collision; probing: (0 − 1)mod 13 = 12
12 no collision
76 11 no collision
13 0 collision; probing: (0 − 1)mod 13 = 12
12 collision; probing: 12 − 1 = 11
11 collision; probing: 11 − 1 = 10
10 collision; probing: 10 − 1 = 9
9 no collision
8 8 no collision
3 3 no collision
33 7 no collision
60 8 collision; probing: 8 − 1 = 7
7 collision; probing: 7 − 1 = 6
6 no collision
42 3 collision; probing: 3 − 1 = 2
2 no collision
The final hash array is
address 0 1 2 3 4 5 6 7 8 9 10 11 12
key 26 – 42 3 – – 60 33 8 13 10 76 52
3. The initially empty hash table of size 13 is formed using the hash address
h(k) = kmod 13 and double hashing probing (with the probe decrement
∆(k) = max{k/13, 1}) as follows:
11
12. Key k Address h(k) ∆(k) Collision resolution
10 10 no collision
26 0 no collision
52 0 4 collision; probing: (0 − 4)mod 13 = 9
9 no collision
76 11 no collision
13 0 1 collision; probing (0 − 1)mod 13 = 12
12 no collision
8 8 no collision
3 3 no collision
33 7 no collision
60 8 4 collision; probing (8 − 4) = 4
4 no collision
42 3 3 collision; probing (3 − 3) = 0
0 collision; probing (0 − 3)mod 13 = 10
10 collision; probing (10 − 3) = 7
7 collision; probing (7 − 3) = 4
4 collision; probing (4 − 3) = 1
1 no collision
The final hash array is
address 0 1 2 3 4 5 6 7 8 9 10 11 12
key 26 42 – 3 60 – – 33 8 52 10 76 13
4. The initially empty hash table of size 13 is formed using the hash address
h(k) = kmod 13 and external chaining as follows:
Key k 10 26 52 76 13 8 3 33 60 42
h(k) 10 0 0 11 0 8 3 7 8 3
Chain 10 26 26 76 26 8 3 33 8 3
52 52 60 42
13
The final hash array with the chains of keys is
address 0 1 2 3 4 5 6 7 8 9 10 11 12
chain 26 – – 3 – – – 33 8 – 10 76 –
52 42 60
13
12