Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bundle 2. #73

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified bundles/02-algorithms-1/02-algorithms-1.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions bundles/02-algorithms-1/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Onsite Contest
--------------
* https://www.hackerrank.com/inzva-02-algorithm-1-onsite-2018
* https://algoleague.com/contest/algorithm-program-2018-2019-algorithm-onsite/description

Online Contest
--------------
* https://www.hackerrank.com/inzva-02-algorithm-1-online-2018
* https://algoleague.com/contest/algorithm-program-2018-2019-algorithm-online/description
32 changes: 20 additions & 12 deletions bundles/02-algorithms-1/latex/02-algorithms-1.tex
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
\newcommand{\mytitle}
{
\textbf {
inzva Algorithm Programme 2018-2019\\ \ \\
inzva Algorithm Program \\ \ \\
Bundle 2 \\ \ \\
Algorithms - 1 \\ \ \\
}
Expand All @@ -162,7 +162,9 @@
Kadir Emre Oto \\ \ \\
\textbf{Reviewers} \\
Muhammed Burak Buğrul \\
Tahsin Enes Kuru
Tahsin Enes Kuru \\ \ \\
\textbf{Contributors} \\
Aybala Karakaya \\
}

\date{}
Expand All @@ -189,7 +191,8 @@
\subsection{Linear Search}

Simplest search algorithm is \textit{linear search}, also know as \textit{sequential search}. In this technique, all elements in the collection of the data is checked one by one, if any element matches, algorithm returns the index; otherwise, it returns -1. \\ \\
ity is $O(N)$
\textbf{Complexity: }
$O(N)$

\begin{figure}[h]
\centering
Expand All @@ -212,15 +215,15 @@

\subsection{Binary Search}

We know linear search is quite a slow algorithm because it compares each element of the set with search key, and there is a high-speed searching technique for \textbf{sorted} data instead of linear search, which is \textbf{binary search}. After each comparison, the algorithm eliminates half of the data using the sorting property.
Linear search is quite a slow algorithm because it compares each element of the set with a search key. There is a high-speed searching technique for \textbf{sorted} data instead of linear search. This technique is called the \textbf{binary search}. After each comparison, the algorithm eliminates half of the data using the sorting property.

We can also use binary search on increasing functions in the same way.

\textbf{Procedure: }
\begin{itemize}
\item Compare the key with the middle element of the array,
\item If it is a match, return the index of middle.
\item If the key is bigger than the middle, it means that the key must be in the right side of the middle. We can eliminate the left side.
\item If it is a match, return the index of the middle.
\item If the key is bigger than the middle, it means that the key must be on the right side of the middle. We can eliminate the left side.
\item If the key is smaller, it should be on the left side. The right side can be ignored.
\end{itemize}

Expand Down Expand Up @@ -316,15 +319,17 @@
\section{Sorting Algorithms}


Sorting algorithms are used to put the elements of an array in a certain order according to the comparison operator. Numerical order or lexcographical orders are the most common ones, and there are a large number of sorting algorithms, but we discuss four of them: \textit{Insertion Sort}, \textit{Merge Sort}, \textit{Quick Sort}, \textit{Radix Sort}.
Sorting algorithms are used to put the elements of an array in a certain order according to the comparison operator. Numerical order or lexicographical orders are the most common ones, and there are a large number of sorting algorithms, but we discuss four of them: \textit{Insertion Sort}, \textit{Merge Sort}, \textit{Quick Sort}, \textit{Radix Sort}.

For a better understanding, you are strongly recommended to go into this visualization site after reading the topics: \href{https://visualgo.net/en/sorting}{Link}
For a better understanding, you are strongly recommended to go to this visualization site after reading the topics: \href{https://visualgo.net/en/sorting}{Link}

\subsection{Insertion Sort}

Think that you are playing a card game and want to sort them before the game. Your sorting strategy is simple: you have already sorted some part and every time you pick up the next card from unsorted part, you insert it into the correct place in sorted part. After you apply this process to all cards, the whole deck would be sorted. \\ \\
This is the basic idea for sorting an array. We assume that the first element of the array is the sorted part, and other elements are in the unsorted part. Now, we choose the leftmost element of the unsorted part, and put it into the sorted part. In this way the left part of the array always remains sorted after every iteration, and when no element is left in the unsorted part, the array will be sorted.

\textbf{Complexity: }
O($N^{2}$).

\begin{minted}[frame=lines,linenos,fontsize=\footnotesize]{c++}
void insertionSort(int *ar, int size){
Expand All @@ -338,7 +343,7 @@

\subsection{Merge Sort}

\textit{Merge Sort} is one of the fastest sorting algorithms that uses \textit{Divide and Conquer} paradigm. The algorithm \textbf{divides} the array into two halves, solves each part \textbf{recursively} using same sorting function and \textbf{combines} them in linear time by selecting the smallest value of the arrays every time.
\textit{Merge Sort} is one of the fastest sorting algorithms that uses \textit{Divide and Conquer} paradigm. The algorithm \textbf{divides} the array into two halves, solves each part \textbf{recursively} using the same sorting function and \textbf{combines} them in linear time by selecting the smallest value of the arrays every time.

\textbf{Procedure: }
\begin{enumerate}
Expand Down Expand Up @@ -424,7 +429,10 @@

\textbf{Procedure: }
\begin{enumerate}
\item For each digit from the least significant to the most, sort the array using \textit{Counting Sort} according to corresponding digit. \textit{Counting Sort} is used for keys between specific range, and it counts the number of elements which have different key values. After counting the number of distict key values, we can determine the position of elements in the array.
\item Start from the least significant digit of the integers being sorted.
\item Apply \textit{Counting Sort} to the entire array based on the digit at the current position. We use \textit{Counting Sort} to compute a cumulative count of the number of integers that are less than or equal to each integer in the array based on their digit at the current position. This count is used to determine the final position of each integer in the sorted array.
\item If we are not considering the most significant digit, move to the digit on the left and repeat Step 2.
\item If we have considered all digits, the array is now sorted in ascending order based on the digits of the integers.
\end{enumerate}

\textbf{Complexity: }
Expand Down Expand Up @@ -470,12 +478,12 @@
\cleardoublepage
\section{Quickselect Algorithm}

\textit{Quickselect} is a selection algorithm that \textit{finds the k-th smallest element in an unordered list}. The algorithm is closely related to QuickSort in partitioning stage; however, instead of recurring for both sides, it recurs only for the part that contains the k-th smallest element.
\textit{Quickselect} is a selection algorithm that \textit{finds the k-th smallest element in an unordered list}. The algorithm is closely related to QuickSort in the partitioning stage; however, instead of recurring for both sides, it recurs only for the part that contains the k-th smallest element.

\textbf{Procedure: }
\begin{enumerate}
\item Choose a pivot randomly,
\item For all values in the array, collect smaller values in the left of the array and greater values in the right of the array,
\item For all values in the array, collect smaller values on the left of the array and greater values on the right of the array,
\item Move the pivot to the correct place,
\item If the current position is equal to k, return the value at the position.
\item If the current position is more than k, repeat the same algorithm for the left partition.
Expand Down