Inorder, Postorder and Preorder traversal in BST

Traversal In Binary Tree :

Preorder traversal (NLR) :

  1. Visit the root(N)
  2. Traverse the left subtree of root in preorder(L)
  3. Traverse the right subtree of root in preorder(R)

Inorder Traversal (LNR) :

  1. Traverse the left subtree of root in inorder(L)
  2. Visit the root(N)
  3. Traverse the right subtree of root in inorder(R)

Postorder Traversal (LRN) :

  1. Traverse the left subtree of root in postorder(L)
  2. Traverse the right subtree of root in postorder(R)
  3. Visit the root(N)

Algorithm for preorder(*ptr):
STEP 1: START
STEP 2: IF(ptr == NULL ) then RETURN
STEP 3: Then PRINT("%d ",ptrinfo)
STEP 4: Then call preorder(ptrlchild)
STEP 5: Then call preorder(ptrrchild)
STEP 6: STOP.

Algorithm for inorder(*ptr):
STEP 1: START
STEP 2: IF(ptr = NULL ) then RETURN
STEP 3: Then call inorder(ptrlchild)
STEP 4: Then PRINT("%d ",ptrinfo)
STEP 5: Then call inorder(ptrrchild)
STEP 6: STOP.

Algorithm for postorder(*ptr):
STEP 1: START
STEP 2: IF(ptr = NULL ) then RETURN
STEP 3: Then call postorder(ptrlchild)
STEP 4: Then call postorder(ptrrchild) S
TEP 5: Then PRINT("%d ",ptrinfo)
STEP 6: STOP.

Code :

/*Operations in Binary Search Tree*/
#include<stdio.h>
#include<stdlib.h>
#define MAX 100

struct node
{
    struct node *lchild;
    int info;
    struct node *rchild;
};

struct node *insert(struct node *ptr, int ikey);
void preorder(struct node *ptr);
void inorder(struct node *ptr);
void postorder(struct node *ptr);

void main( )
{
    printf(". . . . . . . . BINARY SEARCH TREE . . . . . . . .");
    printf("\n");
    struct node *root=NULL,*ptr;
    int choice,k;
        root = insert(root, 50);
        root = insert(root, 10);
        root = insert(root, 60);
        root = insert(root, 40);
        root = insert(root, 30);
        root = insert(root, 5);
        printf("\nPreorder Traversal : \n");
            preorder(root); 
        printf("\nInorder Traversal : \n");
            inorder(root);
        printf("\nPostorder Traversal : \n");
            postorder(root); 
}/*End of main( )*/


struct node *insert(struct node *ptr, int ikey )
{
    if(ptr==NULL){
        ptr = (struct node *) malloc(sizeof(struct node));
        ptr->info = ikey;
        ptr->lchild = NULL;
        ptr->rchild = NULL;}
    else if(ikey < ptr->info)   /*Insertion in left subtree*/
        ptr->lchild = insert(ptr->lchild, ikey);
    else if(ikey > ptr->info)   /*Insertion in right subtree */
        ptr->rchild = insert(ptr->rchild, ikey);  
    else
        printf("Duplicate key.....\n");
    return ptr;
}/*End of insert( )*/

struct node *del(struct node *ptr, int dkey)
{
    struct node *tmp, *succ;
    if( ptr == NULL){
        printf("Key not found.....\n");
        return(ptr);}
    if( dkey < ptr->info )/*delete from left subtree*/
        ptr->lchild = del(ptr->lchild, dkey);
    else if( dkey > ptr->info )/*delete from right subtree*/
        ptr->rchild = del(ptr->rchild, dkey);
    else
    {
        /*key to be deleted is found*/
        if( ptr->lchild!=NULL  &&  ptr->rchild!=NULL )  /*2 children*/
        {
            succ=ptr->rchild;
            while(succ->lchild)
                succ=succ->lchild;
            ptr->info=succ->info;
            ptr->rchild = del(ptr->rchild, succ->info);
        }
        else    
        {
            tmp = ptr;
            if( ptr->lchild != NULL ) /*only left child*/
                ptr = ptr->lchild;
            else if( ptr->rchild != NULL) /*only right child*/
                ptr = ptr->rchild;
            else    /* no child */
                ptr = NULL;
            free(tmp);
        }
        printf("\nNode deleted...");                        
    }
    return ptr; 
}/*End of del( )*/
void preorder(struct node *ptr)
{
    if(ptr == NULL )    /*Base Case*/
        return;
    printf("%d  ",ptr->info);
    preorder(ptr->lchild);
    preorder(ptr->rchild);
}/*End of preorder( )*/

void inorder(struct node *ptr)
{
    if(ptr == NULL )/*Base Case*/
        return;
    inorder(ptr->lchild);
    printf("%d  ",ptr->info);
    inorder(ptr->rchild);
}/*End of inorder( )*/

void postorder(struct node *ptr)
{
    if(ptr == NULL )/*Base Case*/
        return;
    postorder(ptr->lchild);
    postorder(ptr->rchild);
    printf("%d  ",ptr->info);

}/*End of postorder( )*/

Output :

. . . . . . . . BINARY SEARCH TREE . . . . . . . .

Preorder Traversal : 
50  10  5  40  30  60  
Inorder Traversal : 
5  10  30  40  50  60  
Postorder Traversal : 
5  30  40  10  60  50

Quickstart to Using SingleStoreDB, MindsDB, and Deepnote for Data Science

Abstract

This article will show how to use SingleStoreDB with MindsDB using Deepnote. We'll create integrations within Deepnote, load the Iris flower data set into SingleStoreDB, and then use MindsDB to create a Machine Learning (ML) model from the Iris data stored in SingleStoreDB. We'll also make some example predictions using the ML model. Most of the code will be in SQL, enabling developers with solid SQL skills to hit the ground running and start working with ML immediately.

The notebook file used in this article is available on GitHub.

Build a Real-Time Chat App With Nestjs and PostgreSQL

The code for this tutorial is available on my GitHub repository. Feel free to clone it as you follow the steps. Let's begin!

What Is NestJS?

NestJS is a Node.js framework for creating fast, testable, scalable, loosely coupled server-side applications that use TypeScript. It takes advantage of powerful HTTP server frameworks such as Express or Fastify. Nest adds a layer of abstraction to Node.js frameworks and exposes their APIs to developers. It supports database management systems like PostgreSQL and MySQL. NestJS also offers dependency injections Websockets and APIGetaways.

I Need Help With A Simple Program

I need help with this problem!
I can't get all three to display.
Write a program that prompts a user to enter their hourly pay and rate. Understanding that "time and a half" applies to hours in excess of forty, calculate and print the user's regular pay, overtime pay, and total pay for the week.

Learn APIs With Coding Over Cocktails

One of the best ways to learn about anything and everything is through podcasts. Here at Coding Over Cocktails, we talk to the world’s leading experts on application architecture and development who share with us what they’ve learned through years and years of experience. 

Among the many topics we’ve discussed, one that has been extensively talked about is APIs. If you’re looking to learn more about APIs through the words of industry experts and leaders, we’ve compiled all our episodes on the subject to date in one list, so scroll through our API episodes below and feel free to hit play!

WordPress 6.1 to Focus On Refining Full-Site Editing, Next Phase Collaboration and Multilingual Features Anticipated in 2023-2025

Gutenberg lead architect Matías Ventura has identified refinements to experiences introduced in 5.9 and 6.0 as the main goal for the upcoming 6.1 release. He published the roadmap for 6.1 ahead of the closing session at WordCamp Europe in Porto, where he was scheduled to join Matt Mullenweg and Josepha Haden Chomphosy for a demo. Ventura wasn’t able to make it but he tweeted a thread with video demos of some exciting interface updates that Gutenberg contributors are working on.

One of the main thrusts is making site navigation a smoother experience through a new “browse mode” that will allow site editors to zoom in and out while working.

Patterns are another major focus that Ventura has identified as “a central piece of the creative experience.” Contributors are working on making it easier to build with patterns, with plans to improve the discovery and insertion process. WordPress 6.1 will bring better support for pattern usage in custom post types, block types, and a more intuitive experience locking patterns and managing saved patterns.

image credit: WordPress 6.1 Roadmap

Contributors are also exploring a new aerial view and other ideas for making it easier to interact with patterns as sections of a page, as Ventura demonstrated in his thread.

Ventura said another goal for WordPress 6.1 is to improve the global styles interface with better support for restrictions, privileges, and curated presets. Design tools will also be updated to support responsive typography and allow managing webfonts.

“The tune of the release will be to refine the experiences introduced in 5.9 and 6.0, weave the various flows into more coherent and fulfilling experiences for users, maintainers, and extenders, and close some gaps in functionality as we start to look towards Phase 3 of the Gutenberg roadmap,” Ventura said.

Beyond WordPress 6.1: Collaboration Phase 3 Will Precede Multilingual Phase 4 to Establish Core Architecture

Matt Mullenweg and Josepha Haden Chomphosy addressed several questions regarding WordPress’ long term roadmap during their Q&A session at WordCamp Europe. (The video from the livestream is embedded below.)

WordPress core contributors plan to close out the Customization phase before beginning on the Collaboration phase in 2023. During the Q&A session, one of the polyglot contributors asked why WordPress is waiting until Phase 4 to begin working on multilingual features in core.

“Part of the reason we don’t want to set data now and then work on the feature later is that we have learned every time that it’s hard to create the architecture for something without creating the user experience,” Mullwenweg said. “When we try to do one without the other, for example with the REST API we got into the REST API before we were fully using it ourselves. As we started to do first-party usage of the REST API with Gutenberg, we found a bunch of gaps. I would feel particularly bad if those gaps meant plugins had been building on the wrong architecture for a few years.”

Mullenweg also explained why he believes it’s important to prioritize Phase 3, which he referred to as “workflow,” before the multilingual features:

Phase 3 is Workflow. This is basically where we’re going to take real-time co-editing into WordPress, much like Google docs or something else. When you log in to edit a page or your sites or a template or something, if someone else is in there at the same time, you’ll be able to see them moving around. Of course, we want to make sure we have version control built in like we do for posts and pages, into as many parts of WP as possible, so if someone makes a mistake or an edit to the site, you will be able to roll it back easily, which I think is really key for giving people confidence.

He emphasized the importance of establishing the collaboration architecture before introducing multilingual support into core.

“I think that the workflows around multilingual are important,” Mullenweg said. “So where is the content being canonically created, how do changes flow from one language to another, maybe even bi-directionally, depending on the people editing the site, and how that affects the rest of the templates – things that are outside the post and page content.”

He also noted the many third-party multilingual solutions that already exist will have a transition period as core integrates these features.

“I expect that much like has happened with page builders, once there’s something in core, they will either have a data migration path or integrate with whatever foundation we put into core,” Mullenweg said. “But I would like to set expectations that it’s probably more of a 2024 or 2025 initiative for WordPress. And we want to get these other phases done really well first. Why do we have to go in order? We can only do so much at once.”

When the person who had asked the question pressed for a reason why a contingency work group could not begin now, Mullenweg encouraged any eager contributors to put their work into a plugin. He referenced Gutenberg, which began as a plugin and was tested for years before bringing it into core.

I would say when we look at phase 4, the first thing we’re going to look at is how all the plugins are doing it. Perhaps one of those plugins could even become the basis for what comes into core. It’s OK if the plugins take different architectural approaches, because we want to see pluses and minuses of those. Remember people use WordPress with millions and millions of posts and pages, sometimes tens of millions. We want this to scale, we want this to be performant, we want it to be accessible. Take all the things people know and trust about WordPress. and bring it to this functionality.

Mullenweg said he thinks multilingual is “probably going to be one of the most complex things we bring into core, even more so than blocks.” The reason behind this is because blocks took what WordPress did before and gave it a new interface on top of HTML.

“Multilingual is taking every single thing inside of WordPress – tags, categories, pages, templates, and making it multi-factorial so it’s like a factorial amount of complexity on top of what right now is more of a one-to-one relationship,” he said. “If you have some ideas for how to do it, get involved with one of the existing plugins or start your own.”

Delegating JWT Validation for Greater Flexibility

In my opinion, the purpose of all software applications that have been created so far, are being and will be developed should primarily be to make humans' day-to-day activities easier to fulfill. Humans are the most valuable creations, and software applications are great tools that at least could be used by them.

Nowadays, almost every software product exchanges data with at least one other peer software product, which results in huge amounts of data flowing among them. Usually, a request from one product to another needs to pass a set of preconditions before it is considered acceptable and trustworthy.

SQL CTE: How to Master It in One Sitting With Easy Examples

What’s the Big Deal With SQL CTE?

CTE is short for common table expressions. And for one thing, it was first introduced in SQL:1999 specifications. So, it’s pretty standard. Even more, subqueries and temporary tables are its closed relatives.

But What Is SQL CTE? And How Do You Use It?

This article will help you with that. Along with easy examples, you can master this in no time. It’s a painless experience to learn this today.

Scriptless Test Automation — A Pass to the Future

In today’s corporate environment, software testing is no longer regarded as an unnecessary business investment; rather, it has risen to the level of a need rather than a luxury. With the ongoing changes in the market and increased rivalry, it is critical for businesses to do something that sets them apart from their competitors. 

To differentiate themselves, firms must increase efficiency, accelerate development, and offer quality in a cost-effective manner. They can take their items to the next level with perfect software. This fosters confidence and credibility among their prospective and current clients for their products. This may be accomplished with a powerful and regressive Quality Assurance system. 

How to Build Microservices With NodeJS

Building applications is not just meeting the client’s requirements but also integrating complex features along with dynamic programming, maintaining the user experience and the code quality as well. Talking about large-scale applications loaded with features, it is important to ensure that the application runs smoothly.

This article will review the microservices architecture, its benefits, and how to develop microservices with nodejs.

Am I on the IndieWeb yet?

Can’t smash the Like button hard enough for what Miriam Suzanne has to say on the challenging technical hurdles of implementing Webmentions:

The first round required several online services along with HTML & JS changes to my static site, just to verify my indieweb identity. Then more changes to the site and more online services to help fetch any mentions (so far, nothing to see, but that’s probably expected). It seems the only way to test the setup is to launch all those changes publicly, and then ask for other devs to send you mentions.

[…]

I’m an experienced web developer, and I can figure it out. But the steps aren’t simple, and most of my friends are not web developers. So, to me, this all feels like the prototype of an idea – a proof of concept.

A proof of concept for sure. And one that has been around for quite some time. The IndieWeb idea of owning your own data and using your website as a social hub is right up my alley — and likely yours, too, as someone working on the front end.

Yet, I’ve tinkered on and off with it — specifically Webmentions — over the past like three years with little to show for it. The problem isn’t so much the documentation of getting started because it’s all there. It’s more a combination of things…

  • The wiki is confusing. Wikis are super cool in general, but the non-linear nature of it makes it tough to know where to start and where to end.
  • The plugin ecosystem is complex. My personal site is on WordPress and there’s a plugin designed to make it easy to integrate IndieWeb features on it. Except that it’s really one plugin that steers you to install several others, each one introducing a technology that I honestly struggle to understand.
  • There’s a bunch of terms to learn. I mean, “IndieWeb” and “Webmention” are already difficult to grok. Toss in things like “Micropub,” “Microformats,” “IndieAuth,” and “Semantic Linkbacks,” and suddenly it feels like a bunch of puzzle pieces from different puzzles trying to fit together.
  • Some middleware seems necessary? For example, I had to give a service called Bridgy access to my Twitter to get that activity going. It apparently has something to do with Twitter’s shortened t.co URLs and making them play well with microformats.

But, like Miriam, I struggled my way through it and got something working in the end. This is the sort of visual I wish I had when I was first getting started, and maybe it’ll help you too.

Diagram of IndieWeb integration on a WordPress site.

Feels like a lot to get Webmentions going, but maybe that’s only because I have such a light grasp of the tech and how it all fits together. All the pieces are there, though, and even with the initial struggle, I love the IndieWeb concept, er prototype.

To Shared LinkPermalink on CSS-Tricks


Am I on the IndieWeb yet? originally published on CSS-Tricks. You should get the newsletter.

Major Difference Between Cross Browser Testing and Responsive Testing

We live in a digital world with many devices of all forms and sizes. And each of these gadgets has the ability to connect to the internet. As a result, the days of designing a website for a certain browser and not having to worry about element overlap are gone. The number of browsers and internet-connected devices has increased. In addition, end-user surfing habits have changed. One may argue that a website’s lack of browser compatibility is detrimental; instead of switching browsers, online consumers are more inclined to look for another website.

In such a case, cross-browser testing and responsive testing are important to gaining an advantage over the competitors. Both are necessary for the building of a website, yet they are extremely different. This article will provide you with a thorough grasp of cross-browser and responsive testing, as well as its importance in developing a compatible online product.

Implement Language Detection — Thought and Practice

Quick question: How many languages are there in the world? Before you rush off to search for the answer, read on.

There are over 7000 languages — astonishing, right? Such diversity highlights the importance of translation, which is valuable to us on many levels because it opens us up to a rich range of cultures. Psycholinguist Frank Smith said, "One language sets you in a corridor for life. Two languages open every door along the way."

Collective #715






Collective 715 item image

Meet Web Push

WebKit now supports the W3C standards for Push API, Notifications API, and Service Workers to enable Web Push.

Read it





Collective 715 item image

GitNoter

GitNoter is a web application that allows users to store notes in their git repository.

Check it out


Collective 715 item image

Orbit Gallery

Infinite orbit gallery made with THREE.js by Michal Zalobny, based on Luis Bizarro’s Awwwards course. Code can be found .

Check it out


Collective 715 item image

Monorepos in JavaScript & TypeScript

A tutorial on how to use a monorepo architecture in frontend JavaScript and TypeScript with tools like npm/yarn/pnpm workspaces, Turborepo/NX/Lerna, Git Submodules and more.

Read it













Collective 715 item image

Redactle

A daily puzzle game where you have to find the title of a random Wikipedia article by guessing words to reveal them on the page.

Check it out


The post Collective #715 appeared first on Codrops.