- InstaByte
- Posts
- LinkedIn ❤️ Trees
LinkedIn ❤️ Trees
ALSO: TCP vs UDP
Welcome back!
This week’s problem can be solved with two different approaches: recursive, or iterative. Can you come up with both solutions?
Today we will cover:
Symmetric Tree problem
TCP vs UDP
Read time: under 4 minutes
WIN $90 NVIDIA COURSE
We hope you are enjoying our weekly newsletter. We are always looking for ways to provide more value to you. Please help us by answering some questions. Complete this survey by Sunday, 20th October for a chance to win up to $90 AI course from NVIDIA. Good luck!
CODING CHALLENGE
Symmetric Tree
Given the root
of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
Follow up: Could you solve it both recursively and iteratively?
Example:
Input: root = [1,2,2,3,4,4,3]
Output: true
Solve the problem here before reading the solution.
PRESENTED BY WRITER
The fastest way to build AI apps
We’re excited to introduce Writer AI Studio, the fastest way to build AI apps, products, and features. Writer’s unique full-stack design makes it easy to prototype, deploy, and test AI apps – allowing developers to build with APIs, a drag-and-drop open-source Python framework, or a no-code builder, so you have flexibility to build the way you want.
Writer comes with a suite of top-ranking LLMs and has built-in RAG for easy integration with your data. Check it out if you’re looking to streamline how you build and integrate AI apps.
SOLUTION
To solve this problem, we can use either a recursive or an iterative approach. Let's start with the recursive solution.
1) Recursive solution
The idea is to check if the left subtree is a mirror reflection of the right subtree. We'll create a helper function that takes two nodes as input and checks if they are mirrors of each other.
Two trees are mirrors if:
Their root values are the same
The left subtree of one is the mirror of the right subtree of the other
We'll use this helper function to compare the left and right subtrees of the root node.
The time complexity of this solution is O(n)
, where n
is the number of nodes in the tree.
2) Iterative solution
Now, let's look at the iterative solution. We can use a queue
to perform a level-order traversal of the tree. We'll add the left and right children of the current nodes to the queue
in opposite orders.
The time complexity of the iterative solution is also O(n)
, where n
is the number of nodes in the tree.
Both solutions effectively solve the problem of checking if a binary tree is symmetric. The recursive solution might be more intuitive, while the iterative solution could be more efficient in terms of stack space for very deep trees.
SYSTEM DESIGN
TCP vs UDP
Source: WhatIsMyIP.com
TCP and UDP are two different protocols that are used to send and receive data over the internet. Think of ‘protocol’ as a set of rules that determine how data is transmitted between devices.
TCP is a connection-oriented protocol, which means that it establishes a connection between two devices before data can be sent. This connection is maintained until the data transfer is complete. UDP is a connectionless protocol, which means that it does not establish a connection between two devices before data can be sent. This makes UDP faster than TCP, but it is also less reliable.
TCP is more reliable than UDP because it uses a number of mechanisms to ensure that data is delivered correctly. These mechanisms include error detection and retransmission. UDP does not use these mechanisms, so there’s a chance that data will be lost or corrupted with UDP.
TCP is also more efficient than UDP because it uses a technique called flow control. Flow control allows TCP to send data at a rate that the receiving device can handle. This prevents the receiving device from being overwhelmed by data. UDP does not use flow control, so it is possible for the receiving device to be overwhelmed by data.
In addition to the above differences, TCP and UDP also have different uses. TCP is typically used for applications that require reliable and error-free data transfer, such as file transfer and email. UDP is typically used for applications that do not require reliable data transfer, such as audio and video streaming.
TCP | UDP | |
---|---|---|
Connection | Connection-oriented | Connectionless |
Reliability | High | Low |
Speed | Slower | Faster |
Ordering of Data | Guaranteed | Not Guaranteed |
Flow Control | Yes | No |
Use Cases | Email, Web browsing | Video streaming, Gaming |
NEWS
This Week in the Tech World
Source: Tesla
Tesla Optimus Bots Remote-Controlled? Elon Musk showcased Tesla's $30,000 self-driving Cybercab, larger Robovan and Optimus humanoid robots at the “We, Robot” event. These robots were reportedly controlled by humans. This revelation raises questions about the technology's current capabilities and market readiness timeline.
AI Startup Writer Raises Funds: Writer, an AI startup, launched a new model to compete with OpenAI, training it for just $700,000. The company is currently fundraising at a $1.9 billion valuation, nearly quadrupling its value since September 2023.
Bitcoin Surges: Bitcoin hit $68,400, its highest since July, sparking rallies in other cryptocurrencies and related stocks. The surge is partly attributed to new spot bitcoin ETFs launched in January, attracting new investors.
Amazon Launches Color Kindle: Amazon unveiled its first Kindle e-reader with a color display, priced at $279. The company also refreshed its entire e-reader lineup, including updates to the Kindle Scribe, Paperwhite, and standard Kindle.
Generative AI Dominates VC Funding: 40% of all venture capital funding for cloud startups now goes to generative AI companies. Total cloud startup funding is projected to rise 27% year-over-year to $79.2 billion in 2024.
Tech Giants Embrace Nuclear Power: Google and Microsoft are turning to nuclear energy to power their AI-intensive data centers. Google partnered with Kairos Power, while Microsoft plans to revive a reactor at Three Mile Island.
Amazon Tests Robotic Warehouses: Amazon is using robotics technology from Khosla Ventures-backed startup Fulfil at a Whole Foods supermarket. The system will allow shoppers to purchase items not typically stocked at the organic grocer.
Microsoft Launches Healthcare AI Tools: Microsoft announced new AI tools for healthcare, including medical imaging models and an automated documentation solution for nurses. The tools aim to reduce administrative tasks and improve efficiency.
HELP US
👋 Hi there! We are on a mission to provide as much value as possible for free. If you want this newsletter to remain free, please help us grow by referring your friends:
📌 Share your referral link on LinkedIn or directly with your friends.
📌 Check your referrals status here.
BONUS
Just for laughs 😏
Source: r/ProgrammerHumor
YOUR FEEDBACK
What did you think of this week's email?Your feedback helps us create better emails for you! |
Until next time, take care! 🚀
Cheers,