Investing in the stock market is a great way to generate wealth, as long as you allow for the time needed to make it happen. Taking a long-term approach maximizes potential returns as even the best businesses can take years (even decades) to fully flourish. 

The two largest companies in the world right now -- Apple and Microsoft (MSFT 1.82%) -- currently offer their investors a combined $5 trillion in value, but these two companies founded in the mid-1970s took over 40 years to reach this point.

Looking to the future, where might the next generation of market leaders come from? The technology on many investors' minds right now is artificial intelligence (AI), and there's reason to believe it will create trillions of dollars in value once this developing technology reaches maturity. Some analyst estimates suggest AI will add $200 trillion to global economic output by 2030, which implies it will triple the world's current gross domestic product (GDP). That's a giant pie for AI-related companies to share.

Here are five companies developing AI-related products or services that could rise to the top over the next few decades to become among the largest in the world by 2050.

1. Tesla

The first cab off the rank is electric vehicle powerhouse Tesla (TSLA -1.11%), cab pun intended. The company is working on a robotaxi slated for release in 2024, which will rely on AI-powered fully autonomous self-driving software. 

According to an estimate by Cathie Wood's Ark Investment Management, this technology will spawn lucrative new industries like autonomous ride-hailing, which could create $14 trillion in value as soon as 2027. It underpins the firm's bet that Tesla could amass a $6.1 trillion enterprise value by then, with the robotaxi accounting for two-thirds of that number. It also implies Tesla stock will rise 12-fold over the next four years -- and we're still a long way from 2050. 

On that note, AI will be at the core of a host of other Tesla products, including its humanoid robot Optimus. It's a glimpse at a new industry that hasn't even been established yet but could reshape the workforce and significantly boost economic productivity. A mere handful of companies have the resources to work on so many different applications for AI, which is why I think Tesla could be one of the greatest value creators between now and 2050. 

2. Meta Platforms

Social network Facebook was founded in 2004, and it's still the largest platform in its industry going on 20 years later. Meta Platforms (META 0.43%) is Facebook's parent company, and it's joined by other leading social apps Instagram and WhatsApp. But social media is entering a new age, with users relying more on AI to curate content that entertains them, as opposed to content that their friends post. ByteDance's TikTok sparked this trend, and Meta is rapidly catching up.

In fact, Meta CEO Mark Zuckerberg recently said AI is the company's single largest investment right now, and it's focused on building the technology into all its products. In the first quarter of 2023, Meta said AI led to a 24% increase in time users spend on Instagram, and it also increased monetization efficiency by 30% on that platform because AI is getting better at determining which ads to show users. 

Short-form video curated by AI will likely dominate the social media industry over the next five to 10 years (at least), and Meta is quickly becoming a leader in the space. Beyond that, the company is still investing heavily in its metaverse virtual reality projects, which could shape the longer-term future of social and professional connection.

Whichever direction the industry moves, I'd back Meta Platforms to adapt and thrive, given its proven track record of success to date. 

3. Microsoft

As mentioned, Microsoft is the world's second-largest company behind Apple. It got there thanks to its relentless focus on innovation since its founding in 1975, dominating industries like software, gaming, and cloud computing over the years. True to form, in 2023 the company rocketed to the front of the AI industry by betting on some of the hottest start-ups in the space.

Microsoft invested a rumored $10 billion in ChatGPT creator OpenAI earlier this year, and just last week it announced an investment in Builder.ai, which helps businesses develop their own software with no coding experience necessary. So far, Microsoft has woven AI into a large chunk of its product portfolio, including its Bing search engine, its Azure cloud computing platform, and even its Teams video and work collaboration platform. 

Azure might be the most powerful of all the integrations so far because it paves the way for Microsoft to become a distribution channel for the world's most advanced AI technologies. Businesses will need to become Azure customers if they want access, and given the pace with which AI is progressing, it could be central to every business by 2050. For that reason, Microsoft should maintain its position as one of the world's top two companies in the coming decades.

4. Nvidia

Nvidia (NVDA 6.18%) is a widely recognized pioneer of AI technology. It's best known as a producer of some of the world's most advanced graphics computing chips, and they're used by AI leaders like OpenAI to power the supercomputers that train large language models like ChatGPT.

Estimates suggest Nvidia has a dominant 90% market share in AI computing, which isn't surprising, given it delivered the first supercomputer to OpenAI back in 2016, long before the AI frenzy hit the stock market. OpenAI has since purchased at least 10,000 chips from Nvidia and might need 30,000 more. Substantial volumes have also been sold to other tech companies with big aspirations in the AI space, including Microsoft and Elon Musk's new X.AI start-up. 

But Nvidia's opportunity runs beyond hardware. It has also developed software to power products like its Drive platform, which car manufacturers can use to install autonomous self-driving capabilities into their new cars. The company has secured deals with at least 35 leading automakers, building a revenue pipeline worth $11 billion already. 

If investors think of AI as the next gold rush, Nvidia is the business selling shovels and pickaxes to the thousands of hopeful miners -- and it has very little competition. For that reason, no AI-focused portfolio is complete without this stock in the long run.

5. Lemonade

The fifth stock pick that could ride the AI wave to create fortunes for investors is Lemonade (LMND 1.64%). Let me be clear, this is the riskiest of the bunch because the company is valued at just $1 billion today and it's still scaling its business, but that also means it could deliver larger gains than the others, too. 

Lemonade is using AI to revolutionize insurance. It operates in five categories: renters' insurance, homeowners' insurance, pet insurance, life insurance, and car insurance. The company developed two AI bots called Maya and Jim; Maya can write a quote for a customer in under 90 seconds, and Jim is capable of automatically paying claims in just three minutes without human intervention. The latter eliminates a major pain point for customers, who are often left waiting weeks for their payout from traditional insurers. 

Lemonade also wove AI throughout the back end of its business. Its lifetime value 6 (LTV6) machine learning model can predict which customers are likely to switch to a competitor, which customers are most likely to make a claim, and which customers will purchase more than one product. Plus, LTV6 tells Lemonade which geographic markets are underperforming and overperforming, so it can pivot its marketing spend quickly to maximize revenue. The company has just upgraded to a more advanced LTV7, with LTV8 on the way. 

The end result is more accurate premiums for its 1.85 million customers. At the end of the 2023 first quarter, Lemonade had $653 million worth of active policy premiums in total, but the U.S. car insurance market alone has an estimated value of $330 billion this year, so the company has barely scratched the surface of its opportunity. Lemonade is a great example of a company applying AI to solve a real problem while successfully monetizing it in the process, which is why I think it could grow to become a dominant force by 2050.