Questions tagged [ternary-tree]

Ternary tree is a tree data structure in which each node has at most three child nodes, usually distinguished as "left", “mid” and "right".

Nodes with children are parent nodes, and child nodes may contain references to their parents. Outside the tree, there is often a reference to the "root" node (the ancestor of all nodes), if it exists. Any node in the data structure can be reached by starting at root node and repeatedly following references to either the left, mid or right child. Ternary trees are used to implement Ternary search trees and Ternary heaps.

35 questions
1
vote
0 answers

Big O complexity of creating a recursive ternary tree with k width

I want to know the complexity of my algorithm. I'm trying to optimize the profit of buying stocks at every leaf of a tree from a list of prices. For every price we can do 3 options, buy one unit, sell one unit or do nothing. There is a constraint…
Rodrigo
  • 133
  • 1
  • 5
1
vote
1 answer

Ternary Tree methods - Standard ML

A ternary tree type is defined as: datatype ’a tree = Leaf of ’a | Node of ’a tree * ’a tree * ’a tree I need to modify functions map & foldl to match the ternary tree... fun tree_map (f : ’a -> ’b) (t : ’a tree) : ’b tree = f,nil) = nil | map…
1
vote
2 answers

Preorder traversal of ternary tree

I need to perform a preorder traversal of a ternary tree. I'm familiar with this traversal on a binary tree, such as: public void preorder(){ System.out.println(data); if (left != null) left.preorder(); if (right != null) …
Nick Castello
  • 51
  • 2
  • 10
1
vote
0 answers

Serialize ternary tree in c

I am writing ternary tree for string lookup in c. So far I am able to store strings and check whether string exists. Example insert Node *node_link(Node *this, char *line) { 26 if(!this) { 27 this = node_create(*line); 28 } 29 if(*line…
php--
  • 2,647
  • 4
  • 16
  • 18
1
vote
3 answers

Easy way to understand nested ternary operators?

Is there a simple heuristic for understanding how to read nested ternary operators? I came across this in someone's source code and can't grok it. A simple ternary is easy: isRed = color == 'red' ? true : false But how do you read the following?…
SimplGy
  • 20,079
  • 15
  • 107
  • 144
1
vote
1 answer

How to delete a node in Ternary Tree?

I am working on implementing a Java program on inserting and deleting a node in a ternary tree. I am able to implement insertion without any issues, but I'm facing a few hiccups in implementing the deletion operation. So, my question is: How to…
Shan
  • 521
  • 2
  • 8
  • 28
1
vote
1 answer

Most efficient way to implement trickledown operation in a Ternary Heap

Sorry if the terminology in the title was off. I'm trying to better understand the terms by using them more often. Anyway, I'm currently working on a lab in a data structures class (using C++) where I have to build a Ternary Heap and compare it to a…
Christina
  • 97
  • 1
  • 10
1
vote
3 answers

ternary tree giving error

This is simple ternary tree structure . I have written code correctly but while running it says after some time: Sorry ternary.exe has stopped working. Can you tell me the cause of this error. #include #include using namespace…
dann_
  • 59
  • 1
  • 10
0
votes
3 answers

error: pointer to incomplete class type is not allowed

I am stumped at this step while implementing a ternary tree: #include #include #include typedef struct tnode *Tptr; typedef struct node { char splitchar; Tptr lokid,eqkid,hikid; }Tnode; int research(Tptr…
user466534
0
votes
2 answers

Get the depth of a node in a Ternary Tree Using The Indexes in Array Implementation of Trees

Let's assume we create a Ternary tree using an array implementation. The root is stored in the index 1, the left child is stored in index = 3(index)-1, middle child is stored in 3(index), and right child is stored in 3(index)+1. So for example.…
Coder2002
  • 27
  • 2
0
votes
0 answers

Trie search tree vs ternary search tree for autocomplete?

I'm trying to implement a datastructure such that it'll give autocompleted words when the user writes something. So far I've implemented a trie properly, and the autocomplete works quite fast. Thing is, when loading all the information needed, it…
Jskoven
  • 31
  • 1
0
votes
1 answer

Ternary tree paths

I'm solving the following question: Given a ternary tree (each node of the tree has at most three children), find all root-to-leaf paths. Example: My code is as follows: from __future__ import annotations import itertools from collections import…
0
votes
1 answer

insert node in ternary tree

I have a ternary tree, I have created a table CREATE TABLE `user_tree` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `parent_ID` int(11) NOT NULL, `next_pool` tinyint(1) NOT NULL DEFAULT '0', `last_update` timestamp(6)…
Gagandeep Singh
  • 115
  • 1
  • 11
0
votes
1 answer

How to print out ternary tree?

I have the following method to recursively perform a preorder traversal of a ternary tree but having difficulty printing it in a certain manner. public void preOrder(Node node) { if (node == null) { return; } …
0
votes
2 answers

Error in ternary tree implementation

I am trying to implement trenary tree, but I am getting the following error and I am not sure what is the problem, as my constructor requires an integer input. Error: Trenarytree.java:46: error: constructor Trenarytree in class Trenarytree cannot be…
Laurynas G
  • 573
  • 9
  • 30