<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fidan Alizada on Medium]]></title>
        <description><![CDATA[Stories by Fidan Alizada on Medium]]></description>
        <link>https://medium.com/@fidanalizada95?source=rss-be5b67a192a0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mGUIBNf45__qWfV7.jpg</url>
            <title>Stories by Fidan Alizada on Medium</title>
            <link>https://medium.com/@fidanalizada95?source=rss-be5b67a192a0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:05:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fidanalizada95/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ClickHouse #6: MergeTree in Practice,Data Parts, Sorting Keys, Sparse Primary Indexes]]></title>
            <link>https://medium.com/@fidanalizada95/clickhouse-6-mergetree-in-practice-data-parts-sorting-keys-sparse-primary-indexes-a3a7bb7605ec?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3a7bb7605ec</guid>
            <category><![CDATA[dataengineering-future]]></category>
            <category><![CDATA[dbms]]></category>
            <category><![CDATA[clickhouse]]></category>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Wed, 18 Nov 2026 20:17:24 GMT</pubDate>
            <atom:updated>2026-11-18T20:17:24.363Z</atom:updated>
            <content:encoded><![CDATA[<p>In Clickhouse how data is managed in tables defined by table engines.Nature,size,load of data,consistency requirements are not always the same for all type of data. Therefore Clickhouse has differenct table engine types in order to handle different types of data.Choosing the right engine type increases performance and efficiency.Unlike tradational database management systems in Clickhouse we can decide how to manage engine process.By engine process actually is considered 4 diffrent things like:</p><p><strong>1.How data is stored on disk</strong></p><p><strong>2.How data is indexed</strong></p><p><strong>3.How data is merged</strong></p><p><strong>4.What operations are supported</strong></p><p>For example,some engines support replications,meanwhile some engines are read-only. Engine type in some way is an aggreement table and data processing.Clickhouse has diffrent engine family groups like <strong>MergeTree family,Log family,Integration engines,Special-purpose engines:</strong>For most workloads, you will spend almost all of your time in the MergeTree family. The others exist for specific situations.In this article we will focus on MergeTree family.MergeTree table engine mainly is for huge amount of data.MergeTree table engine can be considered the default table engine for single-node ClickHouse instances.ClickHouse is a column-oriented database management system. This means that data is stored by columns rather than by rows. When executing a query, ClickHouse can read only the columns required by that query, reducing unnecessary disk I/O and improving query performance.In Clickhouse, data is stored in data parts.Data parts are immutable.</p><pre>CREATE TABLE sales_info<br>(<br>    date Date,<br>    town LowCardinality(String),<br>    street LowCardinality(String),<br>    price UInt32<br>)<br>ENGINE = MergeTree<br>ORDER BY (town, street);<br>INSERT INTO sales_info VALUES<br>(&#39;2026-11-01&#39;, &#39;Baku&#39;, &#39;Nizami&#39;, 150),<br>(&#39;2026-11-01&#39;, &#39;Baku&#39;, &#39;28 May&#39;, 200),<br>(&#39;2026-11-01&#39;, &#39;Ganja&#39;, &#39;Ataturk&#39;, 100);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sgFaKxjdOCzHQwnvw0LD6g.png" /></figure><p>In this example, we can see that the data part is active.A new data part is created when a set of rows is inserted into a MergeTree table. Each inserted block of data is written as a separate data part for each affected partition.To control the number of active data parts in a table, ClickHouse performs background merges. During this process, smaller data parts are combined into larger ones.The merged parts replace the original parts and become active, while the original parts are marked as inactive. Inactive parts are eventually removed after a certain period, provided they are no longer needed by ongoing queries or other operations.Retention period for deleting inactive parts is by default 8 minutes.Retention period is defined by old_parts_lifetime parametr.Also, it is important to note that merging process is not blocked select queries.Now I inserted 5 new rows to sales_info table.</p><pre>INSERT INTO sales_info VALUES<br>(&#39;2026-11-01&#39;, &#39;Baku&#39;, &#39;Nizami&#39;, 150),<br>(&#39;2026-11-01&#39;, &#39;Baku&#39;, &#39;28 May&#39;, 200),<br>(&#39;2026-11-01&#39;, &#39;Ganja&#39;, &#39;Ataturk&#39;, 100),<br>(&#39;2026-11-01&#39;, &#39;Sumgait&#39;, &#39;Sahil&#39;, 180),<br>(&#39;2026-11-01&#39;, &#39;Baku&#39;, &#39;Fountain Square&#39;, 250);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UbhZAFTff06elkFTk8coUQ.png" /></figure><p>Now, there are 2 parts.Now after running below query</p><pre><br>OPTIMIZE TABLE sales_info FINAL;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZY8JOqHPseMNDUJJDKgHLQ.png" /></figure><p>Now, we can see there is only one active part after merging process.Also we can consider level column.The level of a data part represents its merge depth. Newly inserted parts typically start at level 0, while parts created through background merges receive a higher level.The merge level is incremented by one with each additional merge on the part.</p><p>Order by clause defines how data is sorted on disk within each data part.So, it is called sorting key.If primary key is not provided explicitky it defind by sorting key. If a separate PRIMARY KEY is specified, it must be a prefix of the sorting key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jM1-v-UXz0ZHPLx-ntm39A.png" /></figure><p>ClickHouse physically <strong>sorts data on disk</strong> by the ORDER BY clause. Let us consider different scenarios:</p><ul><li>If you specify both they can differ (but with constraints).</li><li>If you only specify PK, it’s used also for ORDER BY.</li></ul><p>In Clickhouse PK does not guarantee uniqueness of column value.Benefit of primary key is the building sparse index. It means, in Clickhouse PK does not index every row insted it indexs data by granule.It is possible because of storing data in parts.he sparse primary index stores the corresponding Primary Key values for granules, while marks provide the information needed to locate the corresponding data granules on disk.By default granularity level is 8192 rows.It is defined by index_granularity parametr.Since data is physically sorted by the sorting key within each data part, ClickHouse can use the sparse primary index to locate the relevant granules and then read the corresponding data sequentially.This approach is particularly efficient for analytical workloads because sequential reads are generally more efficient than performing numerous random disk reads.Now let us consider how Clickhouse skips indexes.</p><pre>INSERT INTO sales_info<br>SELECT<br>    toDate(&#39;2026-11-01&#39;) AS date,<br>    if(<br>        intDiv(number, 10000) = 42,<br>        &#39;Baku&#39;,<br>        concat(<br>            &#39;town_&#39;,<br>            leftPad(toString(intDiv(number, 10000)), 3, &#39;0&#39;)<br>        )<br>    ) AS town,<br>    concat(<br>        &#39;street_&#39;,<br>        leftPad(toString(number % 100), 3, &#39;0&#39;)<br>    ) AS street,<br>    toUInt32(number % 10000) AS price<br>FROM numbers(1000000);</pre><p>To demonstrate sparse primary index usage, I inserted additional rows into the sales_info table and executed the same query again.As shown in the EXPLAIN output, ClickHouse selected only 3 granules out of 123 for the filtering condition town=’Baku’.This demonstrates how the sparse primary index helps ClickHouse skip irrelevant granules and reduce the amount of data that needs to be read.</p><p>To understand the impact of sorting key column order, I tested different filtering condition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hYJCJeyYeR1RZzj9lWMxWg.png" /></figure><p>When filtering by town, ClickHouse selected only 3 out of 123 granules. However, when filtering by street, it selected 111 out of 123 granules.This demonstrates why the order of columns in a composite sorting key matters. Queries filtering by leading sorting key columns can benefit more from the sparse primary index, while filtering only by subsequent columns may result in less effective data skipping.Understanding the MergeTree engine is essential for understanding how ClickHouse stores, organizes, and reads data.I have explored how INSERT operations create immutable data parts, how background merges combine smaller parts into larger ones, and how the sorting key determines the physical order of data within each part.I have also examined the relationship between the PK and Sorting Key, how sparse primary indexes work with granules and marks, and how ClickHouse uses index pruning to skip unnecessary data during query execution.One of the most important takeaways is that choosing an appropriate sorting key can significantly affect query performance. The order of columns in a composite sorting key matters because it determines how effectively ClickHouse can use the sparse primary index.</p><p><strong>Test Your Knowledge:</strong></p><p><strong>What happens when you insert a new block of data into a MergeTree table?</strong></p><p><strong>What is the main difference between Sorting Key and Primary Key in MergeTree?</strong></p><p><strong>What is a sparse primary index?</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3a7bb7605ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ClickHouse #5: JOIN Algorithms -A Practical Guide]]></title>
            <link>https://medium.com/@fidanalizada95/clickhouse-5-join-algorithms-a-practical-guide-81ef2dffbdde?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/81ef2dffbdde</guid>
            <category><![CDATA[sql-joins]]></category>
            <category><![CDATA[clickhouse]]></category>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Tue, 06 Oct 2026 11:44:55 GMT</pubDate>
            <atom:updated>2026-10-06T11:44:55.824Z</atom:updated>
            <content:encoded><![CDATA[<p>As we know from standard SQL, data is not always stored in a single table. Sometimes the data we need is stored in different tables.In such cases, we can use JOIN to combine related data from different tables.ClickHouse supports the standard JOIN types defined in ANSI SQL.Also there are additional join types as semi, anti, any,asof join.</p><p><strong>SEMI JOIN</strong> returns rows from the left table that have a matching row in the right table, without returning columns from the right table.</p><p><strong>ANTI JOIN</strong> does the opposite: it returns rows from the left table that do not have a matching row in the right table.</p><p><strong>ANY JOIN</strong> returns only one matching row when multiple matches exist.</p><p><strong>ASOF JOIN</strong> is designed for joining data based on the closest matching value, which makes it especially useful for time-series data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5xYVxgfjm0H9I49dl0Kdkw.png" /></figure><p>That’s why, in this article, instead of focusing on JOIN syntax, we will focus on JOIN algorithms and performance.When we join two tables, ClickHouse needs to find matching rows between them. The way ClickHouse performs this operation depends on the JOIN algorithm.In Clickhouse there 6 different join alghorithms.ClickHouse can use different JOIN algorithms depending on the query and data characteristics. The choice of algorithm can have a significant impact on memory usage and query performance. ClickHouse can automatically choose an algorithm when join_alghortihm is set to auto, or we can explicitly specify one when needed.Now in order to compare different alghoritms let us create two tables.</p><pre>CREATE TABLE customers<br>(<br>    customer_id UInt32,<br>    customer_name String,<br>    country LowCardinality(String)<br>)<br>ENGINE = MergeTree<br>ORDER BY customer_id;<br><br>INSERT INTO customers<br>SELECT<br>    number AS customer_id,<br>    concat(&#39;Customer_&#39;, toString(number)) AS customer_name,<br>    arrayElement(<br>        [&#39;Azerbaijan&#39;, &#39;Turkey&#39;, &#39;Georgia&#39;, &#39;Germany&#39;, &#39;USA&#39;],<br>        (number % 5) + 1<br>    ) AS country<br>FROM numbers(1000000);<br><br>CREATE TABLE orders<br>(<br>    order_id UInt64,<br>    customer_id UInt32,<br>    order_date Date,<br>    amount Decimal(10, 2)<br>)<br>ENGINE = MergeTree<br>ORDER BY order_id;<br><br>INSERT INTO orders<br>SELECT<br>    number AS order_id,<br>    number % 1000000 + 1 AS customer_id,<br>    toDate(&#39;2026-01-01&#39;) + (number % 30) AS order_date,<br>    round(randUniform(10, 1000), 2) AS amount<br>FROM numbers(10000000);</pre><p>Firstly, we will review hash algorithm.</p><pre>SET join_algorithm = &#39;hash&#39;;<br>SELECT<br>    o.order_id,<br>    o.customer_id,<br>    c.customer_name,<br>    c.country,<br>    o.amount<br>FROM orders AS o<br>INNER JOIN customers AS c<br>    ON o.customer_id = c.customer_id;</pre><p>In general,three of the ClickHouse join algorithms are based on in-memory hash tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IascIqv0RzB2H93o78-_FA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ma1k5LbdAAVZSfyqD_bkYQ.png" /></figure><p><strong>1.Hash JOIN</strong> is a fast and general-purpose JOIN algorithm. It supports different JOIN types and strictness settings. However, it can consume a significant amount of memory because it builds an in-memory hash table from the right-hand side table.Another limitation is that building the hash table is single-threaded. If the right-hand side table is very large, building the hash table can become a bottleneck and increase the overall query execution time.In my example, I first used the smaller customerstable on the right side of the JOIN. When I switched the tables, the query became much more resource-intensive and eventually reached the time limit. This shows why the size of the right-hand side table can be important when using Hash JOIN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjWfTbUejwYH9vlSWqplDg.png" /></figure><p><strong>2.Parallel Hash JOIN</strong> is similar to Hash JOIN, but it builds several hash tables in parallel instead of building a single hash table.This can make the JOIN faster, especially when the right-hand side table is large. However, because multiple hash tables are created, Parallel Hash JOIN requires more<strong> </strong>memory than the regular Hash JOIN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kvGw6yIc7YFYa4z0C35KZg.png" /></figure><p>In my experiment, the same JOIN query reached the time limit when using Hash JOIN. When I switched to Parallel Hash JOIN, the query completed successfully. This shows how parallel hash table construction can improve JOIN performance, especially when working with large tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwL2SeLyusWn24C5qBrW1w.png" /></figure><p><strong>3.Grace Hash JOIN i</strong>s useful when a regular Hash JOIN cannot efficiently handle the data in memory. It partitions the data into smaller buckets and processes these partitions separately, reducing memory pressure.The main advantage of Grace Hash JOIN is lower memory usage, while its main disadvantage is additional disk I/O and lower performance compared with in-memory hash joins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpXVYg2tE6lDrbYlS29u0w.png" /></figure><p><strong>4.Full Sorting Merge JOIN</strong> uses a different approach compared with hashh join.Instead of building a hash table ClickHouse sorts both tables by the key and then merges the sorted data to find matching rows.For example, in our query the join key is customer_id. ClickHouse sorts the data by customer_id and then compares the sorted values from both tables.If the data is already sorted by the join key, ClickHouse may be able to skip the sorting step. This can make Full Sorting Merge JOIN more efficient.</p><p><strong>Partial Merge JOIN</strong> is mainly used when we want to reduce memory usage during a join operatoon.Firstly ClickHouse sorts the right-hand side table and stores the sorted data on disk. Then, it sorts the left-hand side table block by block in memory and joins the data.This approach uses less memory, but it can be slower because sorting and disk operations take extra time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A1j0O5XBbExWTiSucxg4Nw.png" /><figcaption>Source: ClickHouse Documentation</figcaption></figure><p>As we can see, there is no single join algorithm that is always the best choice. The right algorithm depends on the table size, data sorting, available memory, and query requirements.In this article, I looked at the main join types in ClickHouse and focused on the different join algorithms and their performance. I also tested algorithms using my example tables to better understand how they work in practice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81ef2dffbdde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ClickHouse #4: Data Types in Practice:Standard SQL &ClickHouse-Specific Types]]></title>
            <link>https://medium.com/@fidanalizada95/clickhouse-4-data-types-in-practice-standard-sql-clickhouse-specific-types-06dbbaf432a0?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/06dbbaf432a0</guid>
            <category><![CDATA[dataengineering-future]]></category>
            <category><![CDATA[dbms]]></category>
            <category><![CDATA[olap]]></category>
            <category><![CDATA[clickhouse]]></category>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Sat, 26 Sep 2026 20:00:05 GMT</pubDate>
            <atom:updated>2026-09-26T20:00:05.417Z</atom:updated>
            <content:encoded><![CDATA[<p>In Clickhouse, data types are grouped into data type families.We can see all data types using system.data_type_families system table.The alias column shows whether a data type is an alias for another data type. For example, some type names can be used as alternative names for the same underlying data type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n0JkJfA89VJ9cb7beUGv_w.png" /></figure><p>The case_insenstive column shows whether the data type name is case-insensitive.Now let us briefly review the data type families because some of them are also common in standard ANSI SQL.</p><p><strong>Numeric types</strong> (Int8,Int16,Int32, Int64,Int128,Int256,UInt8,UInt16,UInt32, UInt64,UInt128,UInt256) :</p><p>Int8 … Int256 are signed integers with a fixed size. These types have a range of [-2^(n-1),2^(n-1)-1] where n is the number of bits.Unsigned integer types (UInt8…UInt256) can store only non-negative values. Their range is [0,2^(n-1)].</p><p><strong>Float (Float32,Float64)</strong>:</p><p>Float32 and Float64 are floating-point numbers with single and double precision, respectively. They are used to store numbers with fractional parts.</p><p><strong>Decimal:</strong></p><p>General syntax: Decimal(P, S).</p><p>P — total number of digits (<strong>precision</strong>)</p><p>S— number of digits after the decimal point (<strong>scale</strong>).</p><p><strong>Bool:</strong></p><p>The Bool data type stores two possible values:<strong> true</strong> and <strong>false</strong>. It is useful for storing boolean conditions or status values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qE7ZhakY1tLOKem81jXILA.png" /></figure><p><strong>String:</strong></p><p>The String data type is used to store strings of arbitrary length. It can contain text, characters, and other byte sequences.</p><p><strong>Date:</strong></p><p>ClickHouse provides several date and time data types, including Date,Date32,DateTime,DateTime64 which can be used to store dates, timestamps, and timestamps with fractional seconds.</p><p><strong>Composite data types:</strong></p><p>Composite data types allow us to store multiple values within a single column. ClickHouse provides several composite data types, including Array,Tuple,Map,Nested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hMInUZhKG-THiTppr6DnEQ.png" /></figure><p>If you are familiar with Python, understanding ClickHouse composite data types becomes easier. You can think of them as similar to some of Python’s built-in data structures.For example, an Array in ClickHouse is similar to a Python list because both can contain multiple values. A Tuple is similar to a Python tuple, where multiple values are grouped together. A Map is similar to a Python dict where data is stored as key-value pairs.This analogy makes it easier to understand how ClickHouse handles more complex data structures within a column.</p><p><strong>Nullable:</strong></p><p>Syntax: Nullable(T).T is an data type. Nullable allows a column to store NULL values in addition to its regular data type.However, Nullable comes with a performance and storage overhead. ClickHouse needs to maintain an additional NULL mask to keep track of which values are NULL. This means that Nullable columns can require additional storage and may add some processing overhead during queries.A Nullable type field can’t be included in table indexes.</p><pre>CREATE TABLE users3<br>(<br>    id UInt32,<br>    age Nullable(UInt8)<br>)<br>ENGINE = MergeTree<br>ORDER BY id;<br><br>CREATE TABLE users4<br>(<br>    id UInt32,<br>    age UInt8<br>)<br>ENGINE = MergeTree<br>ORDER BY id;<br><br>INSERT INTO users3<br>SELECT<br>    number,<br>    if(number % 2 = 0, NULL, number % 100)<br>FROM numbers(1000000);<br>INSERT INTO users4<br>SELECT<br>    number,<br>    if(number % 2 = 0,0, number % 100)<br>FROM numbers(1000000);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KzBSmnJf5HOMqqLR2lt1Gg.png" /></figure><p>To demonstrate the storage overhead of Nullable I created two identical tables with the same data. The only difference is the age column: Nullable(UInt8) in one table and UInt8 in the other. The nullable column uses slightly more storage because ClickHouse maintains an additional NULL mask.In this example, the difference is small because ClickHouse compresses the data efficiently. However, Nullable still introduces additional storage and processing overhead.</p><p><strong>Lowcardinality:</strong></p><p>LowCardinality is useful for columns that contain a relatively small number of unique values, especially String columns. For example, a country column may contain millions of rows but only hundreds of different countries. ClickHouse stores the unique string values in a dictionary and uses numeric references internally. This can reduce storage and make comparisons faster. However, LowCardinalty is not limited to very small numbers of unique values; it can also be useful with tens of thousands of distinct values, depending on the data and workload.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06dbbaf432a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ClickHouse #3: Inserting data in practice:batch, async examples]]></title>
            <link>https://medium.com/@fidanalizada95/clickhouse-3-inserting-data-in-practice-batch-async-examples-f0c6031c9f41?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0c6031c9f41</guid>
            <category><![CDATA[olap]]></category>
            <category><![CDATA[clickhouse]]></category>
            <category><![CDATA[dbms]]></category>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Fri, 25 Sep 2026 20:46:50 GMT</pubDate>
            <atom:updated>2026-09-25T20:46:50.872Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will look at how data is inserted into ClickHouse and why the way we insert data can affect performance.ClickHouse uses column-oriented storage and compression which allows it to efficiently handle millions of rows.In ClickHouse there are two common approach of inserting for example, batch insert and async insert.Let me show basic insert statement syntax:</p><pre>INSERT INTO [TABLE] [db.]table [(c1, c2, c3)] [SETTINGS ...] <br>VALUES (v11, v12, v13), (v21, v22, v23), ...</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m9nGevpULcwpsEm18QjtWA.png" /></figure><p>Here, I inserted one row into the sales table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rn_RD72e55eBo8WrHTf3zQ.png" /></figure><p>This is an example of batch insert.This reduces the number of insert requests and is generally more efficient than inserting each row separately.If a list of columns does not include all existing columns, the rest of the columns are filled with:</p><ul><li>The values calculated from the DEFAULT expressions specified in the table definition.</li><li>Zeros and empty strings, if DEFAULT expressions are not defined.</li></ul><p>Each insert creates a new part.Parts are merged periodically.This means that batch inserts are more efficient than inserting one row at a time.If large batches aren’t possible there is an asynchronous option.Now, let’s look at asynchronous inserts and see how they work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*6v0E3gBiD7AMKvteoyDe-w.png" /></figure><p>Here, I enabled asynchronous inserts using async_insert = 1. ClickHouse can buffer the incoming data and write it to storage asynchronously. Asynchronous inserts shift batching responsibility from the client to the server.Both approaches can improve insert efficiency, but they solve slightly different problems. Batch inserts reduce the number of INSERT requests by sending multiple rows together, while asynchronous inserts allow ClickHouse to buffer incoming data.When the buffer reaches the configured threshold, or the configured time limit is reached, ClickHouse flushes the data to storage.</p><p>In ClickHouse we can insert data from another table using a single INSERT statement, similar to traditional databases.This is called INSERT INTO …SELECT. It allows us to select data from one table and insert the result into another table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9GiugGaBAAKSPWQu-Y2U_w.png" /></figure><p>ClickHouse supports different data formats for inserting data. Some commonly used formats are CSV, JSON, TSV, and Parquet.</p><p>Example1 (TSV):</p><pre>INSERT INTO sales<br>FORMAT TabSeparated<br>9 2026-01-08 Azerbaijan 900<br>10 2026-01-08 Turkey 1000</pre><p>Example2 (S3 table function):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOTRDz8Fw54lI7AzDOhEgg.png" /></figure><p>Example3 (Json):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p20jPSpijtvia_QPokPobA.png" /></figure><p>In this article, I looked at different ways to insert data into ClickHouse, including batch inserts, INSERT INTO …SELECT , different data formats, and asynchronous inserts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0c6031c9f41" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clickhouse #2: Understanding Architecure]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@fidanalizada95/clickhouse-2-understanding-architecure-bb5aef7eae50?source=rss-be5b67a192a0------2"><img src="https://cdn-images-1.medium.com/max/2346/1*_O_Wnmny59MFURGUwddAnQ.png" width="2346"></a></p><p class="medium-feed-link"><a href="https://medium.com/@fidanalizada95/clickhouse-2-understanding-architecure-bb5aef7eae50?source=rss-be5b67a192a0------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@fidanalizada95/clickhouse-2-understanding-architecure-bb5aef7eae50?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb5aef7eae50</guid>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Mon, 21 Sep 2026 12:53:30 GMT</pubDate>
            <atom:updated>2026-10-03T14:18:36.442Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Clickhouse #1: Understanding ClickHouse, OLAP, and Columnar Storage]]></title>
            <link>https://medium.com/@fidanalizada95/clickhouse-1-understanding-clickhouse-olap-and-columnar-storage-71378a6afd24?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/71378a6afd24</guid>
            <category><![CDATA[real-time-analytics]]></category>
            <category><![CDATA[olap]]></category>
            <category><![CDATA[clickhouse]]></category>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 21:08:23 GMT</pubDate>
            <atom:updated>2026-09-08T22:02:33.320Z</atom:updated>
            <content:encoded><![CDATA[<h3>ClickHouse #1: Understanding ClickHouse, OLAP, and Columnar Storage</h3><p>Real-time analytics is the process of collecting, processing, and querying data within milliseconds of an event happening so you can act on current information.ClickHouse can handle huge volumes of data.Real-time analysis requires higher costs and complexity compared with batch processing.As the volume of data continues to grow, organizations need systems that can process and analyze massive amounts of data quickly. ClickHouse is designed specifically for analytical workloads and can efficiently handle huge volumes of data.ClickHouse is a fast,open-source,columnar database managament system designed for online analytical processing (OLAP) and real-time data reporting. Let us consider OLAP. There are two types of database workload: OLTP which means Online Transaction Processing and OLAP which means online analytical processing.A lot of things we can differentiate in these categories. OLTP is designed for operational workloads, such as inserting, updating, and retrieving individual records as part of application transactions.OLAP is for analytical reads.OLTP is mainly row-oriented, OLAP is a column oriented.This difference is particularly important for analytical queries because an OLAP query often needs only a subset of columns from a very large dataset.OLTP designed with normalised schemas, OLAP is mainly designed for denormalised ones.Clickhouse name means Clickstream datawarehouse.ClickHouse is SQL-based.Clickhouse logically groups tables in databases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*3peVadDL4o7LiUMnJQWJZA.png" /></figure><p>In clickhouse database is like a schema.In databases we store tables.Every table has a an engine.We will consider this topic in another article.Row oriented and column-oriented databases differs in the way they store data in disk. Row-oriented databases stores rows contiguosly but column-oriented databases store each column’s data contiguosly.A column-oriented database can focus on reading the required columns instead of reading all the columns of every row.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*6mjhwIMH9OOxwCub-onnbw.png" /></figure><p>In analytical queries we usually need only a few columns from a very large dataset.Column-oriented storage allows the database to read only the required columns,which can significantly reduce I/O and make queries faster.Its architecture is designed for analyticalworkloads.In an OLAP database, data is stored column by column, while in an OLTP database, data is typically stored row by row. For example, when we run SUM(salary), a column-oriented database can read only the salary column. In a row-oriented database, the database may need to read the rows containing the salary values, including other columns stored with those rows. Therefore, column-oriented storage can reduce I/O for analytical queries.Understanding the difference between OLTP and OLAP and especially between row-oriented and column-oriented storage, gives us the foundation for understanding why ClickHouse works the way it does.In the next article, we will take a closer look at ClickHouse architecture and how data is stored and processed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71378a6afd24" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Merge Sort Explained: How It Achieves O(n log n)]]></title>
            <link>https://medium.com/@fidanalizada95/merge-sort-explained-how-it-achieves-o-n-log-n-4fecdb85eeae?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fecdb85eeae</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[sorting]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Fri, 05 Jun 2026 10:41:50 GMT</pubDate>
            <atom:updated>2026-06-05T10:41:50.503Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most efficient sorting algorithms is Merge Sort. Its fundamental working principle is based on the Divide and Conquer approach and recursion. The foundation of this algorithm was established in 1945 by John von Neumann, and it is still considered one of the most important sorting algorithms in computer science today.</p><p>Merge Sort consists of two main phases:</p><p><strong>Divide:</strong> The list is recursively divided into two halves until each sublist contains only a single element.</p><p><strong>Merge:</strong> The resulting sublists are then merged back together in sorted order, producing the final sorted list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_r4RoA7rfeTRg4ypH6YX-w.png" /></figure><p>Let’s look at the Python implementation of the Merge Sort algorithm.</p><pre>def merge_sort(nums):<br>    if len(nums) &lt;= 1:<br>        return nums<br><br>    mid = len(nums) // 2<br><br>    left = merge_sort(nums[:mid])<br>    right = merge_sort(nums[mid:])<br><br>    return merge(left, right)<br>    <br>def merge(left, right):<br>    result = []<br>    i = j = 0<br><br>    while i &lt; len(left) and j &lt; len(right):<br>        if left[i] &lt; right[j]:<br>            result.append(left[i])<br>            i += 1<br>        else:<br>            result.append(right[j])<br>            j += 1<br><br>    result.extend(left[i:])<br>    result.extend(right[j:])<br><br>    return result</pre><p>Unlike Quick Sort, one of the greatest advantages of Merge Sort is that its performance does not depend on the order of the input data. Whether the data is already sorted, randomly arranged, or sorted in reverse order, the algorithm performs the same number of divide and merge operations.</p><p>As a result, the time complexity of Merge Sort remains the same in the best, average, and worst cases:</p><p><strong>O(n log n)</strong></p><p>To understand why, let’s consider the following list:</p><p>[38, 27, 43, 3, 9, 82, 10, 1]</p><p><strong>Level 0:</strong></p><p>8 elements</p><pre>[38, 27, 43, 3, 9, 82, 10, 1]</pre><p><strong>Level 1:</strong></p><p>The 8 element list is divided into two halves:</p><pre>[38, 27, 43, 3]      [9, 82, 10, 1]</pre><p><strong>Level 2:</strong></p><p>The 4 element list is divided into two halves:</p><pre>[38, 27] [43, 3]      [9, 82] [10, 1]</pre><p><strong>Level 3:</strong></p><p>Each 2 element sublist is split into individual elements:</p><pre>[38] [27] [43] [3] [9] [82] [10] [1]</pre><p>The division process stops here, as each sublist contains only one element. Since log_2(8) = 3, the divide phase consists of 3 levels. We can now move on to the merge phase.</p><p>Let’s start by merging the sublists at Level 3:</p><pre>[38] + [27] =[27,38]<br><br>[43] + [3] =[3,43]<br><br>[9] + [82] =[9,82]<br><br>[10] + [1] =[1,10]</pre><p>If we merge the sublists at Level 2:</p><pre>[27,38] =[3,43]<br><br>[3,27,38,43]<br><br>[9,82] + [1,10]<br><br>[1,9,10,82]</pre><p>Next, we merge the two sorted sublists at Level 1:</p><pre>[3,27,38,43]<br>+<br>[1,9,10,82]<br>=<br><br>[1,3,9,10,27,38,43,82]</pre><p>At each level, all 8 elements are processed exactly once. Since there are 3 levels in the recursion tree, the total amount of work performed is 8*3=24.In general, for a list of size n, the recursion tree has log₂(n) levels, and each level processes n elements. Therefore, the overall time complexity of Merge Sort is O(n log n).</p><p>One drawback of Merge Sort is that it is not an in-place sorting algorithm. During the merge phase, additional memory is required to store temporary arrays while combining the sorted sublists. As a result, the space complexity of Merge Sort is O(n).</p><p>Despite its extra memory requirements, Merge Sort remains an excellent choice for large datasets and systems where predictable performance is important, as it consistently achieves O(n log n) time complexity regardless of the input order.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fecdb85eeae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Merge Sort Explained: How It Achieves O(n log n)-AZ]]></title>
            <link>https://medium.com/@fidanalizada95/merge-sort-explained-how-it-achieves-o-n-log-n-15781b10a194?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/15781b10a194</guid>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Fri, 05 Jun 2026 08:32:20 GMT</pubDate>
            <atom:updated>2026-06-05T08:34:33.866Z</atom:updated>
            <content:encoded><![CDATA[<p>Ən effektiv sort alqoritmlərindən biri də Merge Sort alqoritmidir. Alqoritmin ümumi işləmə prinsipi parçala və hökm et ( divide and conquer) və rekursiya prinsipinə əsaslanır.Bu alqoritmin əsası 1945-ci ildə Con F. Neyman tərəfindən qoyulmuşdur ə bu gün də kompüter elminin ən mühüm sıralama alqoritmlərindən biri hesab olunur.Merge Sort alqoritmi iki əsas mərhələdən ibarətdir:</p><ol><li>Divide (Parçalama): Siyahı hər hissədə yalnız bir element qalana qədər rekursiv olaraq iki hissəyə bölünür.</li><li>Merge (Birləşdirmə): Yaranmış alt siyahılar sıralanmış şəkildə birləşdirilərək yekun sıralanmış siyahı formalaşdırılır.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tkmIgWNuuxT7-jT7nfaLzw.png" /></figure><p>Alqoritmin Pythonda tətbiqinə baxaq.</p><pre>def merge_sort(nums):<br>    if len(nums) &lt;= 1:<br>        return nums<br><br>    mid = len(nums) // 2<br><br>    left = merge_sort(nums[:mid])<br>    right = merge_sort(nums[mid:])<br><br>    return merge(left, right)<br>    <br>def merge(left, right):<br>    result = []<br>    i = j = 0<br><br>    while i &lt; len(left) and j &lt; len(right):<br>        if left[i] &lt; right[j]:<br>            result.append(left[i])<br>            i += 1<br>        else:<br>            result.append(right[j])<br>            j += 1<br><br>    result.extend(left[i:])<br>    result.extend(right[j:])<br><br>    return result<br></pre><p>Quick sort alqoritmindən fərqli olaraq, Merge Sort alqoritminin ən böyük üstünlüklərindən biri onun performansının giriş verilənlərinin vəziyyətindən asılı olmamasıdır. Verilənlər artıq sıralanmış, qarışıq və ya tam tərs düzülmüş olsa belə, alqoritm hər zaman eyni sayda bölmə və birləşdirmə əməliyyatı yerinə yetirir.Ən yaxşı, orta və ən pis halda alqoritmin zaman mürəkkəbliyi O(nlogn)-dir.</p><p>Tutaq ki, sıralamaq istədiyimiz siyahı aşağıdakı kimidir:</p><p>[38, 27, 43, 3, 9, 82, 10, 1]/</p><h4>Səviyyə 0</h4><p>8 element:</p><pre>[38, 27, 43, 3, 9, 82, 10, 1]</pre><h4>Səviyyə 1</h4><p>8 element 2 hissəyə bölünür:</p><pre>[38, 27, 43, 3]      [9, 82, 10, 1]</pre><h4>Səviyyə 2</h4><p>4 element yenidən 2 hissəyə bölünür:</p><pre>[38, 27] [43, 3]      [9, 82] [10, 1]</pre><h4>Səviyyə 3</h4><p>2 element yenidən 1 elementli hissələrə bölünür:</p><pre>[38] [27] [43] [3] [9] [82] [10] [1]</pre><p>Artıq bölünmə dayanır və alırıq ki, log_2(8) = 3.Parçala mərhələsi bitdi.Bundan sonra birləşdirmə mərhələsini analiz edirik.</p><p>Səviyyə 3-ü birləşdirsək:</p><pre>[38] + [27] =[27,38]<br><br>[43] + [3] =[3,43]<br><br>[9] + [82] =[9,82]<br><br>[10] + [1] =[1,10]</pre><p>Səviyyə 2-ni birləşdirsək:</p><pre>[27,38] =[3,43]<br><br>[3,27,38,43]<br><br>[9,82] + [1,10]<br><br>[1,9,10,82]</pre><p>Səviyyə 1-i birləşdirsək:</p><pre>[3,27,38,43]<br>+<br>[1,9,10,82]<br>=<br><br>[1,3,9,10,27,38,43,82]</pre><p>Hər səviyyədə bütün 8 element bir dəfə emal olunur.Yəni ümumi iş 8*3=24.</p><p>Ümumiləşdirsək n*log_2(n) və buna görə Merge sort-un zaman mürəkkəbliyi. O(nlog⁡n) olur.Merge Sort sıralanmış alt massivləri birləşdirmək üçün əlavə yaddaş sahəsi istifadə etdiyindən in-place alqoritm hesab edilmir. Məhz bu səbəbdən onun yaddaş mürəkkəbliyi O(n) təşkil edir.Əlavə yaddaş istifadəsinə baxmayaraq, böyük verilənlər dəstləri və performansın proqnozlaşdırıla bilməsinin vacib olduğu sistemlər üçün əla seçimdir.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15781b10a194" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Sort in Python — Best, Average, and Worst Case Analysis]]></title>
            <link>https://medium.com/@fidanalizada95/quick-sort-in-python-best-average-and-worst-case-analysis-5f6ebf30491e?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f6ebf30491e</guid>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Thu, 28 May 2026 20:59:09 GMT</pubDate>
            <atom:updated>2026-05-28T20:59:09.201Z</atom:updated>
            <content:encoded><![CDATA[<p>Quick Sort is a sorting algorithm based on the divide and conquer principle. During the execution of this algorithm, one element from the list is selected as the pivot element, and the list is divided into two parts: elements smaller than the pivot are placed on the left side, while elements greater than the pivot are placed on the right side. This process is called partitioning.</p><p>After that, the same operation is recursively repeated for both parts. Since the pivot is chosen randomly, the probability of unbalanced partitions decreases. As a result, the array is usually divided into nearly equal-sized parts, allowing the algorithm to work faster.</p><p>When a random pivot is used, the average time complexity of Quick Sort is O(nlog⁡n), but in the worst case, due to poor pivot selections, the time complexity becomes O(n²).</p><p>Let’s implement it in Python.</p><pre>def quick_sort(nums):<br>    if len(nums) &lt;= 1:<br>        return nums<br>    pivot = nums[len(nums) // 2]<br><br>    left = [i for i in nums if i &lt; pivot]<br>    middle = [i for i in nums if i == pivot]<br>    right = [i for i in nums if i &gt; pivot]<br><br>    return quick_sort(left) + middle + quick_sort(right)<br><br>numbers = [7, 1, 6, 8, 5]<br><br>sorted_numbers = quick_sort(numbers)<br><br>print(sorted_numbers)</pre><p>Here, the pivot element is chosen as 6. The partitioning operation is performed. Then, the elements smaller than 6 are placed on the left side</p><p>left=[1,5]</p><p>the elements greater than 6 are placed on the right side</p><p>right=[7,8]</p><p>the elements equal to 6 are grouped separately</p><p>middle=[6].</p><p>In the final stage, the algorithm recursively sorts the left and right parts and combines all parts together: [1, 5] + [6] + [7, 8].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQ1soTX1zPW8SVjSLtHiVw.png" /></figure><p>The time complexity of the Quick Sort algorithm depends on the selection of the pivot element. To better analyze its time complexity, let us separately examine the best case, average case, and worst case.</p><p>In the best case, the pivot divides the array into approximately equal parts. For example,nums=[1,2,3,4,5,6,7,8] ,pivot=4.After partitioning, we obtain left=[1,2,3], middle=[4] and right=[5,6,7,8].Then, each part is again divided into two smaller parts.</p><p>The recursion is formed as follows:</p><p>n <br>n/2 + n/2<br>n/4 + n/4 + n/4 + n/4<br>…</p><p>At each recursive call, the total work performed is O(n) , while the number of recursive levels is logn. Therefore, the overall time complexity becomes O(nlog⁡n).In the average case, the partitions are not perfectly equal but remain relatively balanced. For example,nums=[8, 3, 1, 7, 4, 9, 2, 6],pivot=4.After partitioning left = [3, 1, 2],middle = [4],right = [8, 7, 9, 6].Now, for the left part, suppose pivot=1,left = [],middle = [1],right = [3,2] then [3,2] is sorted recursively.For the right part, suppose pivot =9, left = [8,7,6] ,middle = [9],right = [].Thus, the number of recursive calls is approximately ogn, and each level requires O(n) work. Hence, the overall time complexity is again O(nlog⁡n).</p><p>The worst case occurs when the pivot is chosen as either the largest or the smallest element in the array. For example, nums=[1,2,3,4,5],pivot = 1.left = [],middle=[1],right = [2,3,4,5].</p><p>The recursion then becomes:</p><p>n<br>n-1<br>n-2<br>n-3<br>…</p><p>The total number of operations is n+(n−1)+(n−2)+…+1.The result of this sum is n*(n-1)/2.Therefore, the time complexity in the worst case is O(n²).</p><p>In the Quick Sort algorithm, the main extra memory usage comes from recursive function calls. In other words, the algorithm uses stack memory, which requires additional space. In the average case, the auxiliary space complexity is O(log⁡n), while in the worst case it becomes O(n).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f6ebf30491e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Sort in Python — Best, Average, and Worst Case Analysis -AZ]]></title>
            <link>https://medium.com/@fidanalizada95/quick-sort-in-python-best-average-and-worst-case-analysis-az-42b0ea08625a?source=rss-be5b67a192a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/42b0ea08625a</guid>
            <dc:creator><![CDATA[Fidan Alizada]]></dc:creator>
            <pubDate>Tue, 26 May 2026 11:04:23 GMT</pubDate>
            <atom:updated>2026-05-26T11:04:23.739Z</atom:updated>
            <content:encoded><![CDATA[<p>Quick sort alqoritmi parçala və hakim ol (divide and counquer) prinsipinə əsaslanan sort alqoritmidir. Bu alqoritmin icrası zamanı siyahıdan bir element pivot element olaraq seçilir və siyahı 2 hissəyə bölünür:pivotdan kiçik elementlər sola, pivotdan böyük elementlər sağa yığılır.Bu proses bölmə ( partitioning) adlanır. Daha sonra eyni əməliyyat hər iki hissə üçün rekursiv şəkildə təkrarlanır. Pivot təsadüfi seçildiyi üçün siyahının balanssız bölünmə ehtimalı azalır. Nəticədə massiv adətən bir-birinə yaxın ölçülü hissələrə bölünür və alqoritm daha sürətli işləyir.Təsadüfi pivot istifadə edildikdə Quick Sort-un orta zaman mürəkkəbliyi O(nlogn) olur,lakin uğursuz pivot seçimləri olduqda ən pis halda zaman mürəkkəbliyi O(n²) olur.</p><p>Pythonda tətbiq edək.</p><pre>def quick_sort(nums):<br>    if len(nums) &lt;= 1:<br>        return nums<br>    pivot = nums[len(nums) // 2]<br><br>    left = [i for i in nums if i &lt; pivot]<br>    middle = [i for i in nums if i == pivot]<br>    right = [i for i in nums if i &gt; pivot]<br><br>    return quick_sort(left) + middle + quick_sort(right)<br><br>numbers = [7, 1, 6, 8, 5]<br><br>sorted_numbers = quick_sort(numbers)<br><br>print(sorted_numbers)</pre><p>Burada pivot element 6 seçilir. Bölmə əməliyyatı yerinə yetirilir.Sonra 6-dan kiçik elementlər sola yığılır</p><p>left=[1,5]</p><p>6-dan böyük elementlər sağa yığılır.</p><p>right=[7,8]</p><p>6-ya bərabər olan elementlər isə ayrıca yığılır.</p><p>middle=[6]</p><p>Son mərhələdə alqoritm sol və sağ hissələri rekursiv şəkildə sıralayır və bütün hissələri birləşdirir:[1, 5] + [6] + [7, 8].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*1gZArN-ny_QPD9QGr3fhXA.png" /></figure><p>Quick sort alqoritminin zaman mürəkkəbliyi pivot elementin seçilməsindən asılıdır. Zaman mürəkkəbliyini daha yaxşı analiz etmək üçün ən yaxşı hal (best case), orta hal ( average case), ən pis halı ayrıca nəzərdən keçirək.Ən yaxşı halda pivot siyahını təxminən bərabər hissələrə bölür.Məsələn, nums=[1,2,3,4,5,6,7,8] ,pivot=4.Bölünmədən alırıq ki, left=[1,2,3], middle=[4] və right=[5,6,7,8].Sonra hər hissə yenidən iki hissəyə bölünür.</p><p>Rekursiya belə formalaşır:</p><p>n<br>n/2 + n/2<br>n/4 + n/4 + n/4 + n/4<br>…</p><p>Hər çağırıçda ümumi sərf O(n) , rekursiv çağırışların sayı isə logn və beləliklə ümumi mürəkkəblik O(nlogn) olur.Average case-də partition-lar tam bərabər olmasa da balanslı olur.Məsələn, nums=[8, 3, 1, 7, 4, 9, 2, 6],pivot=4.Bölmə əməliyyatından sonra left = [3, 1, 2],middle = [4],right = [8, 7, 9, 6].İndi left hissəsi üçün pivot=1,left = [],middle = [1],right = [3,2] bundan sonra , [3,2] yenidən sort olunur.Right hissəsi üçün pivot =9, left = [8,7,6] ,middle = [9],right = [].Beləliklə, rekursiv çağırışların sayı logn olur və hər çağırışda ümumi sərf O(n), ümumi zaman mürəkkəbliyi O(nlogn) olur.Ən pis hal isə pivot siyahıdakı ya ən böyük ya da ən kiçik element seçildikdə baş verir.Məsələn, nums=[1,2,3,4,5],pivot = 1.left = [],middle=[1],right = [2,3,4,5].</p><p>Rekursiya belə formalaşır:</p><p>n<br>n-1<br>n-2<br>n-3<br>…</p><p>Toplam əməliyyat sayı n+(n−1)+(n−2)+…+1 olur.Bu cəmin nəticəsi isə</p><p>n*(n-1)/2. Beləliklə, zaman mürəkkəbliyi O(n²) olur.</p><p>Quick Sort alqoritmində əsas əlavə yaddaş recursive function çağırışlarından yaranır. Yəni alqoritm stack memory istifadə edir.Onun üçün də əlavə yaddaş tələb olunur.Average case-də əlavə yaddaş mürəkkəbliyi O(logn), ən pis halda isə O(n) olur.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42b0ea08625a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>