Skip to content

Algorithms and datastructures for helm, also includes some sql scripts

Notifications You must be signed in to change notification settings

ClaytonSiby/helm_algorithms_n_sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python and SQL

Algorithms and data structures for Helm, also include some SQL scripts.

Problem Statements (Implement the following)

  1. Python Challenge 1: (Repeating Playlist)

A playlist is considered a repeating playlist if any of the songs contain a reference to (i.e points to) a previous song in the playlist. Otherwise, the playlist will end with the last song which points to None.
  • Implement a function is_repeating_playlist that, efficiently with respect to time used, returns true if a playlist is repeating or false if it is not.

Example: (the following code prints "True" as both songs point to each other):

first = Song("Hello")
second = Song("Eye of the tiger")

first.next_song(second)
second.next_song(first)

print(first.is_repeating_playlist()) # True
print(second.is_repeating_playlist()) # True
  1. Python Challenge 1: (Repeating Playlist)

A Binary search tree (BST) is a binary tree where the value of each node is larger or equal to the values in all the node in that node's left subtree and is smaller than the values in all the nodes in that node's right subtree.
  • Write a function def contains(node, value) that, efficiently with respect to time used, checks if a give binary search tree with root node contains the given value.

Example:

n1 = Node(value=1, left=None, right=None)
n3 = Node(value=3, left=None, right=None)
n2 = Node(value=2, left=n1, right=n3)

print(contains(n2, 3)) # true
print(contains(n2, 5)) # false
  1. SQL CHALLENGE 1

A table containing the students enrolled in a yearly course has incorrect data in records with ids between 20 and 100 (inclusive).
  TABLE enrollments
  id INTEGER NOT NULL PRIMARY KEY
  year INTEGER NOT NULL
  studentId INTEGER NOT NULL

Write a query that updates the field (year) of every faulty record of 2015

  1. SQL CHALLENT 2

App usage data are kept in the following table:
  TABLE sessions
  id INTEGER PRIMARY KEY,
  userId INTEGER NOT NULL,
  duration DECIMAL NOT NULL

Write a query that selects userId and average session duration for each user who has more than one session.

Requirements

  • Python
  • Pytest
  • Pip
  • Git

Setup Instructions

From your terminal run:
  • git clone https://github.com/ClaytonSiby/helm_algorithms_n_sql.git
  • cd helm_algorithms_n_sql
  • python3 -m venv .venv
  • source .venv/bin/activate
  • pip install -r requirements.txt
  • pytest

Project Structure

  • all the algorithms are in /algorithms directory

  • all the tests are defined in /tests

  • the sql stuff is in the /sql directory

  • NB make sure your virtual environment is well set and is activated, please refer to the setup instrucitons above

  • IMPORTANT please read through the SQL setup instructions included in the shared documents. Thank you!

Releases

No releases published

Packages

No packages published

Languages