Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Programming Interviews Exposed

You're reading from   Programming Interviews Exposed Coding Your Way Through the Interview

Arrow left icon
Product type Paperback
Published in Jun 2018
Publisher Wiley
ISBN-13 9781119418474
Length 384 pages
Edition 4th Edition
Tools
Concepts
Arrow right icon
Authors (3):
Arrow left icon
John Mongan John Mongan
Author Profile Icon John Mongan
John Mongan
Noah Suojanen Kindler Noah Suojanen Kindler
Author Profile Icon Noah Suojanen Kindler
Noah Suojanen Kindler
Eric Giguère Eric Giguère
Author Profile Icon Eric Giguère
Eric Giguère
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface Introduction 1 Before the Search FREE CHAPTER 2 The Job Application Process 3 The Phone Screen 4 Approaches to Programming Problems 5 Linked Lists 6 Trees and Graphs 7 Arrays and Strings 8 Recursion 9 Sorting 10 Concurrency 11 Object-Oriented Programming 12 Design Patterns 13 Databases 14 Graphics and Bit Manipulation 15 Data Science, Random Numbers, and Statistics 16 Counting, Measuring, and Ordering Puzzles 17 Graphical and Spatial Puzzles 18 Knowledge-Based Questions 19 Nontechnical Questions End User License Agreement
Appendix: Résumés

TREES

A tree is made up of nodes (data elements) with zero, one, or several references (or pointers) to other nodes. Each node has only one other node referencing it. The result is a data structure that looks like Figure 6-1.

Schematic structure of a data tree made up of nodes (data elements) with zero, one, or several references (or pointers) to other nodes. Each node has only one other node referencing it.

FIGURE 6-1

As in a linked list, a node is represented by a structure or class, and trees can be implemented in any language that includes pointers or references. In object-oriented languages you usually define a class for the common parts of a node and one or more subclasses for the data held by a node. For example, the following are the C# classes you might use for a tree of integers:

public class Node {
    public Node[] children;
}

public class IntNode : Node {
    public int value;
}

In this definition, children is an array that keeps track of all the nodes that this node references. For simplicity, these classes expose the children as public data members, but this isn’t good coding practice. A proper class definition would make them private and...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images