<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Babloo Kumar</title>
    <description>The latest articles on DEV Community by Babloo Kumar (@bks1242).</description>
    <link>https://dev.to/bks1242</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F394670%2F836511f2-3735-4fbb-a725-cf16df37f73c.jpeg</url>
      <title>DEV Community: Babloo Kumar</title>
      <link>https://dev.to/bks1242</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bks1242"/>
    <language>en</language>
    <item>
      <title>Retrieval - Augmented Generation (RAG)</title>
      <dc:creator>Babloo Kumar</dc:creator>
      <pubDate>Mon, 15 Jul 2024 19:06:50 +0000</pubDate>
      <link>https://dev.to/bks1242/retrieval-augmented-generation-rag-3856</link>
      <guid>https://dev.to/bks1242/retrieval-augmented-generation-rag-3856</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Retrieval-Augmented Generation&lt;/em&gt;&lt;/strong&gt; (RAG) systems are a class of models that combine elements of both retrieval and generation in natural language processing (NLP). These systems integrate retrieval-based methods with traditional generation-based models like GPT (Generative Pre-trained Transformer).&lt;/p&gt;

&lt;p&gt;It represents a significant advancement in NLP by bridging the gap between retrieval-based approaches (focused on factual accuracy and relevance) and generation-based models (focused on language fluency and coherence). They are increasingly used in various applications, including dialogue systems, question answering, and content generation tasks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F54tn4gplpv51stfmnk6n.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F54tn4gplpv51stfmnk6n.jpeg" alt="End to End RAG System " width="800" height="785"&gt;&lt;/a&gt;&lt;br&gt;
[&lt;em&gt;Fig1. Diagram of the RAG System (Reference image is taken from the internet)&lt;/em&gt;]&lt;/p&gt;

&lt;p&gt;Here’s a breakdown of how RAG systems typically work (taking a simple example of chatbot querying the private knowledge base or collection of documents which could be in different formats):&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For code simplicity and learning purpose, I will be using langchain (Orchestrator)- very minimal , AzureOpenAI (for embedding &amp;amp; gpt-4 models) and FAISS (local vector DB)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;First step _  is store the documents into the vector db using embedding model, popularly known as _Ingestion&lt;/em&gt;. To do below steps has to be followed:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;# load the document --&amp;gt; split the document into chunks --&amp;gt; create embeddings --&amp;gt; store in vector database&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1 - Split the entire knowledge base or collection of documents in chunks, chunks basically represents the single piece of context to be queried.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    pdf_path = "Vectors-in-memory/2210.03629v3.pdf"
    loader = PyPDFLoader(file_path=pdf_path)
    documents = loader.load()
    text_splitter = CharacterTextSplitter(
        chunk_size=1000, chunk_overlap=30, separator="\n"
    )
    docs = text_splitter.split_documents(documents=documents)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2 - Use embedding model to transform each chunks into vector embeddings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  embeddings = AzureOpenAIEmbeddings(
    azure_deployment=os.environ["AZURE_EMBEDDING_OPENAI_DEPLOYMENT"],
    openai_api_key=os.environ["AZURE_EMBEDDING_OPENAI_KEY"],
    azure_endpoint=os.environ["AZURE_EMBEDDING_OPENAI_API_BASE"],
    openai_api_type=os.environ["AZURE_EMBEDDING_OPENAI_API_TYPE"],
    openai_api_version=os.environ["AZURE_EMBEDDING_OPENAI_API_VERSION"],
 )

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3 - Store all the vector embeddings into the vector database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    vectorstore = FAISS.from_documents(docs, embeddings)
    vectorstore.save_local("faiss_index_react")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Next&lt;/strong&gt; work on the query( or chatbot question part), which is popularly known as &lt;strong&gt;&lt;em&gt;Retrieving&lt;/em&gt;&lt;/strong&gt;. The retrieval aspect involves retrieving relevant information or contexts from a large corpus of text based on a given query or input. This retrieval is typically performed using information retrieval techniques, where documents or passages most relevant to the input are selected.&lt;/p&gt;

&lt;p&gt;4 - Embed the query(which is asked from the chatbot) using the same embedding model. See the below code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    chat = AzureChatOpenAI(
        openai_api_key="xxxxxxd8a815xxxxxxxxxxxxx",
        azure_endpoint="https://testmodel.openai.azure.com/",
        openai_api_type="azure",
        azure_deployment="GPT4",
        openai_api_version="2024-05-01-preview",
        temperature=0,
        max_tokens=None,
        timeout=None,
        max_retries=2,
    )
   #Let below be the query from the chatbot
   query = "What is machine learning?"

   new_vectorstore = FAISS.load_local(
      "faiss_index_react",embeddings,allow_dangerous_deserialization=True
   )

   template = """Use the following pieces of context to answer the question at the end.
    If you don't know the answer, just say that you don't know, don't try to make up the answer.
    Use three sentences maximum and keep the answer as concise as possible.
    Always say "Thank you for Asking!!!" at the end of the answer.

    {context}

    Question: {question}

    Helpful Answer:"""

  custom_rag_prompt = PromptTemplate.from_template(template)

  rag_chain = (
      {"context": new_vectorstore .as_retriever(), "question": RunnablePassthrough() }
      | custom_rag_prompt
      | chat
    )

    res = rag_chain.invoke(query)
    print(res)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5 - Use the resulting vector to run the query against the index in the vector DB.&lt;br&gt;
Vector DB performs Approximate Nearest Neighbor for the query embedding and it returns the context, the procedure returns the vectors which are similar in a given latent space.&lt;/p&gt;

&lt;p&gt;6 - Now map the results into the prompt and pass it to the LLM(in this case AzureChatOpenAI, which has Gpt-4 model deployed). Once the relevant information is retrieved, it is combined with the input query or prompt to generate a coherent and contextually relevant response. This generation process often involves models like GPT (or its variants), which are capable of generating fluent and contextually appropriate text.&lt;/p&gt;

&lt;p&gt;The key innovation of RAG systems lies in the effective integration of these two components—retrieval and generation. By leveraging retrieval to provide contextually rich inputs to the generation model, RAG systems aim to produce responses that are not only fluent but also more grounded in relevant knowledge or information from the retrieval process.&lt;/p&gt;

</description>
      <category>rag</category>
      <category>azureopenai</category>
      <category>langchain</category>
    </item>
    <item>
      <title>How Modern Browsers Work?</title>
      <dc:creator>Babloo Kumar</dc:creator>
      <pubDate>Mon, 03 Apr 2023 04:58:49 +0000</pubDate>
      <link>https://dev.to/bks1242/how-modern-browsers-work-4h5o</link>
      <guid>https://dev.to/bks1242/how-modern-browsers-work-4h5o</guid>
      <description>&lt;p&gt;Google published a series of articles some years ago about &lt;strong&gt;&lt;em&gt;"Inside look at modern web browser"&lt;/em&gt;&lt;/strong&gt;. It's a great read.&lt;br&gt;
You guys might have already read but worth refreshing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.chrome.com/blog/inside-browser-part1/" rel="noopener noreferrer"&gt;Part - 1 CPU, GPU, Memory, and multi-process architecture&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.chrome.com/blog/inside-browser-part2/" rel="noopener noreferrer"&gt;Part - 2 What happens in navigation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.chrome.com/blog/inside-browser-part3/" rel="noopener noreferrer"&gt;Part - 3 Inner workings of a Renderer Process&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.chrome.com/blog/inside-browser-part4/" rel="noopener noreferrer"&gt;Part - 4 Input events from the browser's point of view&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>modernorwsers</category>
      <category>chrome</category>
    </item>
    <item>
      <title>Best Practices for Performant Angular Applications - #Part 1</title>
      <dc:creator>Babloo Kumar</dc:creator>
      <pubDate>Sat, 30 Jan 2021 07:47:09 +0000</pubDate>
      <link>https://dev.to/bks1242/best-practices-for-performant-angular-applications-part-1-2f7f</link>
      <guid>https://dev.to/bks1242/best-practices-for-performant-angular-applications-part-1-2f7f</guid>
      <description>&lt;p&gt;This article outlines the practices we should generally use in angular applications to have highly performant and cleaner code base.&lt;br&gt;
In this series of articles I'll be posting one practice at time.&lt;br&gt;
Scope of this series article will be limited to Angular, Typescript, RxJs and @ngrx/store.&lt;/p&gt;

&lt;p&gt;Today lets talk about observables, From coding aspect, it's very important to understand observables and how do we use it. If we use it correctly we can probably reduce the damage we do to the overall performance of the app and save lot of memory and CPU usage at run time.&lt;br&gt;
Some of the best practices are mentioned below, and trust me these are not complicated at all, it's like developing good habit or bad habit and it will automatically be reflected in your day to day activities.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. &lt;em&gt;Subscribe in template&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Avoid subscribing to observables from components and instead subscribe to the observables from the template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it's important ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;async&lt;/strong&gt; pipes unsubscribe themselves automatically and it makes the code simpler by eliminating the need to manually manage subscriptions. It also reduces the risk of accidentally forgetting to unsubscribe a subscription in the component, which would cause a memory leak. This risk can also be mitigated by using a lint rule to detect unsubscribed observables.&lt;br&gt;
This also stops components from being stateful and introducing bugs where the data gets mutated outside of the subscription.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// template
&amp;lt;p&amp;gt;{{ textToDisplay }}&amp;lt;/p&amp;gt;
// component
meTheObservable
    .pipe(
       map(value =&amp;gt; value.item),
       takeUntil(this._destroyed$)
     )
    .subscribe(item =&amp;gt; this.textToDisplay = item);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// template
&amp;lt;p&amp;gt;{{ textToDisplay$ | async }}&amp;lt;/p&amp;gt;
// component
this.textToDisplay$ = meTheObservable
    .pipe(
       map(value =&amp;gt; value.item)
     );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. &lt;em&gt;Clean up subscriptions&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;When subscribing to observables, always make sure you unsubscribe from them appropriately by using operators like &lt;strong&gt;take&lt;/strong&gt;, &lt;strong&gt;takeUntil&lt;/strong&gt;, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it's important ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Failing to unsubscribe from observables will lead to unwanted memory leaks as the observable stream is left open, potentially even after a component has been destroyed / the user has navigated to another page.&lt;br&gt;
Even better, make a lint rule for detecting observables that are not unsubscribed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;meTheObservable
    .pipe(
       map(value =&amp;gt; value.item)     
     )
    .subscribe(item =&amp;gt; this.textToDisplay = item);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;takeUntil&lt;/strong&gt; when you want to listen to the changes until another observable emits a value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private _destroyed$ = new Subject();
public ngOnInit (): void {
    meTheObservable
    .pipe(
       map(value =&amp;gt; value.item)
      // We want to listen to meTheObservable until the component is destroyed,

       takeUntil(this._destroyed$)
     )
    .subscribe(item =&amp;gt; this.textToDisplay = item);
}
public ngOnDestroy (): void {
    this._destroyed$.next();
    this._destroyed$.complete();
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using a private subject like this is a pattern to manage unsubscribing many observables in the component.&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;take&lt;/strong&gt; when you want only the first value emitted by the observable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;meTheObservable
    .pipe(
       map(value =&amp;gt; value.item),
       take(1),
       takeUntil(this._destroyed$)
    )
    .subscribe(item =&amp;gt; this.textToDisplay = item);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;br&gt;
The usage of &lt;strong&gt;takeUntil&lt;/strong&gt; with &lt;strong&gt;take&lt;/strong&gt; here. This is to avoid memory leaks caused when the subscription hasn’t received a value before the component got destroyed. Without &lt;strong&gt;takeUntil&lt;/strong&gt; here, the subscription would still hang around until it gets the first value, but since the component has already gotten destroyed, it will never get a value — leading to a memory leak.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. &lt;em&gt;Avoid having subscriptions inside subscriptions&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Sometimes you may want values from more than one observable to perform an action. In this case, avoid subscribing to one observable in the subscribe block of another observable. Instead, use appropriate chaining operators. Chaining operators run on observables from the operator before them. Some chaining operators are: &lt;strong&gt;withLatestFrom&lt;/strong&gt;, &lt;strong&gt;combineLatest&lt;/strong&gt;, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firstObservable$.pipe(
   take(1)
)
.subscribe(firstValue =&amp;gt; {
    secondObservable$.pipe(
        take(1)
    )
    .subscribe(secondValue =&amp;gt; {
        console.log(`Combined values are: ${firstValue} &amp;amp; ${secondValue}`);
    });
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firstObservable$.pipe(
    withLatestFrom(secondObservable$),
    first()
)
.subscribe(([firstValue, secondValue]) =&amp;gt; {
    console.log(`Combined values are: ${firstValue} &amp;amp; ${secondValue}`);
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why it's important ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code feel/readability/complexity&lt;/strong&gt; : Not using RxJs to its full extent, suggests developer is not familiar with the RxJs API surface area.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: If the observables are cold, it will subscribe to &lt;em&gt;firstObservable&lt;/em&gt;, wait for it to complete, THEN start the second observable’s work. If these were network requests it would show as synchronous.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Developing applications is a journey on &lt;em&gt;the road not taken&lt;/em&gt; and there's always room to learn and improve the things. The optimizations techniques mentioned above are good place to start and applying these patters consistently will make you and your users happy with less buggy and performant application. &lt;br&gt;
In the next part I would take another topic and discuss on it.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Angular 10 Deep Dive</title>
      <dc:creator>Babloo Kumar</dc:creator>
      <pubDate>Sat, 25 Jul 2020 18:58:01 +0000</pubDate>
      <link>https://dev.to/bks1242/angular-10-deep-dive-2g7a</link>
      <guid>https://dev.to/bks1242/angular-10-deep-dive-2g7a</guid>
      <description>&lt;p&gt;Angular 10, the latest major version of angular has just been released. It's time to discover what's new available for us to explore and enhance the experience.&lt;/p&gt;

&lt;h1&gt;
  
  
  What’s in this release?
&lt;/h1&gt;

&lt;p&gt;In this article, I'll touch up almost everything noteworthy in this new release. I'll also go through what's changed around the angular as a platform, including Framework, Angular Material and the CLI.&lt;br&gt;
I'll try here to dig deeper into the release notes for Angular 10.0. &lt;/p&gt;

&lt;p&gt;Angular 10 is already here, just four months after version 9. Of course during this short time period, there’s not that much that has changed. Still, there are quite a few noteworthy features, in addition to the large number of bug fixes brought by this release.As a reminder, the Angular team tries to release two major versions per year, so &lt;b&gt; Angular 11 &lt;/b&gt; should arrive this fall.&lt;/p&gt;

&lt;h2&gt;
  
  
  Support for TypeScript 3.9.x
&lt;/h2&gt;

&lt;p&gt;Keeping upto date with the JavaScript Ecosystem we have made a few updates to the dependencies of Angular to stay synchronized with the JavaScript ecosystem.&lt;br&gt;
So the very first thing that makes me happy about this release of Angular is the fact that it supports &lt;b&gt; TypeScript 3.9. &lt;/b&gt;&lt;br&gt;
Angular 10 has dropped support for TS 3.6, 3.7 and 3.8! I hope this should not be the major hold back for you.&lt;/p&gt;

&lt;p&gt;Thanks to its support for TS 3.9.x and other improvements in the compiler CLI, type-checking is faster than ever in Angular 10, which should be positive for most projects out there; especially larger ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  TSLib 2.0
&lt;/h2&gt;

&lt;p&gt;Additionally, Angular 10 also upgraded to TSLib 2.0. For those who don’t know, TSLib is an official library providing TypeScript helper functions that can be used at runtime. TSLib works in combination with the importHelpers flag of “tsconfig.json”; when enabled, it allows the compiler to generate more condensed/readable code. Anyways, nothing to worry about; TSLib hasn’t changed much.&lt;br&gt;
Starting with version 10 you will see a new tsconfig.base.json. This additional tsconfig.json file better supports the way that IDEs and build tooling resolve type and package configurations.&lt;/p&gt;

&lt;h2&gt;
  
  
  TSLint v6
&lt;/h2&gt;

&lt;p&gt;TSLint has been updated to v6.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stricter settings [optional]
&lt;/h2&gt;

&lt;p&gt;Angular 10 brings the possibility to create stricter projects right at creation time, which is great and should certainly be used for all new projects. To create a project with stricter defaults, use:&lt;br&gt;
ng new --strict&lt;br&gt;
This will allow you to detect issues much sooner at the build time itself, lot of time &amp;amp; effort can be saved.&lt;br&gt;
This new option enables TypeScript strict mode (which you should all enable on your projects!).&lt;br&gt;
Next to that, it also enables strict Angular template type checking.&lt;br&gt;
It also lowers the budgets in “angular.json” quite drastically:&lt;br&gt;
See the pic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvxq5xfk3cdd7isv4ru2t.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvxq5xfk3cdd7isv4ru2t.PNG" alt="Alt Text" width="644" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is good as it will encourage new users to pay attention to the bundle size of their applications. Default bundle budgets have been reduced by ~75%.&lt;/p&gt;

&lt;p&gt;It Configures your app as side-effect free to enable more advanced tree-shaking.&lt;/p&gt;

&lt;p&gt;It also enforces a stricter TSLint configuration which bans “any” (“no-any” is set to true), and also enables quite a few interesting rules provided by codelyzer. Note that even though strict, you can still go much further with TSLint. For instance, here’s the config of one of my &lt;a href="https://github.com/bks1242/Angular-10-Start-Up/blob/master/tslint.json" rel="noopener noreferrer"&gt;projects&lt;/a&gt;, which you can use as starting point.&lt;/p&gt;

&lt;p&gt;I feel that this new "strict" option is amazing, but sadly its an optional flag. For making it optional i imagine that the rationale is that by being more lenient by default, Angular feels less scary at first?&lt;/p&gt;

&lt;p&gt;Anyways, if you do create a new project, please enable this and go even further; you’ll thank me later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuration Layout
&lt;/h2&gt;

&lt;p&gt;This is new TypeScript configuration layout. With this new release, the TypeScript configuration provided by default in new projects has changed. There’s now a “tsconfig.base.json” file in addition to “tsconfig.json”, “tsconfig.app.json” and “tsconfig.spec.json”.&lt;br&gt;
We have included all these configuration files to better support the way IDEs and build tools look up the types and compiler configuration. If you would have worked on Visual Studio Professional for developing any tool/app you can understand easily.&lt;br&gt;
With the new setup, “tsconfig.json” simply contains TypeScript project references based on the so-called “solution style” brought by TypeScript 3.9, which is great to improve compilation times and enforce a stricter separation between parts of the project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh9qo5kg51hdwoihvhiz5.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh9qo5kg51hdwoihvhiz5.PNG" alt="Alt Text" width="681" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, the separation is there to have clean isolation of application code (taken care of by “tsconfig.app.json”) from tests (handled by “tsconfig.spec.json”).&lt;/p&gt;

&lt;p&gt;If you look at the “tsconfig.base.json” file, then you’ll find the bulk of the TypeScript configuration:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4ecy6e66vqdtjufz3dib.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4ecy6e66vqdtjufz3dib.PNG" alt="Alt Text" width="768" height="617"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that this one was generated using the strict option discussed in the previous section.&lt;br&gt;
As you can see above, this file only configures TypeScript compiler and Angular compiler options; it doesn’t list/include/exclude files to compile.&lt;/p&gt;

&lt;p&gt;The answer is indeed in the “tsconfig.app.json” file, which lists the “main.ts” and “polyfills.ts”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9mc0137adjk67wmy3nyw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9mc0137adjk67wmy3nyw.PNG" alt="Alt Text" width="660" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have an existing project without this layout, then you should probably review your TypeScript configuration in order to stay aligned and benefit.&lt;/p&gt;

&lt;p&gt;Now Let's move to new item for discussion.&lt;/p&gt;

&lt;h2&gt;
  
  
  NGCC
&lt;/h2&gt;

&lt;p&gt;In case you haven’t done this yet (this was already true with NG9), make sure that you have a postinstall script in your “package.json” file to execute NGCC right after an installation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffatvt32x8qo30t1g918y.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffatvt32x8qo30t1g918y.PNG" alt="Alt Text" width="419" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that in this release, NGCC is more resilient. Previously, it couldn’t always recover when one of its worker processes crashed. So if you sometimes saw issues with NGCC hanging, this should now be fixed.&lt;br&gt;
There were also quite a lot of improvements made to NGCC, including performance-related ones, which is clearly every ones biggest pain point around NGCC.&lt;/p&gt;

&lt;h2&gt;
  
  
  New Default Browser Configuration
&lt;/h2&gt;

&lt;p&gt;The browser configuration for new projects to exclude older and less used browsers.&lt;/p&gt;

&lt;p&gt;Web browsers move faster than ever. Angular follows course and now uses an updated browserslist file (.browserslistrc).&lt;br&gt;
As explained in the official blog post, the side effect of the new configuration is that ES5 builds are disabled by default for new projects.&lt;br&gt;
Of course, at this point it doesn’t make much sense anymore to generate ES5 code. Modern Web browsers support at the very least ES2015. If you still use Internet Explorer or UC Browser, then it’s clearly time to let go of the past!&lt;br&gt;
To get the exact list of supported Web browsers, just execute the following command in your project:&lt;/p&gt;

&lt;p&gt;&lt;b&gt; npx browserslist &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The output is generated based on the contents of the “.browserslistrc” file at the root; by default it now looks as follows (V10 Defaults):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F18arpkl23ah836cwvd2k.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F18arpkl23ah836cwvd2k.PNG" alt="Alt Text" width="800" height="526"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bazel
&lt;/h2&gt;

&lt;p&gt;Angular Bazel has left Angular Labs now. Support for Bazel is not part of the Angular project anymore. Bazel will never be the default build tool in Angular CLI after all.&lt;/p&gt;

&lt;h2&gt;
  
  
  @angular-devkit/build-angular 0.1000.0)
&lt;/h2&gt;

&lt;p&gt;The name and version nomenclature hides important piece of information around it (the way Angular Apps are built).&lt;br&gt;
The new version has bought lot of good features, all are covered below -&lt;/p&gt;

&lt;p&gt;The coolest one (if you’re using SASS that is) is the fact that build-angular will now rebase relative paths to assets.&lt;/p&gt;

&lt;p&gt;As stated in the commit, previously, paths like url(./foo.png) referenced in stylesheets and imported in other stylesheets would retain the exact URL. This was problematic since it broke as soon as the importing stylesheet was not in the same folder. Now, all resources using relative paths will be found.&lt;/p&gt;

&lt;p&gt;Another hidden gem in that release is the fact that build-angular now dedupes duplicate modules that Webpack can’t handle. This is done through a custom Webpack resolve plugin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Few more are listed below
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Incremental template type checking
&lt;/h3&gt;

&lt;p&gt;In this release, the compiler CLI is now able to perform template type checking incrementally. Hopefully this will save quite a few trees.&lt;/p&gt;

&lt;h3&gt;
  
  
  CanLoad
&lt;/h3&gt;

&lt;p&gt;Previously, CanLoad guards could only return booleans. Now, it’s possible to return a UrlTree. This matches the behavior of CanActivate guards.&lt;br&gt;
Note that this doesn’t affect preloading.&lt;/p&gt;

&lt;h3&gt;
  
  
  Service Workers
&lt;/h3&gt;

&lt;p&gt;The default SwRegistrationStrategy has been improved. Previously, there were cases where the Service Worker never registered (e.g., when there were long-running tasks like intervals and recurring timeouts).&lt;/p&gt;

&lt;h3&gt;
  
  
  Internalization &amp;amp; Localization (I18N/L10N)
&lt;/h3&gt;

&lt;p&gt;Previously, only one translation file was supported per locale. Now, it is possible to specify multiple files for each locale. All of those then get merged by message id. If you are using you would have got my point.&lt;/p&gt;

&lt;h3&gt;
  
  
  Angular Material
&lt;/h3&gt;

&lt;p&gt;Lot of important fixes has been done for the Angular material. For the detailed list please see the &lt;a href="https://github.com/angular/components/releases" rel="noopener noreferrer"&gt;release notes&lt;/a&gt;&lt;br&gt;
Some of the new stuffs included - &lt;br&gt;
Angular Material now includes a new date range picker. To use the new date range picker, you can use the mat-date-range-input and mat-date-range-picker components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Angular Team Fixit (Bug fixes galore)
&lt;/h2&gt;

&lt;p&gt;As mentioned a few weeks back, the Angular team has invested a lot of time and effort in bug fixing and backlog grooming. They’ve decreased their issue count by &amp;gt; 700 issues inlcuding framework, tooling &amp;amp; components, which is quite impressive.&lt;br&gt;
One of fact that enabling strict template type checking caused issues with routerLinks because their underlying type didn’t include null/undefined. Another one that was fixed is the KeyValuePipe, which didn’t play along well with the async pipe.&lt;/p&gt;

&lt;p&gt;While we’re on templates, note that the language service of Angular now supports more array-like objects such as ReadonlyArray and readonly property arrays for *ngFor loops.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deprecations and removals
&lt;/h2&gt;

&lt;p&gt;The Angular Package Format no longer includes ESM5 or FESM5 bundles, saving you 119MB of download and install time when running yarn or npm install for Angular packages and libraries. These formats are no longer needed as any down leveling to support ES5 is done at the end of the build process.&lt;br&gt;
Based on feedback from the community, we have deprecating support for older browsers including IE 9, 10, and Internet Explorer Mobile.&lt;/p&gt;

&lt;p&gt;There are quite a few deprecated elements such as ReflectiveInjector, CollectionChangeRecord, DefaultIterableDiffer, ReflectiveKey, RenderComponentType, ViewEncapsulation.Native, ngModelwith Reactive Forms, preserveQueryParams, @angular/upgrade, defineInjectable, entryComponents, TestBed.get, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Classes using Angular features without an Angular decorator are not supported anymore
&lt;/h2&gt;

&lt;p&gt;Up to version 9, it was okay to have a class using Angular features without specifying one of the decorators (@Component, @Directive, etc).&lt;/p&gt;

&lt;p&gt;With Angular 10, it is now mandatory to add an Angular decorator if a class uses Angular features. This change impacts all cases where you have components extending from a base class and one of the two (i.e., parent or child) is missing an Angular decorator.&lt;br&gt;
Why is this change mandatory? Simply put, because Ivy needs it!&lt;br&gt;
When there’s no Angular decorator on a class, the Angular compiler doesn’t add extra code for dependency injection.&lt;br&gt;
As stated in the official doc, when the decorator is missing from the parent class, the subclass will inherit a constructor from a class for which the compiler did not generate special constructor info (because it was not decorated as a directive). When Angular then tries to create the subclass, it doesn’t have the correct info to create it.&lt;/p&gt;

&lt;p&gt;In View Engine, the compiler has global knowledge, so it can look up the missing data. However, the Ivy compiler only processes each directive in isolation. This means that compilation can be faster, but the compiler can’t automatically infer the same information as before. Adding the @Directive() explicitly provides this information.&lt;/p&gt;

&lt;p&gt;When the child class is missing the decorator, the child class inherits from the parent class yet has no decorators of its own. Without a decorator, the compiler has no way of knowing that the class is a @Directive or @Component, so it doesn't generate the proper instructions for the directive.&lt;br&gt;
The nice thing about this change is that it brings more consistency into the Angular world (and consistency is good :p). Now things are simple: if you use Angular features, then you must add a decorator.&lt;/p&gt;

&lt;p&gt;To give you an example, the following code won’t compile with Ivy:&lt;/p&gt;

&lt;h4&gt;
  
  
  Before:
&lt;/h4&gt;

&lt;p&gt;@Component({&lt;br&gt;
  selector: 'base-menu',&lt;br&gt;
  template: '&lt;/p&gt;'&lt;br&gt;
})&lt;br&gt;
class BaseMenu {}

&lt;p&gt;export class SettingsMenu extends BaseMenu {}&lt;/p&gt;

&lt;h4&gt;
  
  
  After: (this will be valid code for compilation)
&lt;/h4&gt;

&lt;p&gt;@Component({&lt;br&gt;
  selector: 'base-menu',&lt;br&gt;
  template: '&lt;/p&gt;'&lt;br&gt;
})&lt;br&gt;
class BaseMenu {}

&lt;p&gt;@Component({&lt;br&gt;
  selector: 'base-menu',&lt;br&gt;
  template: '&lt;/p&gt;'&lt;br&gt;
})&lt;br&gt;
export class SettingsMenu extends BaseMenu {}

&lt;p&gt;To fix the issue, you need to add a decorator to the SettingsMenu class.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;This schematic also decorates classes that use Angular field decorators, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;@Input()&lt;/li&gt;
&lt;li&gt;@Output()&lt;/li&gt;
&lt;li&gt;@HostBinding()&lt;/li&gt;
&lt;li&gt;@HostListener()&lt;/li&gt;
&lt;li&gt;@ViewChild() / @ViewChildren()&lt;/li&gt;
&lt;li&gt;@ContentChild() / @ContentChildren()&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  Before:
&lt;/h4&gt;

&lt;p&gt;class Base {&lt;br&gt;
  @Output()&lt;br&gt;
  countChanged = new EventEmitter();&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;@Directive({&lt;br&gt;
  selector: '[myDir]'&lt;br&gt;
})&lt;br&gt;
class Dir extends Base {&lt;br&gt;
}&lt;/p&gt;

&lt;h4&gt;
  
  
  After:
&lt;/h4&gt;

&lt;p&gt;@Directive() // schematic adds @Directive()&lt;br&gt;
class Base {&lt;br&gt;
  @Output()&lt;br&gt;
  countChanged = new EventEmitter();&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;@Directive({&lt;br&gt;
  selector: '[myDir]'&lt;br&gt;
})&lt;br&gt;
class Dir extends Base {&lt;br&gt;
}&lt;/p&gt;

&lt;h2&gt;
  
  
  Mandatory generic type for ModuleWithProviders
&lt;/h2&gt;

&lt;p&gt;In previous releases, ModuleWithProviders already accepted a generic type, but it was not mandatory. With NG 10, the generic argument is required.&lt;/p&gt;

&lt;p&gt;It’s a good thing for type safety anyways, so hopefully you already had the parameter defined:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm6vv9jiym85vwvxd5ivh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm6vv9jiym85vwvxd5ivh.PNG" alt="Alt Text" width="786" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you stumble upon the following error because of a library that you’re using:&lt;/p&gt;

&lt;p&gt;&lt;b&gt; "error TS2314: Generic type 'ModuleWithProviders' requires 1 type argument(s)." &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Then you should contact the library author to get it fixed as ngcc can’t help there. A workaround there is to set skipLibChecks to false.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other breaking changes
&lt;/h2&gt;

&lt;p&gt;Here are notable breaking changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Resolvers behave differently; those that return EMPTY will now cancel navigation. If you want to allow navigation to continue, then you need to make sure that your resolvers emit a value; for instance using defaultIfEmpty(...), of(...) and the like.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Service worker implementations that rely on resources with Vary headers will not work like they did previously. Vary headers will be ignored. The proposed “solution” is to avoid caching such resources as they tend to cause unpredictable behavior depending on the user agents. Because of this, resources may be retrieved even when their headers are different. Note that cache match options may now be configured in NGSW’s config file. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Property bindings such as [foo]=(bar$ | async).fubar will not trigger change detection if the fubar value is the same as the previous one. The workaround if you rely on the previous behavior is to manually subscribe / force change detection or adapt the binding in order to make sure that the reference does change.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The following format codes of formatDate() and DatePipe have changed; apparently the previous behavior was incorrect for day periods that crossed midnight.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The function that stands behind the UrlMatcher utility type (function alias) now correctly states that its return type may be null. If you have a custom Router or Recognizer class, then you need to adapt those.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Additional occurrences of ExpressionChangedAfterItHasBeenChecked can now be raised by Angular for errors that it didn’t detect before.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Angular now logs at error level when it notices unknown elements / property bindings in your templates. These were previously warnings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reactive forms’s valueChangeshad a bug with FormControls that were bound to inputs of type number (they fired twice since 2016! A first time after typing in the input field and a second time when the input field lost focus). Now, number inputs don’t listen to the change event anymore, but to the input event. Don’t forget to adapt your tests accordingly. Note that this breaks IE9 compatibility, but that’s not a problem for anyone.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The minLength and maxLength validators now make sure that the associated form controls values have a numeric length property. If that’s not the case, then these won’t be validated. Previously, falsy values without a length property (e.g., false or 0) were triggering validation errors. If you rely on that behavior, then you should add other validators like min or requiredTrue.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Upgrading
&lt;/h2&gt;

&lt;p&gt;As usual, there’s a complete upgrade guide available and ng update will help you out: &lt;a href="https://update.angular.io/#9.0:10.0l3" rel="noopener noreferrer"&gt;https://update.angular.io/#9.0:10.0l3&lt;/a&gt;&lt;br&gt;
If you do the upgrade manually and still use Protractor (just in case), then don’t forget to update protractor to 7.0.0+ as previous versions had a vulnerability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, I’ve tried to explore the new features of Angular 10, as well as the deprecations, removals and breaking changes.&lt;/p&gt;

&lt;p&gt;All in all, it’s clearly a rock solid one with tons of bug fixes and a few gems.&lt;/p&gt;

&lt;p&gt;As usual, we can only be thankful for all the efforts made by the Angular team and the community that surrounds it!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://in.linkedin.com/in/babloo-kumar-a9269995?trk=profile-badge" rel="noopener noreferrer"&gt;Babloo Kumar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>angular10</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>apps</category>
    </item>
    <item>
      <title>A Complete Guide for Flex</title>
      <dc:creator>Babloo Kumar</dc:creator>
      <pubDate>Sun, 21 Jun 2020 12:30:12 +0000</pubDate>
      <link>https://dev.to/bks1242/a-complete-guide-for-flex-3imd</link>
      <guid>https://dev.to/bks1242/a-complete-guide-for-flex-3imd</guid>
      <description>&lt;p&gt;The "Flexible Box" or "Flexbox" or "Flex" Layout, makes it easier to design flexible responsive layout structure without using float or positioning. It offers alternative to Floats for overall appearance of web page. Flex gives us the complete control over the alignment, direction, order and size of our boxes. Flex is divided into two parts i.e. flex containers (responsible for styling of full box i.e. Parent Element) and flex items (responsible for individual item in a box i.e. Child elements).&lt;br&gt;
Below image shows the parent container(flex containers) and child items(flex items). The blue box is container which hold the child items(in orange colors).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdht0v79z5z9pl8cqyydv.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdht0v79z5z9pl8cqyydv.PNG" alt="Alt Text" width="573" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5t1rsau91u509jmrgfcw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5t1rsau91u509jmrgfcw.PNG" alt="Alt Text" width="632" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below image displays the properties for the parent containers and child items.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq31z28g3gn1hfg4u9u4k.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq31z28g3gn1hfg4u9u4k.PNG" alt="Alt Text" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Section 1:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Below are the properties of the Parent flex Container:&lt;br&gt;
Flex-direction, Justify-Content, Align-Items, Flex-Wrap, Align-Content.&lt;br&gt;
Each property is explained in detailed in below read.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;display&lt;/strong&gt; - It defines a flex container; It can have block or inline depending on the value provided. It enables a flex context for all its direct children.&lt;br&gt;
Sample e.g.&lt;/p&gt;

&lt;p&gt;display: flex  (this is for block)&lt;br&gt;
display: inline-flex (this is for inline)&lt;/p&gt;

&lt;p&gt;Container can be styled as below for the flex.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcmm6v0xw8our5zml6e2g.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcmm6v0xw8our5zml6e2g.PNG" alt="Alt Text" width="738" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;flex-direction&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Flexbox is mainly single-direction layout concept. Flex can put it's child items either in horizontal rows or vertical columns.&lt;/p&gt;

&lt;p&gt;flex-direction can have below values:&lt;/p&gt;

&lt;p&gt;(i) &lt;em&gt;flex-direction: row&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It's the default value and it displays child items from left to right in ltr and Right to Left in rtl.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuc3bxwr5tr3f6l3ar370.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuc3bxwr5tr3f6l3ar370.PNG" alt="Alt Text" width="471" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(ii) &lt;em&gt;flex-direction: row-reverse&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;it displays the child items from right to left in ltr; left to right in rtl&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwvgdxpuevltu5a5dx9de.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwvgdxpuevltu5a5dx9de.PNG" alt="Alt Text" width="800" height="146"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iii) &lt;em&gt;flex-direction: column&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It displays the child items from top to bottom.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frtfq2ah8tbbztlgprx4h.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frtfq2ah8tbbztlgprx4h.PNG" alt="Alt Text" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iv) &lt;em&gt;flex-direction: column-reverse&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It displays the child items from bottom to top.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F71e9o3is9inu508huybv.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F71e9o3is9inu508huybv.PNG" alt="Alt Text" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;flex-direction can be used as below (sample code):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;row&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;reverse&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;column&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;column&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;justify-content&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;This defines the alignment along the main axis. It helps distribute extra free space leftover when either all the flex items on a line are inflexible, or are flexible but have reached their maximum size. It also exerts some control over the alignment of items when they overflow the line.&lt;/p&gt;

&lt;p&gt;Justify content can have below values, see the below diagrams to have better understanding how items will be placed:&lt;/p&gt;

&lt;p&gt;(i) &lt;em&gt;justify-content: flex-start&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The flex-start value aligns the flex items at the beginning of the container (this is default).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcsc19aascn10ufta0zik.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcsc19aascn10ufta0zik.PNG" alt="Alt Text" width="800" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(ii) &lt;em&gt;justify-content: flex-end&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The flex-end value aligns the flex items at the end of the container:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Feg9kc6fh3a8b71gofvwv.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Feg9kc6fh3a8b71gofvwv.PNG" alt="Alt Text" width="800" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iii) &lt;em&gt;justify-content: center&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The center value aligns the flex items at the center of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpuecsxw1mzvt5ta1a0n5.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpuecsxw1mzvt5ta1a0n5.PNG" alt="Alt Text" width="800" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iv) &lt;em&gt;justify-content: space-around&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The space-around value displays the flex items with space before, between, and after the lines. If we say is short equal space will be between an element and after the element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff42mouq5r988bnsmzzs7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff42mouq5r988bnsmzzs7.PNG" alt="Alt Text" width="800" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(v) &lt;em&gt;justify-content: space-between&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The space-between value displays the flex items with space between the lines. In short space will be only between two items. &lt;br&gt;
See first element and last element, it will help in differentiating between "space-around" &amp;amp; "space-between".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7pvkz99vhvskoubt5wgn.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7pvkz99vhvskoubt5wgn.PNG" alt="Alt Text" width="800" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;justify-content can be used as below (sample code):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;justify&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;space&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;around&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;space&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;align-items&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The align-items property is used to align the flex items.&lt;br&gt;
This defines the default behavior for how flex items are laid out along the cross axis(perpendicular axis) on the current line.&lt;/p&gt;

&lt;p&gt;Align items can have below values, see the diagrams underneath to have better understanding:&lt;/p&gt;

&lt;p&gt;(i) &lt;em&gt;align-items: flex-start&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The flex-start value aligns the flex items at the top of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdmjd15pjvo1jxibgoa25.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdmjd15pjvo1jxibgoa25.PNG" alt="Alt Text" width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(ii) &lt;em&gt;align-items: flex-end&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The flex-end value aligns the flex items at the bottom of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flj78zcifjsyujk4nxa44.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flj78zcifjsyujk4nxa44.PNG" alt="Alt Text" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iii) &lt;em&gt;align-items: center&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The center value aligns the flex items in the middle of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fa7xd7uvs84crozx0vb8t.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fa7xd7uvs84crozx0vb8t.PNG" alt="Alt Text" width="800" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iv) &lt;em&gt;align-items: stretch&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The stretch value stretches the flex items to fill the container (this is default).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5p0lx2uypt12mflrt2zm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5p0lx2uypt12mflrt2zm.PNG" alt="Alt Text" width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(v) &lt;em&gt;align-items: baseline&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The baseline value aligns the flex items such as their baselines aligns.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs6fx8en5hk9me0cic0a0.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs6fx8en5hk9me0cic0a0.PNG" alt="Alt Text" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F44l1wei3zs7nkwnii71f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F44l1wei3zs7nkwnii71f.png" alt="Alt Text" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the sample code through which align-items can be applied.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;align&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;stretch&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;baseline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;flex-wrap&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The flex-wrap property specifies whether the flex items should wrap or not.By default, flex items will all try to fit onto one line. You can change that and allow the items to wrap as needed with this property. &lt;/p&gt;

&lt;p&gt;Flex-wrap can have below values, please see the diagrams underneath to have better depth understanding.&lt;/p&gt;

&lt;p&gt;(i) &lt;em&gt;flex-wrap: nowrap&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The nowrap value specifies that the flex items will not wrap (this is default).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyb8wfcqn87ujvira6jek.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyb8wfcqn87ujvira6jek.PNG" alt="Alt Text" width="800" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(ii) &lt;em&gt;flex-wrap: wrap&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The wrap value specifies that the flex items will wrap if necessary.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flmbluxg46xgh93pkxq8n.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flmbluxg46xgh93pkxq8n.PNG" alt="Alt Text" width="800" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iii) &lt;em&gt;flex-wrap: wrap-reverse&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The wrap-reverse value specifies that the flexible items will wrap if necessary, in reverse order.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5vp23xlq20gwdoy0hyns.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5vp23xlq20gwdoy0hyns.PNG" alt="Alt Text" width="800" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the sample code for flex-wrap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;nowrap&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;wrap&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;wrap&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;align-content&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The align-content property is used to align the flex lines.This aligns a flex container’s lines within when there is extra space in the cross-axis, similar to how justify-content aligns individual items within the main-axis.&lt;/p&gt;

&lt;p&gt;Note: this property has no effect when there is only one line of flex items.&lt;/p&gt;

&lt;p&gt;align-content can have below values, please see the underneath diagrams to have better understanding.&lt;/p&gt;

&lt;p&gt;(i) &lt;em&gt;align-content: flex-start&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The flex-start value displays the flex lines at the start of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5qu0vw38b1v0jovroypt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5qu0vw38b1v0jovroypt.PNG" alt="Alt Text" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(ii) &lt;em&gt;align-content: flex-end&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The flex-end value displays the flex lines at the end of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9yh8ccy6u7rrs09z7ny7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9yh8ccy6u7rrs09z7ny7.PNG" alt="Alt Text" width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iii) &lt;em&gt;align-content: center&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The center value displays display the flex lines in the middle of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fym0pg38fcqqy00ytd1fx.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fym0pg38fcqqy00ytd1fx.PNG" alt="Alt Text" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iv) &lt;em&gt;align-content: space-around&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The space-around value displays the flex lines with space before, between, and after them&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzuobtijw4ctmpk1lx9zg.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzuobtijw4ctmpk1lx9zg.PNG" alt="Alt Text" width="800" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(v) &lt;em&gt;align-content: space-between&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The space-between value displays the flex lines with equal space between them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3cciy8kaj9h4tzauri0m.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3cciy8kaj9h4tzauri0m.PNG" alt="Alt Text" width="800" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(v) &lt;em&gt;align-content: stretch&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The stretch value stretches the flex lines to take up the remaining space (this is default).&lt;/p&gt;

&lt;p&gt;Below is the sample code to use align-items:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;align&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;space&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;around&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;space&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;between&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;stretch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Section 2:&lt;/strong&gt; ...
&lt;/h2&gt;

&lt;p&gt;Now let's see the properties which are applicable for the flex items (children of the flex container).&lt;br&gt;
flex-items can have below properties to style themselves individually. &lt;br&gt;
"order, Align Self, Flex Grow, Flex Shrink, Flex Basis, Flex( shorthand for flex grow, flex shrink &amp;amp; flex basis)".&lt;br&gt;
Each property is defined in brief in the below read.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;order&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;By default, flex items are basically laid in the order in which they are defined in the markup.&lt;br&gt;
Order property determines the order in which they appear in the flex container, so without changing the html markup we can re arrange (re-order) in the flex container.&lt;/p&gt;

&lt;p&gt;Default value of order is 0. See below example, Suppose we have 4 boxes, by default value of order will be 0 for all.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxlb0yb19cofzw7d4526x.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxlb0yb19cofzw7d4526x.PNG" alt="Alt Text" width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we want to rearrange the boxes, for example(See below figure) if we want to place 2nd box at the first place and 3rd box at the end. First Lets see how to put 2nd box at the first place. If we give the value of order less than 0 i.e. -1 or -2, -3 ..., it will be come at the first place. Similarly when we have to put the 3rd box at last place , we have to give the value of "order" more than 0 i.e. 1 or 2 , or 3, .... basically based on the integer value (ascending) the boxes get sorted in horizontal direction(flex-direction: row) or vertical direction(flex-direction: column).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fctfew6ju5oznk1b77nz8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fctfew6ju5oznk1b77nz8.PNG" alt="Alt Text" width="800" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets take an example where i want to put all the boxes in random fashion. How do we do it? Answer is simple, assign the value of "order" for each block in the ascending order. Box with lowest value of order will be in the left most and box with highest value of order will be in the right most. See below example for reference.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Feyvrewvlqfgj8s94znom.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Feyvrewvlqfgj8s94znom.PNG" alt="Alt Text" width="800" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;align-self&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is used to style individual child item in the flex container. Styling is done basically with respect to cross axis here. Suppose flex-direction is row for the container , so all child items are places horizontally like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftqax1ufa42h58ylz8v9p.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftqax1ufa42h58ylz8v9p.PNG" alt="Alt Text" width="471" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;now each child item can be styled in vertical direction(cross axis) using "align-self" property moved up, down, center etc.&lt;/p&gt;

&lt;p&gt;Please see below possible values for align-self, and diagram underneath to have better understanding:&lt;/p&gt;

&lt;p&gt;(i) &lt;em&gt;align-self: flex-start&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The flex-start value displays the individual item at the start of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5jj9ofz1q7y3o0rbgm00.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5jj9ofz1q7y3o0rbgm00.PNG" alt="Alt Text" width="800" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(ii) &lt;em&gt;align-self: flex-end&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The flex-end value displays the individual item at the end of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp66nzjt7py1db1750mk3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp66nzjt7py1db1750mk3.PNG" alt="Alt Text" width="800" height="185"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iii) &lt;em&gt;align-self: stretch&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The stretch value stretches the individual item to take up the remaining space.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffmart53mssd8l7s8f7gx.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffmart53mssd8l7s8f7gx.PNG" alt="Alt Text" width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(iv) &lt;em&gt;align-self: baseline&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The baseline value aligns the individual items such as their baselines aligns.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftrmeptafyus4aiizjmtt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftrmeptafyus4aiizjmtt.PNG" alt="Alt Text" width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the sample code to use align-self:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;align&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;auto&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;baseline&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;stretch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;flex-grow&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This give ability for the individual child item to grow proportionally.It dictates what amount of the available space inside the flex container the item should take up. Default value of flex-grow is 0(zero). In this it takes width based on the individual content width and extra space remains empty.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F56t6cjjrcwxgvuuq8uo5.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F56t6cjjrcwxgvuuq8uo5.PNG" alt="Alt Text" width="800" height="110"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If all child items have flex-grow set to 1, the remaining space in the container will be distributed equally to all children.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fouo6iwuva05kdnltm7h8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fouo6iwuva05kdnltm7h8.PNG" alt="Alt Text" width="800" height="113"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets see some examples to have better understanding:&lt;/p&gt;

&lt;p&gt;(a) Among 4 available boxes with flex-grow value (0) , all will be displayed based on the content width. Now suppose 3rd box(3rd child item) has flex-grow property 1 (one) and other boxes(child items i.e. 1, 2, 4) have flex-grow property 0, then all the child items with flex-grow value 0 will take space based on content width and the remaining available space is occupied by the 3rd box (child item). &lt;br&gt;
Please see below figure for better understanding.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkatd6583cy89q6gsk63a.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkatd6583cy89q6gsk63a.PNG" alt="Alt Text" width="800" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(b) Now lets take another example, where child items (1,2,4) have flex-grow property value 1 each and child item 3 has flex-grow property value 2. So remaining space of flex-container is divided into 5 equal parts. Now based on the flex-grow value equivalent proportion of width will be allocated. Item 3 gets 2/5 (40%) of remaining space. &lt;br&gt;
Please see below diagram for better understanding.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1r0bzg5pv01dp184zvk7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1r0bzg5pv01dp184zvk7.PNG" alt="Alt Text" width="800" height="113"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly suppose child items(1, 3) has flex-grow value 3 and child items(2, 4) has flex-grow value 2. Now the remaining space of flex container will be divided into 10 equal parts (3 + 3 + 2 + 2). And share of child item 1 &amp;amp; 3 would be 3/10 each of remaining space and share of child items 2 &amp;amp; 4 would be 2/10 each of remaining space.&lt;/p&gt;

&lt;p&gt;(c) Lets take one more example to have better understanding. Suppose flex-grow value for child-item 1, 2, 4 is 1 each and for child item-3 is 4. Now the remaining space of flex container will be divided equally in 7 parts. And share of child item 3 would be 4/7 remaining space. &lt;br&gt;
Please see below diagram for better illustration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fosown0f1k8q16q1jqk34.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fosown0f1k8q16q1jqk34.PNG" alt="Alt Text" width="800" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;flex-shrink&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This property gives flexibility to allow child flex-items to shrink by some degree. Here negative values are not allowed. The shrinking happens with respect to the other items available in the flex-container. Like shrinking 2nd child item by 3 times w.r.t to other child items. It's always relative to other items in the container.&lt;br&gt;
Now lets see some example to understand more in depth.&lt;/p&gt;

&lt;p&gt;(a) &lt;em&gt;flex-shrink : 1&lt;/em&gt; &lt;br&gt;
(this is the default value and it allows all the child items to shrink by some degree, depends on the browsers implementation). See the below diagram for better illustration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqeu0z4uzm7umhozg3ts2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqeu0z4uzm7umhozg3ts2.PNG" alt="Alt Text" width="800" height="106"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here all the child items have flex-shrink value 1 , so all will shrink with some degree.&lt;/p&gt;

&lt;p&gt;(b) Lets see the below diagram&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe026yafhq2tvxpfpwzwv.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe026yafhq2tvxpfpwzwv.PNG" alt="Alt Text" width="800" height="110"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here child items 1, 2, 6 have shrink value 1. And child items 3, 4, 5 have shrink value 0. Now items 3, 4, 5 are not allowed to shrink , however 1, 2, 6 will shrink with same degree.&lt;br&gt;
Here also if shrink value is custom like child items with shrink property value 2, 3 ,4 ...and so on then shrinking will happen proportionally with each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;flex-basis&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It provides the initial length of the child items.It defines the default size of the child item without the remaining space around it is distributed. It can be defined in percentage or some magic number or it can be auto. If set to 0, the extra space around child item isn’t factored in. If set to auto, the extra space is distributed based on its flex-grow value.&lt;/p&gt;

&lt;p&gt;See the below example illustration to understand in depth and visualize different possibilities.&lt;/p&gt;

&lt;p&gt;(a)&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe026yafhq2tvxpfpwzwv.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe026yafhq2tvxpfpwzwv.PNG" alt="Alt Text" width="800" height="110"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(b)&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6o4phjaaz22qcqbf1fuf.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6o4phjaaz22qcqbf1fuf.PNG" alt="Alt Text" width="800" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(c)&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6o4phjaaz22qcqbf1fuf.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6o4phjaaz22qcqbf1fuf.PNG" alt="Alt Text" width="800" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Property:&lt;/strong&gt; &lt;em&gt;flex&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is shorthand for flex-grow, flex-shrink and flex-basis combined. The flex property sets the flexible length on flexible items.&lt;br&gt;
lets see some examples to understand in depth and visualize different possibilities.&lt;/p&gt;

&lt;p&gt;(a)&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwe15s89n12wvef29g6wh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwe15s89n12wvef29g6wh.PNG" alt="Alt Text" width="800" height="228"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(b)&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyrajyqyi55ovy2mh7thn.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyrajyqyi55ovy2mh7thn.PNG" alt="Alt Text" width="800" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(c)&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyrajyqyi55ovy2mh7thn.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyrajyqyi55ovy2mh7thn.PNG" alt="Alt Text" width="800" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(d)&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fehp5wgk0fyygy03h8j04.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fehp5wgk0fyygy03h8j04.PNG" alt="Alt Text" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To Conclude, i would say flex is good option (not only option)to position our elements. I hope you had good learning time. Now it's time to utilize the learned skills to try some hands on. To take flex to next level try making Holy Grail layout, or Hexagon layout, or Flexbox grids and comment how did you achieve. If you have some other layout which you feel we can achieve through flex, comment and do let me know.&lt;/p&gt;

</description>
      <category>css</category>
      <category>flex</category>
      <category>ux</category>
      <category>stylenewbie</category>
    </item>
    <item>
      <title>Space Complexity</title>
      <dc:creator>Babloo Kumar</dc:creator>
      <pubDate>Wed, 27 May 2020 14:38:21 +0000</pubDate>
      <link>https://dev.to/bks1242/space-complexity-529b</link>
      <guid>https://dev.to/bks1242/space-complexity-529b</guid>
      <description>&lt;p&gt;Whenever we write an algorithm or we want to perform analysis of an algorithm, we need to calculate the complexity of that algorithm. But when we calculate complexity of any algorithm, it does not give us the exact amount of resources required to accomplish it. So instead of taking the exact amount of resource, we represent that complexity in a general form (Asymptotic Notation) which produces the basic nature of that algorithm. We use that general form (Asymptotic Notation) for analysis process. &lt;br&gt;
Asymptotic notation of an algorithm is a mathematical representation of it's complexity. In asymptotic notation, when we want to represent the complexity of an algorithm, we use only the most significant terms in the complexity of that algorithm and ignore least significant terms in the complexity of that algorithm (Here complexity can be Space Complexity or Time Complexity).&lt;/p&gt;

&lt;p&gt;For example- Consider the following time complexities of two algorithms.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Algorithm 1 : 4n^2 + 4n + 1&lt;/li&gt;
&lt;li&gt;Algorithm 2 : 10n^2 + 8n + 3&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Generally, when we analyze an algorithm, we consider the time or space complexity for larger values of input data (i.e. 'n' value). In above two complexities(time &amp;amp; space), for larger value of 'n' the term '4n + 1' in algorithm 1 has least significance than the term '4n^2', and the term '8n + 3' in algorithm 2 has least significance than the term '10n^2'.&lt;br&gt;
Here, for larger value of 'n' the value of most significant terms ( 4n^2 and 10n^2 ) is very larger than the value of least significant terms ( 4n + 1 and 8n + 3 ). So for larger value of 'n' we ignore the least significant terms to represent overall time or space required by an algorithm. In asymptotic notation, we use only the most significant terms to represent the time/space complexity of an algorithm.&lt;/p&gt;

&lt;p&gt;Today we will be discussing more about Space Complexity. Space complexity is amount of memory of a system required to execute a program to produce some legitimate output. Similar to &lt;a href="https://dev.to/bks1242/time-complexity-5c3"&gt;Time Complexity&lt;/a&gt;, Space Complexity is often expressed asymptotically in Big O Notation such as O(1), O(log n), O(n), O(n log n), O(n^2), O(n^3), O(n^y), O(2^n), O(n!) where n is a characteristic of the input influencing space complexity and O is the worst case scenario growth rate function.&lt;/p&gt;

&lt;p&gt;Why it's important to know the space complexity? Answer to this is, the computational device has limited memory and our overall cost increases with the increase in storage. So it's very important to know beforehand the amount of space required for the size of input data set.&lt;br&gt;
For any algorithm, memory is used for the following purpose:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To store Variables (constant values, temporary values).&lt;/li&gt;
&lt;li&gt;To store program instructions(or steps).&lt;/li&gt;
&lt;li&gt;For the program Execution.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mathematically if we put in equation, space complexity can be defined as,&lt;/p&gt;
&lt;h5&gt;
  
  
  Space Complexity = Auxiliary Space + Input space
&lt;/h5&gt;

&lt;p&gt;Most of the times, Auxiliary Space is confused with Space Complexity. However, Auxiliary Space is the extra space or the temporary space used by the algorithm during it's execution.&lt;/p&gt;

&lt;p&gt;When a program is under execution, it uses computational device memory for three main reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Instruction Space: When the code is compiled we need to keep in the memory somewhere, so that it can be executed afterwards. Instruction Space is the place where it is stored.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Environmental Stack: It is used to store the addresses of the partially called functions. It means, Sometimes an algorithm(function) may be called inside another algorithm(function). In such a situation, the current variables are pushed onto the system stack, where they wait for further execution and then the call to the inside algorithm(function) is made.&lt;br&gt;
For example, If a function A() calls function B() inside it, then all the variables of the function A() will get stored on the system stack temporarily, while the function B() is called and executed inside the function A().&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data Space: It is the place where data, variables, and constants are stored by the program and it is updated during execution.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When we want to perform analysis of an algorithm based on its Space complexity, we usually consider only Data Space and ignore Instruction Space as well as Environmental Stack.That means we calculate only the memory required to store Variables, Constants, Structures, etc.&lt;/p&gt;

&lt;p&gt;Cheat sheet, to keep it handy.&lt;br&gt;
Below is the list of some common Space Complexity terms, which we knowingly or unknowingly use in our day to day coding. It is arranged in order of there execution time when their input size increases.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;S.NO&lt;/th&gt;
&lt;th&gt;Big O Notation&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1.&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Constant Space Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.&lt;/td&gt;
&lt;td&gt;O(log n)&lt;/td&gt;
&lt;td&gt;Logarithmic Space Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3.&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;td&gt;Linear Space complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4.&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;Linearithmic Space Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5.&lt;/td&gt;
&lt;td&gt;O(n^2)&lt;/td&gt;
&lt;td&gt;Quadratic Space Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6.&lt;/td&gt;
&lt;td&gt;O(n^3)&lt;/td&gt;
&lt;td&gt;Cubic Space Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7.&lt;/td&gt;
&lt;td&gt;O(n^y)&lt;/td&gt;
&lt;td&gt;Polynomial Space Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8.&lt;/td&gt;
&lt;td&gt;O(2^n)&lt;/td&gt;
&lt;td&gt;Exponential Space Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9.&lt;/td&gt;
&lt;td&gt;O(n!)&lt;/td&gt;
&lt;td&gt;Factorial Space Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For better understanding See the below graph, it's combination of all the graphs for different Space Complexities, You can clearly see with the increase in input data set how space complexity varies. Based on the amount of input data set choose your algorithm wisely.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---5IHdxoa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/Timecomplexity.PNG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---5IHdxoa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/Timecomplexity.PNG%3Fraw%3Dtrue" alt="Space Complexity" width="800" height="630"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now let's see the calculation part of the space complexity through some examples,&lt;br&gt;
For calculating the space complexity, we need to know the value of memory used by different types of datatype variables, which generally varies for different operating systems, but the method for calculating the space complexity remains the same. For example - Generally (not always) C Programming Language compiler requires the following:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;bool, char, unsigned char, signed char, __int8&lt;/td&gt;
&lt;td&gt;1 byte&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;__int16, short, unsigned short, wchar_t, __wchar_t&lt;/td&gt;
&lt;td&gt;2 bytes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;float, __int32, int, unsigned int, long, unsigned long&lt;/td&gt;
&lt;td&gt;4 bytes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;double, __int64, long double, long long&lt;/td&gt;
&lt;td&gt;8 bytes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;However you are always free to choose some sample unit (like T size) for same type of variables to calculate the size.&lt;br&gt;
Now lets take some example and decode how to calculate space time complexity:&lt;/p&gt;

&lt;p&gt;Example 1-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above expression, variables a, b, c and z are all integer types, hence they will take up 4 bytes each, so total memory requirement will be (4(4) + 4) = 20 bytes, this additional 4 bytes is for return value. And because this space requirement is fixed for the above example, hence it is called Constant Space Complexity.&lt;br&gt;
If any algorithm requires a fixed amount of space for all input values then that space complexity is said to be Constant Space Complexity or O(1) space complexity.&lt;/p&gt;

&lt;p&gt;Example 2- It's bit complex than first one,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="c1"&gt;// n is the length of array a[]&lt;/span&gt;
  &lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// 4 bytes for x&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// 4 bytes for i&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;   
        &lt;span class="nx"&gt;x&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;      
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the above code, 4*n bytes of space is required for the array a[] elements.&lt;/li&gt;
&lt;li&gt;4 bytes each for x, n, i and the return value.
Hence the total memory requirement will be (4n + 12), which is increasing linearly with the increase in the input value n, hence it is called as Linear Space Complexity or O(n) Space Complexity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example 3- When you implement binary search, You will find total memory requirement will be something similar in terms of log(n). Hence it is called as Logarithmic Space Complexity or O(log n) Space Complexity.&lt;br&gt;
In practical on day to day basis,&lt;br&gt;
LOGSPACE is the set of problems that can be solved by a deterministic Turing machine using only O(log n) memory space with regards to input size. Even a single counter that can index the entire n-bit input requires log n space, so LOGSPACE algorithms can maintain only a constant number of counters or other variables of similar bit complexity.&lt;/p&gt;

&lt;p&gt;Example 4- Let's take an example of merge sort&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;mergeSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

     &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here, the memory requirement will be some &lt;strong&gt;constant&lt;/strong&gt;  *( n * log (n)). Hence it is called Linearithmic Space complexity or O(n log n).&lt;/p&gt;

&lt;p&gt;Similarly, we can have quadratic and other complex space complexity as well, as the complexity of an algorithm increases.&lt;/p&gt;

&lt;p&gt;But we should always focus on writing algorithm code in such a way that we keep the space complexity minimum.&lt;/p&gt;

&lt;p&gt;To conclude, i would say, better the space complexity of an algorithm better will be performance of it. Before finalizing the algorithm for your programming code the worst case scenario should be considered. It would help in longer terms with respect to scalability and sustainability of the overall system and it will help in keeping the resources in healthy condition without burning out.&lt;/p&gt;

&lt;p&gt;If you have some algorithm and want to calculate the space complexity, put the code in the comment section and we can decode together.&lt;/p&gt;

</description>
      <category>datastructure</category>
      <category>spacecomplexity</category>
      <category>algorithms</category>
      <category>performance</category>
    </item>
    <item>
      <title>Time Complexity</title>
      <dc:creator>Babloo Kumar</dc:creator>
      <pubDate>Tue, 26 May 2020 14:14:19 +0000</pubDate>
      <link>https://dev.to/bks1242/time-complexity-5c3</link>
      <guid>https://dev.to/bks1242/time-complexity-5c3</guid>
      <description>&lt;p&gt;In the programming, when we have a problem there are many ways to solve it. But which is the best way and how do we decide to pick the right algorithm.&lt;br&gt;
Algorithms are set of instructions(or steps) which tells what to do and how to do it.&lt;br&gt;
Some algorithms finishes within a second, another takes minutes with even smaller data sets. How do we compare different performances and come to conclusion?&lt;br&gt;
Answer to this is to measure the time complexity of an algorithm. Time complexity represents number of times a statement is executed. The execution time of the code does not depend only upon the algorithm, it depends upon certain factors like programming language, operating software, processing power, etc etc. However, Keeping in mind the system configuration to be constant, time complexity is calculated on the execution of algorithm itself and its input.&lt;/p&gt;

&lt;p&gt;To express the time complexity "Big O Notation" terminology is used. It is a function of input size (n) of Big O Notation, where n is input and O is the worst case scenario growth rate function.&lt;/p&gt;

&lt;p&gt;Cheat sheet, to keep it handy.&lt;br&gt;
Below is the list of some common time complexities terms, which we knowingly or unknowingly use in our day to day coding. It is arranged in order of there execution time when their input size increases.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;S.NO&lt;/th&gt;
&lt;th&gt;Big O Notation&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1.&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Constant Time Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.&lt;/td&gt;
&lt;td&gt;O(log n)&lt;/td&gt;
&lt;td&gt;Logarithmic Time Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3.&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;td&gt;Linear Time complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4.&lt;/td&gt;
&lt;td&gt;O(n log n)&lt;/td&gt;
&lt;td&gt;Linearithmic Time Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5.&lt;/td&gt;
&lt;td&gt;O(n^2)&lt;/td&gt;
&lt;td&gt;Quadratic Time Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6.&lt;/td&gt;
&lt;td&gt;O(n^3)&lt;/td&gt;
&lt;td&gt;Cubic Time Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7.&lt;/td&gt;
&lt;td&gt;O(n^y)&lt;/td&gt;
&lt;td&gt;Polynomial Time Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8.&lt;/td&gt;
&lt;td&gt;O(2^n)&lt;/td&gt;
&lt;td&gt;Exponential Time Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9.&lt;/td&gt;
&lt;td&gt;O(n!)&lt;/td&gt;
&lt;td&gt;Factorial Time Complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;let's go one by one, decode &amp;amp; define them to have better understanding.&lt;/p&gt;

&lt;p&gt;(1) O(1): When our algorithm takes same time regardless of the input size we term it as O(1) Or constant time complexity. It means even though we increase the input , the time remains same.&lt;br&gt;
Example- add 2 numbers, find if a number is divisible by 2 or not.&lt;br&gt;
See the below graph to have more understanding.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PffXLuiO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/ConstantTc.PNG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PffXLuiO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/ConstantTc.PNG%3Fraw%3Dtrue" alt="Time Complexity" width="478" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(2) O(log n): When input grows time increases linearly up to certain point and then becomes almost constant w.r.t horizontal axis. It means even though input increases drastically after certain interval of time it will take constant time.&lt;br&gt;
Logarithmic time complexities usually apply to algorithms that divide problems in half every time. For instance, let’s say that we want to look for a "book" word in a dictionary. For that we need not to go through all the words before &amp;amp; after it. We just need to eliminate at every stage till we reach the word "book".&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the book in the middle and check the first word on it.&lt;/li&gt;
&lt;li&gt;If the word that you are looking for is alphabetically more significant, then look to the right. Otherwise, look in the left half.&lt;/li&gt;
&lt;li&gt;Divide the remainder in half again, and repeat step #2 until you find the word you are looking for.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example - Binary Search&lt;br&gt;
See the below example to have better understanding.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2o17rdPp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/LogarithmicTC.PNG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2o17rdPp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/LogarithmicTC.PNG%3Fraw%3Dtrue" alt="Time Complexity" width="506" height="510"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(3) O(n) : When input grows , the algorithm takes proportionally longer time to complete the operation. Linear time algorithms imply that the program visits every element from the input.&lt;br&gt;
Example - to find maximum in an array. When the size of the input grows, time also grows proportionally.&lt;/p&gt;

&lt;p&gt;This can be usually identified when the function has single for loop.&lt;br&gt;
See the below graph to have better understading.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GZOxGwKg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/Linear%2520TC.PNG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GZOxGwKg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/Linear%2520TC.PNG%3Fraw%3Dtrue" alt="Time Complexity" width="524" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(4) O(n log n): Linearithmic time complexity, it’s slightly slower than a linear algorithm. However, it’s still much better than a quadratic algorithm.&lt;br&gt;
Example, sorting algorithms like MergeSort, depicts this time complexity.&lt;/p&gt;

&lt;p&gt;See the below graph, it's combination of all the graphs for different time complexities, in practicality, algorithms with Linearithmic time complexity are one of the well appreciated algorithm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---5IHdxoa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/Timecomplexity.PNG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---5IHdxoa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/Timecomplexity.PNG%3Fraw%3Dtrue" alt="Time Complexity" width="800" height="630"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;(5) O(n^2): In this type of algorithms, the time it takes to run grows directly proportional to the square of the size of the input, means when 1 unit of input grows, it takes 2 unit of time, 2 unit of input takes 4 unit of time and so on.&lt;br&gt;
In most of the scenarios and particularly for large data sets, algorithms with quadratic time complexities take a lot of time to execute and should be avoided. &lt;br&gt;
This can be identified when the function has nested for loop or two inner for loops.&lt;br&gt;
Example - printing two dimensional arrays, or bubble sort.&lt;/p&gt;

&lt;p&gt;See the below graph to have better understanding.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nPYoFxzn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/QuadraticTC.PNG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nPYoFxzn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/QuadraticTC.PNG%3Fraw%3Dtrue" alt="Time Complexity" width="480" height="549"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;(6) O(n^y): Polynomial time complexity is represented as O(n^y), when y &amp;gt; 1. here n is input , y is exponential integer greater than 1. As you already saw, two inner loops almost translate to O(n^2) since it has to go through the array twice in most cases. Are three nested loops cubic? If each one visit all elements, then yes! And that terms out to be Cubic Time Complexity O(n^3).&lt;/p&gt;

&lt;p&gt;Usually, we want to stay away from polynomial running times (quadratic, cubic, n^y, etc.) since they take longer to compute as the input grows fast. However, they are not the worst :) .&lt;/p&gt;

&lt;p&gt;(7) O(2^n): In exponential time algorithms, the growth rate doubles with each addition to the input (n), often iterating through all subsets of the input elements. Any time an input unit increases by 1, it causes you to double the number of operations performed. Basically calculations performed by an algorithm double every time as the input grows.&lt;br&gt;
Example- Creating subset of string like 'abc' , 'abcd', 'abcd.....z'&lt;/p&gt;

&lt;p&gt;See the below graph to have better understanding.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ghgptM8C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/ExponentialTC.PNG%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ghgptM8C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bks1242/Time-Complexity/blob/master/ExponentialTC.PNG%3Fraw%3Dtrue" alt="Time Complexity" width="526" height="520"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;(8) O(n!): Factorial is the multiplication of all whole numbers from our chosen number down to 1.&lt;br&gt;
Example: 5! = 5 x 4 x 3 x 2 x 1 = 120&lt;br&gt;
it grows when input increases&lt;br&gt;
20! = 2,432,902,008,176,640,000&lt;br&gt;
With small increase in input data set there is huge increase in the execution time. We should stay away from such algorithms as much as possible.&lt;/p&gt;

&lt;p&gt;These were the basics Time Complexity terms you might come across daily while programming or writing algorithms.&lt;/p&gt;

&lt;p&gt;Next step would be to deep dive to decode the function and write down time complexity of each line and summation of it, will give the exact time complexity of the program code which you have written.&lt;/p&gt;

&lt;p&gt;To conclude, i would say, better the time complexity of an algorithm better will be performance of it. Before finalizing the algorithm for your programming code the worst case scenario should be considered. It would help in longer terms with respect to scalability and sustainability of the overall system. &lt;/p&gt;

</description>
      <category>datastructures</category>
      <category>timecomplexity</category>
      <category>algorithms</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
