Write a program to reverse a singly linked list? Modify that program to reverse a doubly linked list.
Python Data Structures Interview Questions
What is a hashtable? Give an example of a type of problem that a hashtable is useful for.
For the data structures: Array and Linked List explain:
- Where you might use them
- Operations that are commonly supported (add, insert etc)
Explain what a list comprehension is and write some code that illustrates an example use.
Explain the difference between a tuple and a list and give an example of where you would use each.
Explain what the following Python code does:
phrase = 'hello mommy'
print phrase[:4] + phrase[4:]
Write a python program that will take the following list of words as input and output a dictionary with a the frequency of each word:
words = ['apple', 'apple', 'banana', 'banana', 'banana', 'pear', 'banana', 'pear', 'pear', 'pear', 'pear', 'pear']
Write a function to take the following list and return one list of odd numbers and one list of even numbers:
ints = [1,21,53,84,50,66,7,38,9]
Discuss an algorithm to traverse a tree, depth first.
Given a N by N matrix of both negative and positive integers. Write an efficient algorithm to find the sub-matrix with the largest sum of all the contained elements.
Write a function to efficiently determine the result of a game of Tic Tac Toe.
The function takes as input the game and the sign (x or o) of the player. The function returns if this player has won the game or not.
Carefully consider both the data structure and the algorithm for your answer.
Express the following table as a static structure, and write a function, find_routes(source, destination) that efficiently outputs all possible routes.
Source | Dest
~~~~~~ ~~~~
Seattle | LA
LA | Florida
LA | Maine
Florida | Seattle
Seattle | Florida
The solution for find_routes('Seattle', 'Florida') should be [Seattle -> Florida, Seattle -> LA -> Florida]
Write a function that takes as input a binary tree, and returns the length of the longest path.
For example, in this binary tree:
1
/ \
2 3
/
5
the answer is 2, since the path from vertex 1 to vertex 5 involves two edge traversals.
Write function that takes a binary tree and efficiently returns the Nth smallest element.
For example, if N=4, and the tree looks like:
3
/ \
2 5
/ / \
1 4 6
The function should return 4.
Write a function that takes as input a binary tree, and prints out each level of the tree on a newline. For example:
a
/ \
b c
/ / \
d e f
will output:
a
b c
d e f