Tag Archives: linked list

Linked list for interviews in a Python job. Or try R code walkthrough?

ome will always say how interviewer will test your coding capabilities. This is one popular question for any job in this field. Anyone have any other popular questions for their potential job? How about a an R code walkthrough?

https://codereview.stackexchange.com/questions/117668/linked-list-for-interviews

I just posted this old legacy R course if you are interested. This include R code walkthrough. I have many posted on this language here 

Purchase here if interested

http://quantlabs.net/academy/buy-all-of-our-r-courses/

To be quite honest, I am quite surprised on how popular this seems to be among my site visitors.

Note that this is older version of R using version 2.15!

Here are the details with a video at this location

R Course with Technical Analysis

R Course with Technical Analysis

 

Module 1

Technical Analysis in R

 

Technical Analysis in R

Unit 1

30 day moving average function

Unit 2

2 sided moving average for mean rolling window

Unit 3

R Code Walkthrough Improved Moving Average using intra day for Forex data

Unit 4

The improved moving average

Unit 5

R Code Wakthrough Simple Moving Averag Strategy with Volatility Filter

Unit 6

Love level Improved Moving Average functions with testing code

Unit 7

R source code for trading script with update portfolio, position size, MA, cross over, SMA, optimize parameters pt 2

Unit 8

R source code for trading script including MACD, Omega performance, RSI, and Bollinger Band measuring strategy and portfolio performance with plots Pt 3

R Course with Quant including GARCH

 

Module 1

Quant trading in R

 

Quant trading in R

Unit 1

Walthrough Parallel R Model Prediction Building and Analytics

Unit 2

Intro to GARCH forecasting with various R packages

Unit 3

How to use GARCH for predict market movements

Unit 4

How to use GARCH to predict distributions

Unit 5

GARCH trading R script walkthrough with a rolling window

R Course with Quant

R Course with Quant

 

Module 1

Intro

 

Intro

Unit 2

An ARMA model R code walkthrough

Unit 3

Checklist of forecasting with ARIMA: is time series stationary, differentiate, ARIMA(p,d,q), and which AMRA model to use?

Unit 4

R code walkthrough: Detrend to use Auto ARIMA modelling and forecast with statistical data and Ljung BoxTest

Unit 5

My first version of ARIMA R script with Forex data and Equity 1 and 5 min frequency

Unit 6

Bayesian analysis to Compare algorithms with Gibbs

Unit 7

Markov Chain R source code walkthrough

Unit 8

Monte Carlo R Walkthrough Demo

Unit 9

An alternative to running a Monte Carlo simulation

Unit 10

R code walkthrough Mean Absolute Deviation with Efficiency Frontiers Demo

R Course with Mean Reversion and Pair Trading

 

Module 1

Mean Reversion in R

 

Mean Reversion in R

Unit 1

Backtesting a Strategy with Mean Reversion

Unit 2

Mean Reversion Euler with Ornstein Uhlenbeck process

Unit 3

Pairs trading R source code walkthrough with mean reverting logic, spread and beta calculation

Module 2

Pair Trading in R

 

Pair Trading in R

Unit 1

Poor mans Pair Trading with Cointegration R Walkthrough

Unit 2

Pair trading with S&P 500 companies

Unit 3

Pairs trading with testing cointegration

Unit 4

Seasonal pair trading

Unit 5

 

Unit 6

Pairs Trading R Code Walkthrough

Unit 7

Pairs trading with a Hedge Ratio Demo

Unit 8

R Code Walkthrough Back testing with trading pair with CAPM

Unit 9

Gold versus Fear in Cointegration test

R Course with Arbitrage and Volatility

Arbitrage and Volatility

 

Module 1

Arbitrage in R

 

Arbitrage in R

Unit 1

Beating a random walk with arbitrage

Unit 2

Beating a random walk with arbitrage

Unit 3

Time Based Arbitrage Opportunities in Tick Data: Why low latency is needed in HFT?

Unit 4

Building a currency graph with arbitrage

Unit 5

Arbitrage: Modelling returns with CAPM APT aka Abritrage Pricing Theory

Unit 6

Indian equity market index NIFTY anaysis with CAPM vs APT aribitrage pricing theory using PCA and moment analysis

Module 2

Volatility in R

 

Volatility in R

Unit 1

R Code Walkthrough Adding a volatility filter with VIX

Unit 2

R Code Wakthrough Simple Moving Averag Strategy with Volatility Filter

Unit 3

Mean Reverting with Volatility Spike

Unit 4

Trading with GARCH volatility R script walkthrough demo

Unit 5

Jeff Augen volatility spike code

 

Reminder from yesterday. This closes out TONIGHT as well:

 

 

 

This is the your chance to learn about behind the scenes of these trading patterns I presented on Monday night. I have made this replay video now private which means it is only available to my Quant Elite Members. This is a very limited and exclusive offering to access it! I even revealed the source of how the Python code was created to generate them, This will never be seen again after this Friday! It is way too valuable that I don’t need the world to know how these work.

 

This posting will be removed this Friday night Eastern Standard Time (same as NYC)!

 

I Want To Learn Trading Patterns Now

Get your access to this via my 3 month Quant Elite Membership if interested!

 

Please find the upcoming new items I will be adding the next few months for this membership:

 

1. Live Q&A workshop bootcamp for the Python 3 Infrastructure Course for a Primitive Algo/Automtated Trading System

2. Packaged up course of using Dukascopy JForex API for automated forex and CFD trading. (this is partially done now with access for this membership)

3. Daily charting within the Quant Analytics service.

 

Here are the details with benefits of this trial membership

http://quantlabs.net/academy/introduction-quant-elite-membership/

 

REMEMBER: My patterns talk will be removed forever as of Friday!!!

 

Always remember I just created the online store for all other product and services.

I Want to Learn Trading Patterns Now

Please find the upcoming new items I will be adding the next few months for this membership:

 

1. Live Q&A workshop bootcamp for the Python 3 Infrastructure Course for a Primitive Algo/Automtated Trading System

2. Packaged up course of using Dukascopy JForex API for automated forex and CFD trading. (this is partially done now with access for this membership)

3. Daily charting within the Quant Analytics service.

 

Here are the details with benefits of this trial membership

http://quantlabs.net/academy/introduction-quant-elite-membership/

 

RMEMEBER: My patterns talk will be removed forever as of Friday!!!

 

Always remember I just created the online store for all other product and services.

P.S. Let me know if you are interested in an annual term as well.

Buy all of our R courses with R code walkthrough

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Even more resources for Java and C++ data structures, linked list, sort, binary search tree

Even more resources for Java and C++ data structures, linked list, sort, binary search tree

I have already posted some more advanced Java topics you can be expected in to know in any high end financial company like Morgan Stanley. Java is an important element within investment banks like Morgan Stanley but C++ is your building block.
As for any Java based position in a company like Morgan Stanley, it is safe to say you will be expected to know Java data structures really, really well. I have already put up some sample questions and resources for tips in help you clear the conceptual type of interviews. You know how to look for those tips and postings.

Now I have put together a bunch of resources to help you learn the more advanced data structures you will not really find in books. You can only find them individually but I have a small list that should help you out.
I found one list of topics that looked very good for collections and generics. This is at:
http://www.cogs.susx.ac.uk/courses/dats/notes/html/notes.html
This seems to be based off a course but you have to hyper link from topic to topic which is a real pain. I like few clicks to get my stuff. Once you hit this page, make sure you understand the main components because this will cover a lot of the sample questions I originally posted about Java job interviews from companies like Morgan Stanley.
Below are the links that cover what I think you cannot get in a complete tutorial but you also cannot find in books.

Binary search trees:
http://www.java-tips.org/java-se-tips/java.lang/binary-search-tree-implementation-in-java.html

Heap sort
http://www.java-tips.org/java-se-tips/java.lang/heap-sort-implementation-in-java.html

Binary heap/priority queue

http://www.java-tips.org/java-se-tips/java.lang/priority-queue-binary-heap-implementation-in-2.html

Heap sort
http://www.java-tips.org/java-se-tips/java.lang/heap-sort-implementation-in-java.html
Weighted graphs:
http://www.algolist.net/Data_structures/Graph
http://www.algolist.net/Data_structures/Graph/Internal_representation
http://www.algolist.net/Data_structures/Graph/Internal_representation

Linked list
http://www.java2s.com/Code/Java/Collections-Data-Structure/LinkedListexample.htm
These listed above are the typical topics you would need to know if you are expected to go into a more senior Java or C++ role. Do note you need to know the different access and sorting algorithms and will be expected to talk about them. I have found a very striking pattern among questions asked at a lot of the financial or tech companies in telephone or onsite interviews. Some of the above links do cover both Java and C++ so do understand them.
Good luck with all this.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

C++ interview questions on binary trees with in order traversal, linked list, recursive traverse

C++ interview questions on binary trees with in order traversal, linked list, recursive traverse

Binary tree:
Convert a binary search tree to a circular sorted linked list. The highest valued node should point to the lowest valued node at each step.
I think it should be implemted by using Breadth-first traversal.

We can Insert elements in link list by traversing tree in INORDER. At last we can point last elemtents node to the head.

You are right.
Inorder traversal would give a sorted list which can be pused inside a circular link list.

Guys,

1) Inorder traversal of a Binary search Tree prints the data in the increasing order.
2) While doing inorder traversal, at each step, build the linked list adding the each element at the end of linked list.
3) At each step, also make the end of the linked list to point to the first element of the linked list.

Basically, we need to maintain always two pointers, one to head and another to the last element of the linked list

its the great tree list recursion problem… find it on
http://www.google.com/search?hl=en&q=stanford+cs+lib&btnG=Search

Question doesn’t restrict space usage and thus this is not that ‘great’ problem. Moreover, this is a question asked for Program Manager.

void main_class::iterate(Node *new_node)
{
char flag;
Node *temp_parent = NULL;
if (root == NULL)
{
//This is the root node
root = new_node;
cout<<"Root value: "<value<<"\n\n"; } else { //This is not a root node and hence, now we iterate Node *current = root; while(current != NULL) { if(current->value < new_node->value) // Go right
{
temp_parent = current;
current = current->child_right;
flag = ‘r’;

}
else
{
temp_parent = current;
current = current->child_left;
flag = ‘l’;

}
}

new_node->parent = temp_parent;
if(flag == ‘l’)
{
temp_parent->child_left = new_node;
}
else
{
temp_parent->child_right = new_node;
}
cout<<"Value: "<value<<" Parent value: "<<(new_node->parent)->value<<"\n\n"; } } /* This is a recursive function to traverse the binary tree INORDER */ void main_class::recursive_traverse(Node *current) { if(current->child_left != NULL)
{
current = current->child_left;
//cout<<"Going left to: "<value;
recursive_traverse(current);
current = current->parent;
}

cout<value<<" "; /* This section is for making of the Circular Linked list*/ if(previous_node == NULL) { /* This is the head*/ previous_node = current; root = current; //root->child_left = NULL;
//previous_node->child_left = NULL;
}
else
{
//previous_node->child_right = current; // Logical error here. The tree structure is being changed
//before the tree can be traversed!
current->child_left = previous_node;
previous_node = current;
}
/* Section for making of the Linked List ends here */

if(current->child_right !=NULL)
{
current = current->child_right;
//cout<<"Going right to: "<value;
recursive_traverse(current);
}

return;
}

Oops… u guys will need one more function…lol… on May 09, 2009 |Edit | Edit

{
new Node(7); new Node(4); new Node(3); new Node(5);
new Node(15); new Node(12); new Node(10);

recursive_traverse(root);

Node *an_iterator = previous_node;

/*The following part connects the root node
to the last node making the queue circular
*/
root->child_left = previous_node;
previous_node->child_right = root;

/* The following prints the Linked list
to check if it is indeed the list that
was intended. It also makes it a double
linked list form a single linked list while doing so.
It was not possible to make a double linked list
to begin with because it was creating a logical
error as indicated a few lines of code below.
Hence, iterating from right to left.
*/

cout<<"\n\nThe Linked list: "; while (an_iterator != root) { cout<value<<" "; an_iterator->child_left->child_right = an_iterator;
an_iterator = an_iterator->child_left;
}

/*
This extra print statement has to be put
outside to print the root node’s valuel
*/
cout<value<<" "; cout<<"\n\n"; } Isnt the problem statement to convert the existing bst to a ll and not creating a new one!!! This is the well working code for this problem..:) #include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#define MAX 1000
#define max(a,b) (a)>=(b)?(a):(b)
#define REP(i,n) for(i=0;i
/*** structure of the tree node ****/
struct node
{
int data;
node *small;
node *large;
};
/* fun to insert element in the binary search tree */
void insert(node **root,int val)
{
node *tmp;
if(*root==NULL)
{
tmp=(node*)malloc(sizeof(node));
tmp->data=val;
tmp->small=NULL;
tmp->large=NULL;
*root=tmp;
}
else
{
if(val<(*root)->data)
insert(&((*root)->small),val);
else
insert(&((*root)->large),val);
}
}
/* this function joins two given nodes */
void join(node **a,node **b)
{
(*a)->large=(*b);
(*b)->small=(*a);
}

/* this function appends second list behind first list */
node *append(node *head1,node *head2)
{
if(head1==NULL)
return head2;
if(head2==NULL)
return head1;
node *alast,*blast;
alast=head1->small;
blast=head2->small;

join(&alast,&head2);
join(&blast,&head1);
return head1;
}

/**** most important function ,uses recursion to convert bst to circular ll ***/

node* treetolist(node *root)
{
if(root==NULL)
return NULL;
node *alist,*blist;
alist=treetolist(root->small);
blist=treetolist(root->large);

root->small=root;
root->large=root;

alist=append(alist,root);
alist=append(alist,blist);

return alist;
}
/* funtion to display bst */
void display(node *root)
{
if(root!=NULL)
{
display(root->small);
cout<data<<"\t"; display(root->large);

}
}
/* function to display ll */
void displayl(node *head)
{
for(int i=1;i<=5;i++) { cout<data<<"\t"; head=head->large;
}
}
int main()
{
node *root=NULL;
node *head;
/* test values */
insert(&root,10);insert(&root,4);insert(&root,8);insert(&root,15);insert(&root,9);
display(root);
cout<
struct ListNode
{
T value;
ListNode* next;
explicit ListNode(T v) : value(v), next(NULL) { }
};
template
struct TreeNode
{
T value;
TreeNode* left;
TreeNode* right;
};

template
ListNode* to_list(TreeNode* tree, ListNode*& tail)
{
ListNode* list = NULL;
if (tree)
{
list = to_list(tree->right, tail);
ListNode* node = new ListNode(tree->value);
if (!list)
{
list = node;
}
if (tail)
{
tail->next = node;
}
tail = node;
node->next = to_list(tree->left, tail);
}
return list;
}

cristi.vlasceanu on July 17, 2009 |Edit | Edit

oh, and to make the list circular we need to call the function like this:

ListNode* tail = NULL;
ListNode* list = to_list(tree, tail);
if (tail)
tail->next = list; // make it circular

what nagendra.kumar suggested is right.
this way list would be sorted in increasing order and each element would be pointing
to the smallest as per the question.And there is no need to traverse right subtree first.

i m using double linked list….

node *p=NULL;
node* Cirq(node *t)//we have call with root node….
{

if(t->left !=NULL)
{
p=tree(t->left);
p->right=t;
t->left=p;
}
else if(t->right !=NULL)
{
p=tree(t->right);
t->right=p;
return p;
}
else
{
return t;
}
}

Inorder traversal would print the numbers in icreasing order for Binary search tree.

inorder(Node *root)
{
if(root)
{
inorder(root->left);
//printf(“%d”, root->value); Instead of print to just assign the next poiter to end //of the list. I guess that shoudn;t be hard to figure how to assign the next link 😉
inorder(root->right);
}
}

one more statement after the end of the traversal to point the last node to the head of the list
Reply to Comment
nirmalr on November 09, 2009 |Edit | Edit

// Routine to convert tree into doubly list
// after conversion “right” points to “next” node and “left” points to “prev” node

node_t * toList(node_t *curr, node_t *next) {
if (curr == 0) return next;

curr->right = toList(curr->right, next);
if (curr->right)
curr->right->left = curr;

return toList(curr->left, curr);
}

invoke like this,

head = toList(root, 0);

this routine returns head of the list. head and tail is not linked that can be done easily.

abhimanipal on May 09, 2010 |Edit | Edit

Very nice and effective solution

typedef node * NodePtr;

node *CreateListFromTree(node *root)
{
NodePtr start = NULL, tail = NULL;
CreateListFromTreeCore(root,&start,&tail);
return start;
}

/* Assume right for tree will act as next for Linked List */
void CreateListFromTreeCore(node *root, NodePtr *start, NodePtr *tail)
{
CreateListFromTreeCore(root->left,start,tail);
node *temp = root->right;
root->left = NULL;
if (*start == NULL)
*start = *tail = root;
else
{
(*tail)->right = root;
*tail = root;
}
*tail->right = *start;
CreateListFromTreeCore(temp,start,tail);
}

Question is convert BST to LL but not create another list and copy values.
here is working solution.

btnode* formListFromBT(btnode* root, btnode* cur, btnode** head) {
if(!root) return cur;

cur = formListFromBT(root->left, cur, head);
if(*head == NULL) {
*head = cur = root;
}
cur->left = root; cur = cur->left;

cur = formListFromBT(root->right, cur, head);
}

// call the above function using…
btnode *listhead = NULL;
tail = formListFromBT(head, NULL, &listhead);
tail->left = listhead;
Reply to Comment
Anonymous on January 14, 2010 |Edit | Edit

//call will be
// Element *start = null;
// Element *tail = BuildCircularLL(root, &start);
// tail->left = start;

Element *BuildCircularLL(Element *head, Element **start)
{
Element *begin = *start;
Element *node = head;
Element *prev = null;
Element *after = null;
if(node == null)
{
return null;
}
prev = BuildCircularLL(&node->left, &begin);
if(prev != null)
{
if(begin == null)
{
begin = prev;
}
prev->left = node;
}
after = BuildCircularLL(&node->right, &begin);
if(after != null)
{
node->left = after;
node->right = null;
return after;
}
else
{
return node;
}

}

binary search to speed up

balancing binary trees, find the depth of a tree.
They asked about balancing binary trees and
Print nodes in a binary tree in level order
Tree traversal

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!