Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

DISCRETE MATHAMTICS

Rating
-
Sold
-
Pages
33
Uploaded on
26-02-2023
Written in
2022/2023

Discrete Mathematics is a branch of mathematics that deals with discrete structures, which are structures that have distinct, separate, and countable elements. It is used to study algorithms, logic, and mathematical reasoning. The subject covers a range of topics, including set theory, graph theory, combinatorics, logic, and probability theory.

Show more Read less
Institution
Course

Content preview

CSC 344 – Algorithms and
Complexity
Lecture #3 – Internal Sorting




What is the Brute Force Approach?
• A straightforward approach, usually based
directly on the problem’s statement and
definitions of the concepts involved
• Examples:
1. Computing an (a > 0, n a nonnegative integer)
2. Computing n!
3. Multiplying two matrices
4. Searching for a key of a given value in a list

, Brute-Force Sorting Algorithm
• Selection Sort
– Scan the array to find its smallest element and swap it with
the first element.
– Starting with the second element, scan the elements after it
to find the smallest among them and swap it with the
second elements.
– Generally, on pass i (0 ≤ i ≤ n-2), find the smallest element
after A[i] and swap it with A[i]:
A[0] ≤ . . . ≤ A[i-1] | A[i], . . . , A[min], . . ., A[n-1]
in their final positions
• Example: 7 3 2 5




Selection Sort
// selectionSort() - The selection sort where we
// seek the ith smallest value and
// swap it into its proper place
void selectionSort(int x[], int n) {
int i, j, min;

for (i = 0; i < n-1; i++) {
min = i;
for (j = i; j < n; j++) {
if (x[j] < x[min])
min = j;
swap(x[i], x[min]);
}
}
}

, Analysis of Selection Sort




• Time efficiency:
• Space efficiency:
• Stability:




Decrease and Conquer
1. Reduce problem instance to smaller instance of the
same problem
2. Solve smaller instance
3. Extend solution of smaller instance to obtain solution
to original instance

• Can be implemented either top-down or bottom-up
• Also referred to as inductive or incremental approach

, 3 Types of Decrease and Conquer
• Decrease by a constant (usually by 1):
– insertion sort
• Decrease by a constant factor (usually by half)
– binary search
– exponentiation by squaring
• Variable-size decrease
– Euclid’s algorithm
– Nim-like games




Insertion Sort
• To sort array A[0..n-1], sort A[0..n-2] recursively and
then insert A[n-1] in its proper place among the
sorted A[0..n-2]
• Usually implemented bottom up (nonrecursively)
• Example: Sort 6, 4, 1, 8, 5
6|4 1 8 5
4 6|1 8 5
1 4 6|8 5
1 4 6 8|5
1 4 5 6 8

Written for

Institution
Course

Document information

Uploaded on
February 26, 2023
Number of pages
33
Written in
2022/2023
Type
Class notes
Professor(s)
Kuldip korat
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
kuldipkorat

Get to know the seller

Seller avatar
kuldipkorat C.K PITHAWALA COLLEGE OF ENGG. AND TECH.
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
3
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions